Page MenuHomec4science

authaction.wml
No OneTemporary

File Metadata

Created
Sun, Nov 17, 22:34

authaction.wml

## $Id$
## authaction -- CLI interface to Access Control Engine
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002 CERN.
##
## The CDSware 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.
##
## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## read config variables:
#include "config.wml"
#include "configbis.wml"
#include "cdswmllib.wml"
## start Python:
<protect>#!</protect><PYTHON>
<protect>## $Id$
<protect>## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.</protect>
"""authaction -- CLI interface to Access Control Engine"""
__version__ = "<: print generate_pretty_version_string('$Id$'); :>"
## fill config variables:
pylibdir = "<LIBDIR>/python"
try:
import sys
sys.path.append('%s' % pylibdir)
from cdsware.config import *
from cdsware.access_control_engine import acc_authorize_action
from cdsware.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" % __version__)
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