Page MenuHomec4science

authaction.in
No OneTemporary

File Metadata

Created
Mon, Nov 18, 19:28

authaction.in

#!@PYTHON@
## -*- mode: python; coding: utf-8; -*-
##
## $Id$
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""authaction -- CLI interface to Access Control Engine"""
__revision__ = "$Id$"
try:
import sys
from invenio.config import *
from invenio.access_control_engine import acc_authorize_action
from invenio.access_control_config import CFG_WEBACCESS_WARNING_MSGS
except ImportError, e:
print "Error: %s" % e
import sys
sys.exit(1)
def usage(code, msg=''):
"""Print usage info."""
if msg:
sys.stderr.write("Error: %s.\n" % msg)
sys.stderr.write("authaction -- CLI interface to Access Control Engine\n")
sys.stderr.write("Usage: %s [options] <id_user> <name_action> [keyword1] [value1] [keyword2] [value2] ...\n" % sys.argv[0])
sys.stderr.write("Command options:\n")
sys.stderr.write(" <id_user> = ID of the user\n")
sys.stderr.write(" <name_action> = action name\n")
sys.stderr.write(" [keyword1] = optional first keyword argument\n")
sys.stderr.write(" [value1] = its value\n")
sys.stderr.write(" [keyword2] = optional second keyword argument\n")
sys.stderr.write(" [value2] = its value\n")
sys.stderr.write(" ... = et caetera\n")
sys.stderr.write("General options:\n")
sys.stderr.write(" -h, --help \t\t Print this help.\n")
sys.stderr.write(" -V, --version \t\t Print version information.\n")
sys.exit(code)
def main():
"""CLI to acc_authorize_action. The function finds the needed
arguments in sys.argv.
If the number of arguments is wrong it prints help.
Return 0 on success, 9 or higher on failure. """
alen, auth = len(sys.argv), 0
# return ``not permitted'' if wrong arguments
if alen > 1 and sys.argv[1] in ["-h", "--help"]:
usage(0)
elif alen > 1 and sys.argv[1] in ["-V", "--version"]:
sys.stderr.write("%s\n" % __revision__)
sys.exit(0)
if alen < 3 or alen % 2 == 0:
print "7 - %s" % CFG_WEBACCESS_WARNING_MSGS[7]
return "7 - %s" % CFG_WEBACCESS_WARNING_MSGS[7]
# try to authorize
else:
# get values
id_user = sys.argv[1]
name_action = sys.argv[2]
dict = {}
for i in range(3, alen, 2):
dict[sys.argv[i]] = sys.argv[i + 1]
# run ace-function
(auth_code, auth_message) = acc_authorize_action(id_user, name_action, **dict)
# print and return
print "%s - %s" % (auth_code, auth_message)
return "%s - %s" % (auth_code, auth_message)
if __name__ == '__main__':
main()

Event Timeline