Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/add federated repo #399

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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