diff --git a/dohq_artifactory/admin.py b/dohq_artifactory/admin.py index 7b49e87..748a6c3 100644 --- a/dohq_artifactory/admin.py +++ b/dohq_artifactory/admin.py @@ -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) @@ -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): @@ -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") @@ -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" @@ -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") @@ -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")