1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | import sys |
---|
4 | from datetime import datetime |
---|
5 | |
---|
6 | from federation.fedid import fedid, generate_fedid |
---|
7 | from federation.remote_service import service_caller |
---|
8 | from federation.proof import proof |
---|
9 | from federation.client_lib import client_opts, exit_with_fault, RPCException, \ |
---|
10 | wrangle_standard_options, do_rpc, get_experiment_names, \ |
---|
11 | save_certfile, get_abac_certs, log_authentication |
---|
12 | |
---|
13 | class new_opts(client_opts): |
---|
14 | def __init__(self): |
---|
15 | client_opts.__init__(self) |
---|
16 | self.add_option("--experiment_cert", dest="out_certfile", |
---|
17 | action='callback', callback=self.expand_file, type='str', |
---|
18 | help="output certificate file") |
---|
19 | self.add_option("--experiment_name", dest="exp_name", |
---|
20 | type="string", help="Suggested experiment name") |
---|
21 | self.add_option('--gen_cert', action='store_true', dest='gen_cert', |
---|
22 | default=False, |
---|
23 | help='generate a cert to which to delegate rights') |
---|
24 | |
---|
25 | parser = new_opts() |
---|
26 | (opts, args) = parser.parse_args() |
---|
27 | |
---|
28 | try: |
---|
29 | cert, fid, url = wrangle_standard_options(opts) |
---|
30 | acerts = get_abac_certs(opts.abac_dir) |
---|
31 | except EnvironmentError, e: |
---|
32 | sys.exit('%s: %s' % (e.filename, e.strerror)) |
---|
33 | except RuntimeError, e: |
---|
34 | sys.exit("%s" %e) |
---|
35 | |
---|
36 | out_certfile = opts.out_certfile |
---|
37 | |
---|
38 | msg = { } |
---|
39 | |
---|
40 | if opts.gen_cert: |
---|
41 | expid, expcert = generate_fedid(opts.exp_name or 'dummy') |
---|
42 | msg['experimentAccess'] = { 'X509': expcert } |
---|
43 | else: |
---|
44 | expcert = None |
---|
45 | |
---|
46 | if opts.exp_name: |
---|
47 | msg['experimentID'] = { 'localname': opts.exp_name } |
---|
48 | |
---|
49 | if acerts: |
---|
50 | msg['credential'] = acerts |
---|
51 | |
---|
52 | if opts.debug > 1: print >>sys.stderr, msg |
---|
53 | |
---|
54 | try: |
---|
55 | resp_dict = do_rpc(msg, |
---|
56 | url, opts.transport, cert, opts.trusted, |
---|
57 | serialize_only=opts.serialize_only, |
---|
58 | tracefile=opts.tracefile, |
---|
59 | caller=service_caller("New"), responseBody='NewResponseBody') |
---|
60 | except RPCException, e: |
---|
61 | exit_with_fault(e, 'New', opts) |
---|
62 | except RuntimeError, e: |
---|
63 | sys.exit("Error processing RPC: %s" % e) |
---|
64 | |
---|
65 | if opts.debug > 1: print >>sys.stderr, resp_dict |
---|
66 | |
---|
67 | try: |
---|
68 | save_certfile(opts.out_certfile, resp_dict.get('experimentAccess', None), |
---|
69 | expcert) |
---|
70 | except EnvironmentError, e: |
---|
71 | sys.exit('Could not write to %s:' % (e.strerror, e.filename)) |
---|
72 | except CertificateMismatchError: |
---|
73 | printf >>sys.stderr, "Fedid of created experiment does not match generated" |
---|
74 | |
---|
75 | |
---|
76 | e_fedid, e_local = get_experiment_names(resp_dict.get('experimentID', None)) |
---|
77 | st = resp_dict.get('experimentStatus', None) |
---|
78 | proof = proof.from_dict(resp_dict.get('proof', {})) |
---|
79 | |
---|
80 | if e_local: print "localname: %s" % e_local |
---|
81 | if e_fedid: print "fedid: %s" % e_fedid |
---|
82 | if st: print "status: %s" % st |
---|
83 | if proof and opts.auth_log: |
---|
84 | log_authentication(opts.auth_log, 'New', 'succeeded', proof) |
---|