当前位置: 首页>>代码示例>>Python>>正文


Python fetch.GPGKeyError方法代码示例

本文整理汇总了Python中charmhelpers.fetch.GPGKeyError方法的典型用法代码示例。如果您正苦于以下问题:Python fetch.GPGKeyError方法的具体用法?Python fetch.GPGKeyError怎么用?Python fetch.GPGKeyError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在charmhelpers.fetch的用法示例。


在下文中一共展示了fetch.GPGKeyError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_key

# 需要导入模块: from charmhelpers import fetch [as 别名]
# 或者: from charmhelpers.fetch import GPGKeyError [as 别名]
def import_key(key):
    """Import an ASCII Armor key.

    /!\ A Radix64 format keyid is also supported for backwards
    compatibility, but should never be used; the key retrieval
    mechanism is insecure and subject to man-in-the-middle attacks
    voiding all signature checks using that key.

    :param keyid: The key in ASCII armor format,
                  including BEGIN and END markers.
    :raises: GPGKeyError if the key could not be imported
    """
    key = key.strip()
    if '-' in key or '\n' in key:
        # Send everything not obviously a keyid to GPG to import, as
        # we trust its validation better than our own. eg. handling
        # comments before the key.
        log("PGP key found (looks like ASCII Armor format)", level=DEBUG)
        if ('-----BEGIN PGP PUBLIC KEY BLOCK-----' in key and
                '-----END PGP PUBLIC KEY BLOCK-----' in key):
            log("Importing ASCII Armor PGP key", level=DEBUG)
            with NamedTemporaryFile() as keyfile:
                with open(keyfile.name, 'w') as fd:
                    fd.write(key)
                    fd.write("\n")
                cmd = ['apt-key', 'add', keyfile.name]
                try:
                    subprocess.check_call(cmd)
                except subprocess.CalledProcessError:
                    error = "Error importing PGP key '{}'".format(key)
                    log(error)
                    raise GPGKeyError(error)
        else:
            raise GPGKeyError("ASCII armor markers missing from GPG key")
    else:
        # We should only send things obviously not a keyid offsite
        # via this unsecured protocol, as it may be a secret or part
        # of one.
        log("PGP key found (looks like Radix64 format)", level=WARNING)
        log("INSECURLY importing PGP key from keyserver; "
            "full key not provided.", level=WARNING)
        cmd = ['apt-key', 'adv', '--keyserver',
               'hkp://keyserver.ubuntu.com:80', '--recv-keys', key]
        try:
            subprocess.check_call(cmd)
        except subprocess.CalledProcessError:
            error = "Error importing PGP key '{}'".format(key)
            log(error)
            raise GPGKeyError(error) 
开发者ID:openstack,项目名称:charm-swift-proxy,代码行数:51,代码来源:ubuntu.py


注:本文中的charmhelpers.fetch.GPGKeyError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。