helpers.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:dockerscan 作者: cr0hn 项目源码 文件源码
def get_remote_registry_info(target: str) -> Union[Set,
                                                   DockerscanTimeoutError]:
    """
    This function does two things:

    - detect the remote registry version. Allowed returned values are: {1, 2}
    - detect if remote Docker Registry has enabled the authentication

    :return: a tuple as format: (REMOTE_VERSION, ENABLED_OR_NOT_AUTH)
    :rtype: tuple(int, bool)

    :raise DockerscanTimeoutError: If remote server reach a timeout
    """
    #
    # Check for verion 2
    #
    remote_version = 1
    enabled_auth = False

    try:
        r = requests.get("{}/v2/".format(target),
                         timeout=2,
                         allow_redirects=False,
                         verify=False)

        if r.status_code in (200, 401):
            if "registry/2.0" in r.headers["Docker-Distribution-Api-Version"]:
                remote_version = 2

            if r.status_code == 401:
                enabled_auth = True

        return remote_version, enabled_auth

    except (ConnectTimeout, ConnectionError) as e:
        raise DockerscanTimeoutError("Remote registry '{}' do not responds".
                                     format(target))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号