From: garciadeblas Date: Fri, 20 Oct 2023 09:12:21 +0000 (+0200) Subject: Feature 10997: add oci flag as new property in helm-chart repos X-Git-Tag: release-v15.0-start^0 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F76%2F13976%2F4;p=osm%2Fosmclient.git Feature 10997: add oci flag as new property in helm-chart repos Change-Id: Ic0a826fc10709b210704d5615295364e66ac455c Signed-off-by: garciadeblas --- diff --git a/osmclient/cli_commands/repo.py b/osmclient/cli_commands/repo.py index 2e5b860..495bd7f 100755 --- a/osmclient/cli_commands/repo.py +++ b/osmclient/cli_commands/repo.py @@ -29,9 +29,9 @@ logger = logging.getLogger("osmclient") @click.argument("uri") @click.option( "--type", - type=click.Choice(["helm-chart", "juju-bundle", "osm"]), + type=click.Choice(["osm", "helm-chart", "juju-bundle"]), default="osm", - help="type of repo (helm-chart for Helm Charts, juju-bundle for Juju Bundles, osm for OSM Repositories)", + help="type of repo (osm for OSM repositories, helm-chart for Helm Charts, juju-bundle for Juju Bundles)", ) @click.option("--description", default=None, help="human readable description") @click.option( @@ -42,6 +42,11 @@ logger = logging.getLogger("osmclient") default=None, help="OSM repository: The password of the OSM repository", ) +@click.option( + "--oci", + is_flag=True, + help="enable OCI (only for helm-chart repos, default: false, automatically set to true for oci:// URI)", +) @click.pass_context def repo_add(ctx, **kwargs): """adds a repo to OSM @@ -52,6 +57,8 @@ def repo_add(ctx, **kwargs): kwargs = {k: v for k, v in kwargs.items() if v is not None} repo = kwargs repo["url"] = repo.pop("uri") + if repo["url"].startswith("oci://"): + repo["oci"] = True if repo["type"] in ["helm-chart", "juju-bundle"]: ctx.obj.repo.create(repo["name"], repo) else: @@ -63,8 +70,13 @@ def repo_add(ctx, **kwargs): @click.option("--newname", help="New name for the repo") @click.option("--uri", help="URI of the repo") @click.option("--description", help="human readable description") +@click.option( + "--oci", + is_flag=True, + help="enable OCI (only for helm-chart repos, default: false, automatically set to true for oci:// URI)", +) @click.pass_context -def repo_update(ctx, name, newname, uri, description): +def repo_update(ctx, name, newname, uri, description, oci): """updates a repo in OSM NAME: name of the repo @@ -74,9 +86,13 @@ def repo_update(ctx, name, newname, uri, description): if newname: repo["name"] = newname if uri: - repo["uri"] = uri + repo["url"] = uri + if uri.startswith("oci://"): + repo["oci"] = True if description: repo["description"] = description + if oci: + repo["oci"] = oci try: ctx.obj.repo.update(name, repo) except NotFound: diff --git a/osmclient/sol005/repo.py b/osmclient/sol005/repo.py index 6e6e927..00b95eb 100644 --- a/osmclient/sol005/repo.py +++ b/osmclient/sol005/repo.py @@ -33,7 +33,12 @@ class Repo(object): self._apiName, self._apiVersion, self._apiResource ) + def check_oci(self, repo): + if repo["oci"] and repo["type"] != "helm-chart": + raise ClientException("OCI can only be enabled in helm-chart repos") + def create(self, name, repo): + self.check_oci(repo) self._client.get_token() http_code, resp = self._http.post_cmd( endpoint=self._apiBase, postfields_dict=repo @@ -56,6 +61,7 @@ class Repo(object): # raise ClientException("failed to add repo {} - {}".format(name, msg)) def update(self, name, repo): + self.check_oci(repo) self._client.get_token() repo_dict = self.get(name) http_code, resp = self._http.put_cmd(