source: fedd/fedd_new.py @ 8fbef04

Last change on this file since 8fbef04 was 6bedbdba, checked in by Ted Faber <faber@…>, 8 years ago

Split topdl and fedid out to different packages. Add differential
installs

  • Property mode set to 100755
File size: 2.6 KB
Line 
1#!/usr/bin/env python
2
3import sys
4from datetime import datetime
5
6from deter import fedid, generate_fedid
7from federation.remote_service import service_caller
8from federation.proof import proof
9from 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
13class 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
25parser = new_opts()
26(opts, args) = parser.parse_args()
27
28try:
29    cert, fid, url = wrangle_standard_options(opts)
30    acerts = get_abac_certs(opts.abac_dir)
31except EnvironmentError, e:
32    sys.exit('%s: %s' % (e.filename, e.strerror))
33except RuntimeError, e:
34    sys.exit("%s" %e)
35
36out_certfile = opts.out_certfile
37
38msg = { }
39
40if opts.gen_cert:
41    expid, expcert = generate_fedid(opts.exp_name or 'dummy')
42    msg['experimentAccess'] = { 'X509': expcert }
43else:
44    expcert = None
45
46if opts.exp_name:
47    msg['experimentID'] = { 'localname': opts.exp_name }
48
49if acerts:
50    msg['credential'] = acerts
51
52if opts.debug > 1: print >>sys.stderr, msg
53
54try:
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')
60except RPCException, e:
61    exit_with_fault(e, 'New', opts)
62except RuntimeError, e:
63    sys.exit("Error processing RPC: %s" % e)
64
65if opts.debug > 1: print >>sys.stderr, resp_dict
66
67try:
68    save_certfile(opts.out_certfile, resp_dict.get('experimentAccess', None), 
69            expcert)
70except EnvironmentError, e:
71    sys.exit('Could not write to %s:' %  (e.strerror, e.filename))
72except CertificateMismatchError:
73    printf >>sys.stderr, "Fedid of created experiment does not match generated"
74
75
76e_fedid, e_local = get_experiment_names(resp_dict.get('experimentID', None))
77st = resp_dict.get('experimentStatus', None)
78proof = proof.from_dict(resp_dict.get('proof', {}))
79
80if e_local: print "localname: %s" % e_local
81if e_fedid: print "fedid: %s" % e_fedid
82if st: print "status: %s" % st
83if proof and opts.auth_log:
84    log_authentication(opts.auth_log, 'New', 'succeeded', proof)
Note: See TracBrowser for help on using the repository browser.