source: fedd/creddy_split.py @ 56baf92

axis_examplecompt_changesinfo-ops
Last change on this file since 56baf92 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
RevLine 
[2e46f35]1#!/usr/bin/env python
[87c0fc1]2
3import sys
4import re
5import os
6
[62f3dd9]7from federation.util import abac_split_cert, abac_pem_type, file_expanding_opts
[87c0fc1]8
9# Options
[62f3dd9]10class Parser(file_expanding_opts):
[87c0fc1]11    def __init__(self):
[62f3dd9]12        file_expanding_opts.__init__(self, usage="%prog [options] file.pem")
[87c0fc1]13        self.add_option('--cert', dest='cert', default='./cert.pem', 
[62f3dd9]14                action='callback', callback=self.expand_file, type='str',
[87c0fc1]15                help='File to extract certificate into, default: [%default]')
16        self.add_option('--key', dest='key', default='./key.pem', 
[62f3dd9]17                action='callback', callback=self.expand_file, type='str',
[87c0fc1]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
[353db8c]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)
[87c0fc1]38
39try:
[353db8c]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'));
[87c0fc1]45except EnvironmentError, e:
46    sys.exit("%s: %s" % (e.strerror, e.filename or '?!'))
Note: See TracBrowser for help on using the repository browser.