Skip to content

Commit

Permalink
feat: allow anonymous authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
anancarv committed Sep 20, 2024
1 parent 2991106 commit d13143c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ This library enables you to manage Artifactory resources such as users, groups,
- [Install](#install)
- [Usage](#usage)
* [Authentication](#authentication)
+ [Basic authentication](#basic-authentication)
+ [Authentication with access token](#authentication-with-access-token)
+ [Anonymous authentication](#anonymous-authentication)
* [SSL Cert Verification Options](#ssl-cert-verification-options)
* [Timeout option](#timeout-option)
* [Admin objects](#admin-objects)
Expand Down Expand Up @@ -69,11 +72,24 @@ pip install pyartifactory

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.

#### Basic authentication
```python
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), api_version=1)
```

#### Authentication with access token
```python
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", access_token="your-access-token")
```

#### Anonymous authentication
```python
from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", anonymous_auth=True)
```

### SSL Cert Verification Options

Specify a local cert to use as client side certificate
Expand Down
1 change: 1 addition & 0 deletions pyartifactory/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AuthModel(BaseModel):
url: str
auth: Tuple[str, SecretStr]
access_token: Optional[str] = None
anonymous_auth: bool = False
verify: Union[bool, str] = True
cert: Optional[str] = None
api_version: int = 1
Expand Down
16 changes: 10 additions & 6 deletions pyartifactory/objects/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, artifactory: AuthModel) -> None:
self._artifactory.auth[1].get_secret_value(),
)
self._access_token = self._artifactory.access_token
self._anonymous_auth = self._artifactory.anonymous_auth
self._api_version = self._artifactory.api_version
self._verify = self._artifactory.verify
self._cert = self._artifactory.cert
Expand Down Expand Up @@ -79,14 +80,17 @@ 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

if self._anonymous_auth:
auth = None
else:
auth = self._auth
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(
Expand Down

0 comments on commit d13143c

Please sign in to comment.