Skip to content

Commit 2991106

Browse files
author
Ananias Carvalho
committed
feat: add possibility to authenticate using access_token
1 parent d7b7e85 commit 2991106

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

pyartifactory/models/auth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class AuthModel(BaseModel):
1313

1414
url: str
1515
auth: Tuple[str, SecretStr]
16+
access_token: Optional[str] = None
1617
verify: Union[bool, str] = True
1718
cert: Optional[str] = None
1819
api_version: int = 1

pyartifactory/objects/object.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, artifactory: AuthModel) -> None:
1818
self._artifactory.auth[0],
1919
self._artifactory.auth[1].get_secret_value(),
2020
)
21+
self._access_token = self._artifactory.access_token
2122
self._api_version = self._artifactory.api_version
2223
self._verify = self._artifactory.verify
2324
self._cert = self._artifactory.cert
@@ -78,10 +79,19 @@ def _generic_http_method_request(
7879
:return: An HTTP response
7980
"""
8081

82+
if self._access_token is not None:
83+
headers = kwargs.get("headers", {})
84+
headers["Authorization"] = f"Bearer {self._access_token}"
85+
kwargs["headers"] = headers
86+
87+
auth = None
88+
else:
89+
auth = self._auth
90+
8191
http_method = getattr(self.session, method)
8292
response: Response = http_method(
8393
f"{self._artifactory.url}/{route}",
84-
auth=self._auth,
94+
auth=auth,
8595
**kwargs,
8696
verify=self._verify,
8797
cert=self._cert,

0 commit comments

Comments
 (0)