Skip to content

Commit

Permalink
feat: add possibility to authenticate using access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananias Carvalho committed Sep 20, 2024
1 parent d7b7e85 commit 2991106
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyartifactory/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AuthModel(BaseModel):

url: str
auth: Tuple[str, SecretStr]
access_token: Optional[str] = None
verify: Union[bool, str] = True
cert: Optional[str] = None
api_version: int = 1
Expand Down
12 changes: 11 additions & 1 deletion pyartifactory/objects/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, artifactory: AuthModel) -> None:
self._artifactory.auth[0],
self._artifactory.auth[1].get_secret_value(),
)
self._access_token = self._artifactory.access_token
self._api_version = self._artifactory.api_version
self._verify = self._artifactory.verify
self._cert = self._artifactory.cert
Expand Down Expand Up @@ -78,10 +79,19 @@ def _generic_http_method_request(
:return: An HTTP response
"""

if self._access_token is not None:
headers = kwargs.get("headers", {})
headers["Authorization"] = f"Bearer {self._access_token}"
kwargs["headers"] = headers

auth = None
else:
auth = self._auth

http_method = getattr(self.session, method)
response: Response = http_method(
f"{self._artifactory.url}/{route}",
auth=self._auth,
auth=auth,
**kwargs,
verify=self._verify,
cert=self._cert,
Expand Down

0 comments on commit 2991106

Please sign in to comment.