source: fedd/creddy_split.py @ 771a277

axis_examplecompt_changesinfo-ops
Last change on this file since 771a277 was 2e46f35, checked in by mikeryan <mikeryan@…>, 14 years ago

switch to /usr/bin/env python to run python

  • Property mode set to 100755
File size: 1.4 KB
Line 
1#!/usr/bin/env python
2
3import sys
4import re
5import os
6
7from federation.util import abac_split_cert, abac_pem_type, file_expanding_opts
8
9# Options
10class Parser(file_expanding_opts):
11    def __init__(self):
12        file_expanding_opts.__init__(self, usage="%prog [options] file.pem")
13        self.add_option('--cert', dest='cert', default='./cert.pem', 
14                action='callback', callback=self.expand_file, type='str',
15                help='File to extract certificate into, default: [%default]')
16        self.add_option('--key', dest='key', default='./key.pem', 
17                action='callback', callback=self.expand_file, type='str',
18                help='File to extract key into, default: [%default]')
19        self.add_option('--force', action='store_true', dest='force',
20                default=False,
21                help=('Overwite existing certificate and key files. ' + \
22                        'default: [%default]'))
23
24# Option validation
25parser = Parser()
26opts, args = parser.parse_args()
27
28if len(args) == 1:
29    combo = args[0]
30else:
31    parser.print_help()
32    sys.exit('\nMust have one file argument')
33
34for fn in (opts.cert, opts.key):
35    if os.access(fn, os.F_OK):
36        if opts.force: os.unlink(fn)
37        else: sys.exit('%s exists.  --force to overwite it' % fn)
38
39try:
40    type = abac_pem_type(combo)
41    if type == 'both':
42        abac_split_cert(combo, opts.key, opts.cert)
43    else:
44        sys.exit('Cannot split %s as it is a %s' % (combo, type or 'dunno'));
45except EnvironmentError, e:
46    sys.exit("%s: %s" % (e.strerror, e.filename or '?!'))
Note: See TracBrowser for help on using the repository browser.