From f0bde60cc806476df8dd96e90b51d9f2d313d86f Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Wed, 14 Sep 2016 14:21:04 +0200 Subject: rename thinclient-config-agent to remote-logon-config-agent --- remote-logon-config-agent | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 remote-logon-config-agent (limited to 'remote-logon-config-agent') diff --git a/remote-logon-config-agent b/remote-logon-config-agent new file mode 100755 index 0000000..3d7b5bc --- /dev/null +++ b/remote-logon-config-agent @@ -0,0 +1,68 @@ +#!/usr/bin/python3 +# Copyright 2012 Canonical Ltd. This software is licensed under the GNU +# General Public License version 3 (see the file LICENSE). + +from optparse import OptionParser +import os +import sys + +from rscalib import ( + api_versions, + UserError, +) + +class Usage(UserError): + + status = 1 + + +def get_sso_credentials(args, stream): + """Determine SSO credentials from the args and stream.""" + if stream.isatty(): + raise Usage('Password must be provided on stdin.') + if len(args) == 0: + raise Usage('Email must be provided as the first argument.') + password = sys.stdin.read().rstrip('\n') + username = args[0] + return username, password + +def get_json_error(error_message): + return '{ "Error": "%s" }' % error_message + +def main(args): + """Request data for the specified SSO credentials from the server. + + Prints the data in JSON format on success and a JSON error in the case + of a failure. + + Exit status summary: + 0 Success + 1 Usage error + 2 Authentication error + 3 Connection error + 4 SSL Certificate verification error + 100 All other errors. + """ + parser = OptionParser() + parser.add_option('--skip-ssl-verify', action='store_true') + options, args = parser.parse_args(args) + verify_ssl = not options.skip_ssl_verify + try: + username, password = get_sso_credentials(args, sys.stdin) + server_root = os.environ.get('SERVER_ROOT') + api = api_versions[os.environ.get('API_VERSION', 'default')] + sys.stdout.write(api.run(username, password, server_root, verify_ssl)) + except UserError as e: + sys.stderr.write(str(e) + '\n') + sys.stdout.write(get_json_error(str(e)) + '\n') + sys.exit(e.status) + except Exception as e: + sys.stderr.write('Exception: ' + str(type(e)) + '\n' + str(e) + '\n') + sys.stdout.write(get_json_error('Contact your administrator')+ '\n') + sys.exit(100) + else: + sys.exit(0) + + +if __name__ == '__main__': + main(sys.argv[1:]) -- cgit v1.2.3