示例#1
0
    def __call__(self, args):

        email = config.email

        if args.command == "generate":
            yield [geneate_keys()]
        elif args.command == "delete":
            with get_cred(config.oauth_gcp_conf) as cred:
                yield from delete_gpg_key(args.argument, config.password)
                delete_gpg(cred, email, args.argument)
        elif args.command == "list-pub":
            yield from get_existing_pub_keys(args.argument)
        elif args.command == "list-priv":
            yield from get_existing_priv_keys()
        elif args.command == "pull":
            with get_cred(config.oauth_gcp_conf) as cred:
                if args.argument:
                    email = args.argument
                privs = get_gpgs(cred, email, key_type="priv")
                pubs = get_gpgs(cred, email, key_type="pub")
                for p in privs:
                    yield from import_gpg_key(p["data"])
                for p in pubs:
                    yield from import_gpg_key(p["data"])
        elif args.command == "push":
            if not config.export_priv_key:
                yield [
                    "configuration denies pushing priv key. Please update config first"
                ]
            password = None
            if config.export_password:
                password = config.password
                yield ["exporting password with key"]
            email = config.email
            with get_cred(config.oauth_gcp_conf) as cred:
                for k in get_existing_priv_keys():
                    key_id = k[0]
                    priv_key = export_key(key_id, True)
                    put_gpg(
                        cred,
                        email,
                        priv_key,
                        key_type="priv",
                        key_name=key_id,
                        password=password,
                    )
                    yield key_id, email
                for k in get_existing_pub_keys(config.email):
                    key_id = k[0]
                    pub_key = export_key(key_id, False)
                    put_gpg(cred,
                            email,
                            pub_key,
                            key_type="pub",
                            key_name=key_id)
                    yield key_id, email

        else:
            raise Exception("not supported subcommands")
示例#2
0
 def test_import_gpg_key_ok_data(self, mocker, username, password, pub_key):
     import_gpg_key(pub_key)
示例#3
0
 def test_import_gpg_key_invalid_data(self, mocker, username, password, keypair):
     with pytest.raises(GPGException):
         for _ in import_gpg_key("invalid data"):
             pass
示例#4
0
文件: base.py 项目: n0npax/lime-comb
def import_keys(email, cred, *, key_type="pub"):
    for key in api.get_gpgs(cred, email, key_type=key_type):
        yield from gpg.import_gpg_key(key["data"])
示例#5
0
def import_keys(email, cred, *, key_type="pub"):
    for key_str in get_gpgs(cred, email, key_type=key_type):
        yield from import_gpg_key(key_str)