Skip to content

Commit 87cfaae

Browse files
committed
fix: fix create local repository
1 parent 8236326 commit 87cfaae

5 files changed

Lines changed: 28 additions & 13 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# vscode
129129
.vscode/
130+
131+
# ruff
132+
.ruff_cache

pyartifactory/objects/artifact.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import requests
1010
from pydantic import ValidationError
11+
from requests import Response
1112

1213
from pyartifactory.exception import ArtifactNotFoundError, ArtifactoryError, BadPropertiesError, PropertyNotFoundError
1314
from pyartifactory.models.artifact import (
@@ -65,7 +66,8 @@ def info(self, artifact_path: Union[Path, str]) -> ArtifactInfoResponse:
6566
artifact_info = ArtifactFileInfoResponse.model_validate(response.json())
6667
return artifact_info
6768
except requests.exceptions.HTTPError as error:
68-
if error.response.status_code == 404:
69+
http_response: Union[Response, None] = error.response
70+
if isinstance(http_response, Response) and http_response.status_code == 404:
6971
logger.error("Artifact %s does not exist", artifact_path)
7072
raise ArtifactNotFoundError(f"Artifact {artifact_path} does not exist")
7173
raise ArtifactoryError from error
@@ -174,7 +176,8 @@ def list(
174176
artifact_list: ArtifactListResponse = ArtifactListResponse.model_validate(response.json())
175177
return artifact_list
176178
except requests.exceptions.HTTPError as error:
177-
if error.response.status_code == 404:
179+
http_response: Union[Response, None] = error.response
180+
if isinstance(http_response, Response) and http_response.status_code == 404:
178181
logger.error("Artifact %s does not exist", artifact_path)
179182
raise ArtifactNotFoundError(f"Artifact {artifact_path} does not exist")
180183
raise ArtifactoryError from error
@@ -196,7 +199,8 @@ def properties(self, artifact_path: str, properties: Optional[List[str]] = None)
196199
logger.debug("Artifact Properties successfully retrieved")
197200
return ArtifactPropertiesResponse(**response.json())
198201
except requests.exceptions.HTTPError as error:
199-
if error.response.status_code == 404:
202+
http_response: Union[Response, None] = error.response
203+
if isinstance(http_response, Response) and http_response.status_code == 404:
200204
raise PropertyNotFoundError(f"Properties {properties} were not found on artifact {artifact_path}")
201205
raise ArtifactoryError from error
202206

@@ -230,10 +234,11 @@ def set_properties(
230234
logger.debug("Artifact Properties successfully set")
231235
return self.properties(artifact_path)
232236
except requests.exceptions.HTTPError as error:
233-
if error.response.status_code == 404:
237+
http_response: Union[Response, None] = error.response
238+
if isinstance(http_response, Response) and http_response.status_code == 404:
234239
logger.error("Artifact %s does not exist", artifact_path)
235240
raise ArtifactNotFoundError(f"Artifact {artifact_path} does not exist")
236-
if error.response.status_code == 400:
241+
if isinstance(http_response, Response) and http_response.status_code == 400:
237242
logger.error("A property value includes forbidden special characters")
238243
raise BadPropertiesError("A property value includes forbidden special characters")
239244
raise ArtifactoryError from error
@@ -263,7 +268,8 @@ def update_properties(
263268
logger.debug("Artifact Properties successfully updated")
264269
return self.properties(artifact_path)
265270
except requests.exceptions.HTTPError as error:
266-
if error.response.status_code == 400:
271+
http_response: Union[Response, None] = error.response
272+
if isinstance(http_response, Response) and http_response.status_code == 400:
267273
logger.error("Error updating artifact properties")
268274
raise ArtifactoryError("Error updating artifact properties")
269275
raise ArtifactoryError from error

pyartifactory/objects/group.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import annotations
22

33
import logging
4-
from typing import List
4+
from typing import List, Union
55

66
import requests
7+
from requests import Response
78

89
from pyartifactory.exception import ArtifactoryError, GroupAlreadyExistsError, GroupNotFoundError
910
from pyartifactory.models.group import Group
@@ -44,7 +45,8 @@ def get(self, name: str) -> Group:
4445
logger.debug("Group %s found", name)
4546
return Group(**response.json())
4647
except requests.exceptions.HTTPError as error:
47-
if error.response.status_code in (404, 400):
48+
http_response: Union[Response, None] = error.response
49+
if isinstance(http_response, Response) and http_response.status_code in (404, 400):
4850
logger.error("Group %s does not exist", name)
4951
raise GroupNotFoundError(f"Group {name} does not exist")
5052
raise ArtifactoryError from error

pyartifactory/objects/repository.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import json
44
import logging
5-
from typing import List, overload
5+
from typing import List, Union, overload
66

77
import requests
88
from pydantic import ValidationError
9+
from requests import Response
910

1011
from pyartifactory.exception import ArtifactoryError, RepositoryAlreadyExistsError, RepositoryNotFoundError
1112
from pyartifactory.models import AnyRepository, AnyRepositoryResponse
@@ -47,13 +48,14 @@ def get_repo(self, repo_name: str) -> AnyRepositoryResponse:
4748
artifact_info = RemoteRepositoryResponse.model_validate(response.json())
4849
return artifact_info
4950
except requests.exceptions.HTTPError as error:
50-
if error.response.status_code in (404, 400):
51+
http_response: Union[Response, None] = error.response
52+
if isinstance(http_response, Response) and http_response.status_code in (404, 400):
5153
logger.error("Repository %s does not exist", repo_name)
5254
raise RepositoryNotFoundError(f" Repository {repo_name} does not exist")
5355
raise ArtifactoryError from error
5456

5557
@overload
56-
def create_repo(self, repo: LocalRepositoryResponse) -> LocalRepositoryResponse:
58+
def create_repo(self, repo: LocalRepository) -> LocalRepositoryResponse:
5759
...
5860

5961
@overload

pyartifactory/objects/user.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import annotations
22

33
import logging
4-
from typing import List
4+
from typing import List, Union
55

66
import requests
7+
from requests import Response
78

89
from pyartifactory.exception import ArtifactoryError, UserAlreadyExistsError, UserNotFoundError
910
from pyartifactory.models.user import NewUser, SimpleUser, User, UserResponse
@@ -46,7 +47,8 @@ def get(self, name: str) -> UserResponse:
4647
logger.debug("User %s found", name)
4748
return UserResponse(**response.json())
4849
except requests.exceptions.HTTPError as error:
49-
if error.response.status_code in (404, 400):
50+
http_response: Union[Response, None] = error.response
51+
if isinstance(http_response, Response) and http_response.status_code in (404, 400):
5052
logger.error("User %s does not exist", name)
5153
raise UserNotFoundError(f"{name} does not exist")
5254
raise ArtifactoryError from error

0 commit comments

Comments
 (0)