Skip to content

Commit d13143c

Browse files
committed
feat: allow anonymous authentication
1 parent 2991106 commit d13143c

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ This library enables you to manage Artifactory resources such as users, groups,
1717
- [Install](#install)
1818
- [Usage](#usage)
1919
* [Authentication](#authentication)
20+
+ [Basic authentication](#basic-authentication)
21+
+ [Authentication with access token](#authentication-with-access-token)
22+
+ [Anonymous authentication](#anonymous-authentication)
2023
* [SSL Cert Verification Options](#ssl-cert-verification-options)
2124
* [Timeout option](#timeout-option)
2225
* [Admin objects](#admin-objects)
@@ -69,11 +72,24 @@ pip install pyartifactory
6972

7073
Since Artifactory 6.6.0 there is version 2 of the REST API for permission management, in case you have that version or higher, you need to pass api_version=2 to the constructor when you instantiate the class.
7174

75+
#### Basic authentication
7276
```python
7377
from pyartifactory import Artifactory
7478
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), api_version=1)
7579
```
7680

81+
#### Authentication with access token
82+
```python
83+
from pyartifactory import Artifactory
84+
art = Artifactory(url="ARTIFACTORY_URL", access_token="your-access-token")
85+
```
86+
87+
#### Anonymous authentication
88+
```python
89+
from pyartifactory import Artifactory
90+
art = Artifactory(url="ARTIFACTORY_URL", anonymous_auth=True)
91+
```
92+
7793
### SSL Cert Verification Options
7894

7995
Specify a local cert to use as client side certificate

pyartifactory/models/auth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class AuthModel(BaseModel):
1414
url: str
1515
auth: Tuple[str, SecretStr]
1616
access_token: Optional[str] = None
17+
anonymous_auth: bool = False
1718
verify: Union[bool, str] = True
1819
cert: Optional[str] = None
1920
api_version: int = 1

pyartifactory/objects/object.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self, artifactory: AuthModel) -> None:
1919
self._artifactory.auth[1].get_secret_value(),
2020
)
2121
self._access_token = self._artifactory.access_token
22+
self._anonymous_auth = self._artifactory.anonymous_auth
2223
self._api_version = self._artifactory.api_version
2324
self._verify = self._artifactory.verify
2425
self._cert = self._artifactory.cert
@@ -79,14 +80,17 @@ def _generic_http_method_request(
7980
:return: An HTTP response
8081
"""
8182

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-
83+
if self._anonymous_auth:
8784
auth = None
8885
else:
89-
auth = self._auth
86+
if self._access_token is not None:
87+
headers = kwargs.get("headers", {})
88+
headers["Authorization"] = f"Bearer {self._access_token}"
89+
kwargs["headers"] = headers
90+
91+
auth = None
92+
else:
93+
auth = self._auth
9094

9195
http_method = getattr(self.session, method)
9296
response: Response = http_method(

0 commit comments

Comments
 (0)