Skip to content

Commit 8f43c03

Browse files
committed
Support 401 status for v2 registry endpoint
1 parent d70aa1e commit 8f43c03

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

docker/utils/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,21 @@ def compare_version(v1, v2):
120120

121121

122122
def ping_registry(url):
123-
return ping(url + '/v2/') or ping(url + '/v1/_ping')
123+
return ping(url + '/v2/', [401]) or ping(url + '/v1/_ping')
124124

125125

126-
def ping(url):
126+
def ping(url, valid_4xx_statuses=None):
127127
try:
128128
res = requests.get(url, timeout=3)
129129
except Exception:
130130
return False
131131
else:
132132
# We don't send yet auth headers
133133
# and a v2 registry will respond with status 401
134-
return res.status_code == 401 or res.status_code < 400
134+
return (
135+
res.status_code < 400 or
136+
(valid_4xx_statuses and res.status_code in valid_4xx_statuses)
137+
)
135138

136139

137140
def _convert_port_binding(binding):

0 commit comments

Comments
 (0)