Skip to content

Commit c9515bb

Browse files
committed
fix: update authentication method to use Bearer token for Docker Hub API
1 parent 1cd4324 commit c9515bb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

scripts/prune/registries/dockerhub.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ def _get_auth_token(self) -> str:
3030
if self._auth_token:
3131
return self._auth_token
3232

33+
self._auth_token = self.password
34+
35+
sess = requests.Session()
36+
sess.headers.update({
37+
'Authorization': f'Bearer {self._auth_token}',
38+
'Content-Type': 'application/json'
39+
})
40+
41+
test_url = f'{self.DOCKER_HUB_API}/repositories/{self.username}/'
42+
resp = sess.get(test_url, params={'page_size': 1})
43+
44+
if resp.status_code == 200:
45+
return self._auth_token
46+
3347
auth_data = {
3448
'username': self.username,
3549
'password': self.password
@@ -50,7 +64,7 @@ def list_versions(self) -> List[ImageVersion]:
5064

5165
sess = requests.Session()
5266
sess.headers.update({
53-
'Authorization': f'JWT {token}',
67+
'Authorization': f'Bearer {token}',
5468
'Content-Type': 'application/json'
5569
})
5670

@@ -116,7 +130,7 @@ def delete_version(self, version_id: str) -> bool:
116130

117131
sess = requests.Session()
118132
sess.headers.update({
119-
'Authorization': f'JWT {token}',
133+
'Authorization': f'Bearer {token}',
120134
'Content-Type': 'application/json'
121135
})
122136

0 commit comments

Comments
 (0)