X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fcli_commands%2Frepo.py;h=b2ecd9a75872d58c5561e2a9b08f42aa6ee09230;hb=c0420cf86aaed737f59666516dd9e4de5c5db16c;hp=495bd7f147b50cbc74da1cf66aae52ce00ab61ba;hpb=f5b188e14053b2246be507a23d9eef5ff7e42123;p=osm%2Fosmclient.git diff --git a/osmclient/cli_commands/repo.py b/osmclient/cli_commands/repo.py index 495bd7f..b2ecd9a 100755 --- a/osmclient/cli_commands/repo.py +++ b/osmclient/cli_commands/repo.py @@ -14,7 +14,7 @@ # under the License. import click -from osmclient.common.exceptions import NotFound +from osmclient.common.exceptions import NotFound, ClientException from osmclient.cli_commands import utils from prettytable import PrettyTable import yaml @@ -47,6 +47,11 @@ logger = logging.getLogger("osmclient") is_flag=True, help="enable OCI (only for helm-chart repos, default: false, automatically set to true for oci:// URI)", ) +@click.option( + "--ca-file", + default=None, + help="cert to use when adding a repository (only for helm)", +) @click.pass_context def repo_add(ctx, **kwargs): """adds a repo to OSM @@ -59,6 +64,19 @@ def repo_add(ctx, **kwargs): repo["url"] = repo.pop("uri") if repo["url"].startswith("oci://"): repo["oci"] = True + if "ca_file" in kwargs: + try: + with open(kwargs["ca_file"], "r") as ca_cert: + repo["cacert"] = ca_cert.read() + repo.pop("ca_file") + except FileNotFoundError: + raise ClientException("CA file not found !") + except EOFError: + raise ClientException("Empty CA file !") + except PermissionError: + raise ClientException("Can not read CA file ! Insufficient permissions") + except Exception as e: + raise ClientException(f"Can not read the cert file ! Error: {e}") if repo["type"] in ["helm-chart", "juju-bundle"]: ctx.obj.repo.create(repo["name"], repo) else: