Skip to content

Commit

Permalink
Add federated repo (#399)
Browse files Browse the repository at this point in the history
* Extract validation to a function

* Create RepositoryFederated class and validate types

Co-authored-by: Aleksey <[email protected]>
  • Loading branch information
RoeeDazz and allburov authored Dec 6, 2022
1 parent 3fda864 commit 8421973
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions dohq_artifactory/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ def _build_query(
query.extend([".limit", limit])
return query

def _validate_type(self, rclass: str, expected_type: str):
if rclass.lower() != expected_type:
raise ArtifactoryException(
f"Repository '{self.name}' have '{rclass}', but expected '{expected_type}'"
)

def search_raw(self, *args, **kwargs):
query = self._build_query(*args, **kwargs)

Expand Down Expand Up @@ -698,8 +704,10 @@ def create_by_type(repo_type="LOCAL", artifactory=None, name=None, *, type=None)
return RepositoryRemote(artifactory, name)
elif repo_type == "VIRTUAL":
return RepositoryVirtual(artifactory, name)
elif repo_type == "FEDERATED":
return RepositoryFederated(artifactory, name)
else:
return None
raise ValueError(f"Unknown repo type: {repo_type}")

@property
def packageType(self):
Expand Down Expand Up @@ -797,14 +805,10 @@ def _read_response(self, response):
"""
JSON Documentation: https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON
"""
rclass = response["rclass"].lower()
if rclass != "local":
raise ArtifactoryException(
"Repository '{}' have '{}', but expect 'local'".format(
self.name, rclass
)
)
self._validate_type(response["rclass"], "local")
self._extract_params(response)

def _extract_params(self, response: dict):
self.name = response["key"]
self.description = response.get("description")
self.package_type = response.get("packageType")
Expand All @@ -813,6 +817,15 @@ def _read_response(self, response):
self.docker_api_version = response.get("dockerApiVersion", None)


class RepositoryFederated(RepositoryLocal):
def _read_response(self, response):
"""
JSON Documentation: https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON
"""
self._validate_type(response["rclass"], "federated")
self._extract_params(response)


class RepositoryVirtual(GenericRepository):
_uri = "repositories"

Expand Down Expand Up @@ -882,13 +895,7 @@ def _read_response(self, response):
"""
JSON Documentation: https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON
"""
rclass = response["rclass"].lower()
if rclass != "virtual":
raise ArtifactoryException(
"Repository '{}' have '{}', but expect 'virtual'".format(
self.name, rclass
)
)
self._validate_type(response["rclass"], "virtual")

self.name = response["key"]
self.description = response.get("description")
Expand Down Expand Up @@ -999,13 +1006,7 @@ def _read_response(self, response):
"""
JSON Documentation: https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON
"""
rclass = response["rclass"].lower()
if rclass != "remote":
raise ArtifactoryException(
"Repository '{}' have '{}', but expect 'remote'".format(
self.name, rclass
)
)
self._validate_type(response["rclass"], "remote")

self.name = response["key"]
self.description = response.get("description")
Expand Down

0 comments on commit 8421973

Please sign in to comment.