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))
评论列表
文章目录