예제 #1
0
def main():
    args = docopt(__doc__, version="keyfor " + VERSION)

    masterkey = get_masterkey(username=args["--username"])
    keychain = KeyChain(path=os.path.expanduser(config["key_path"]), masterkey=masterkey)

    if "<label>" in args and args["<label>"]:
        label = args["<label>"]
        subset = args["<subset>"]

        if "add" in args and args["add"]:
            keys = keychain.list_keys()
            if label in keys:
                print "Key already stored for label: " + label + ", -u to update or ommit flags to read"
                return
            print "Create a new key for: " + label
            credentials = get_credentials(username=masterkey.username)
            key = Key(label=label, username=credentials["username"], password=credentials["password"])
            keychain.save_key(key)
            print "created new key for: " + key.label
            show_key(key, subset)

        elif "edit" in args and args["edit"]:
            key = read_key(keychain, label)
            if key:
                credentials = get_credentials(username=key.username, password=key.password)
                key.username = credentials["username"]
                key.password = credentials["password"]
                keychain.save_key(key)
                print "Updated key for label: " + label
                show_key(key, subset)

        elif "delete" in args and args["delete"]:
            if key_exists(keychain, label):
                keychain.delete_key(label)

        elif "refresh" in args and args["refresh"]:
            if key_exists(keychain, label):
                refresh_key(keychain, label)

        elif "verify" in args and args["verify"]:
            if key_exists(keychain, label):
                verify_key(keychain, label)

        else:
            key = read_key(keychain, label)
            if key:
                shoud_print = "--print" in args and args["--print"]
                show_key(key, subset, shoud_print=shoud_print)

    elif "all" in args and args["all"]:

        if "refresh" in args and args["refresh"]:
            for label in keychain.list_keys():
                refresh_key(keychain, label)

        elif "verify" in args and args["verify"]:
            for label in keychain.list_keys():
                verify_key(keychain, label)

        elif "list" in args and args["list"]:
            for label in keychain.list_keys():
                print label

    else:
        print __doc__
예제 #2
0
파일: __main__.py 프로젝트: simbha/keyfor
def main():    
    args = docopt(__doc__, version='keyfor '+VERSION)
    
    # print repr(args)

    masterkey = get_masterkey(username=args['--username'])
    keychain = KeyChain(path=os.path.expanduser(config['key_path']), masterkey=masterkey)
    
    if '<label>' in args and args['<label>']:
        label = args['<label>']
        
        if 'add' in args and args['add']:
            keys = keychain.list_keys()
            if label in keys:
                print "Key already stored for label: " + label +", -u to update or ommit flags to read"
                return
            print "Create a new key for: " + label
            credentials = get_credentials(username=masterkey.username)
            key = Key(label=label, username=credentials['username'], password=credentials['password'])
            keychain.save_key(key)
            print "created new key for: "+key.label
            show_key(key)
            
        elif 'edit' in args and args['edit']:
            key = read_key(keychain, label)
            if key:
                credentials = get_credentials(username=key.username, password=key.password)
                key.username = credentials['username']
                key.password = credentials['password']
                keychain.save_key(key)
                print "Updated key for label: " + label
                show_key(key)
                
        elif 'delete' in args and args['delete']:
            if key_exists(keychain, label):
                keychain.delete_key(label)
                
        elif 'refresh' in args and args['refresh']:
            if key_exists(keychain, label):
                refresh_key(keychain, label)
                
        elif 'verify' in args and args['verify']:
            if key_exists(keychain, label):
                verify_key(keychain, label)
                    
        else:
            key = read_key(keychain, label)
            if key:
                show_key(key)
                
    elif 'all' in args and args['all']:
                
        if 'refresh' in args and args['refresh']:
            for label in keychain.list_keys():
                refresh_key(keychain, label)
        
        elif 'verify' in args and args['verify']:
            for label in keychain.list_keys():
                verify_key(keychain, label)
        
        elif 'list' in args and args['list']:
            for label in keychain.list_keys():
                print label
        
    else:
        print __doc__