diff --git a/e2e/test_cli.sh b/e2e/test_cli.sh index 755af15..817c51d 100755 --- a/e2e/test_cli.sh +++ b/e2e/test_cli.sh @@ -12,9 +12,9 @@ pip install dist/omlmd-*.whl echo "Running E2E test for CLI ..." -omlmd push localhost:5001/mmortari/mlartifact:v1 README.md --metadata tests/data/md.json +omlmd push localhost:5001/mmortari/mlartifact:v1 README.md --metadata tests/data/md.json --plain-http -omlmd pull localhost:5001/mmortari/mlartifact:v1 -o tmp/a +omlmd pull localhost:5001/mmortari/mlartifact:v1 -o tmp/a --plain-http file_count=$(find "tmp/a" -type f | wc -l) if [ "$file_count" -eq 3 ]; then echo "Expected 3 files in $DIR, ok." @@ -23,7 +23,7 @@ else exit 1 fi -omlmd pull localhost:5001/mmortari/mlartifact:v1 -o tmp/b --media-types "application/x-mlmodel" +omlmd pull localhost:5001/mmortari/mlartifact:v1 -o tmp/b --media-types "application/x-mlmodel" --plain-http file_count=$(find "tmp/b" -type f | wc -l) if [ "$file_count" -eq 1 ]; then echo "Expected 1 files in $DIR, ok." @@ -32,9 +32,9 @@ else exit 1 fi -omlmd get config localhost:5001/mmortari/mlartifact:v1 -omlmd crawl localhost:5001/mmortari/mlartifact:v1 localhost:5001/mmortari/mlartifact:v1 | jq . -omlmd crawl \ +omlmd get config localhost:5001/mmortari/mlartifact:v1 --plain-http +omlmd crawl localhost:5001/mmortari/mlartifact:v1 localhost:5001/mmortari/mlartifact:v1 --plain-http | jq . +omlmd crawl --plain-http \ localhost:5001/mmortari/mlartifact:v1 \ localhost:5001/mmortari/mlartifact:v1 \ localhost:5001/mmortari/mlartifact:v1 \ diff --git a/omlmd/cli.py b/omlmd/cli.py index 17a8cfb..b546c8b 100644 --- a/omlmd/cli.py +++ b/omlmd/cli.py @@ -1,46 +1,59 @@ # Using this to scope CLI targets import click from omlmd.helpers import Helper +from omlmd.provider import OMLMDRegistry from omlmd.model_metadata import deserialize_mdfile + +plain_http = click.option('--plain-http', help="allow insecure connections to registry without SSL check", is_flag=True, default=False, show_default=True) + + +def get_OMLMDRegistry(plain_http: bool) -> OMLMDRegistry: + return OMLMDRegistry(insecure=plain_http) + + @click.group() def cli(): pass @click.command() +@plain_http @click.argument('target', required=True) @click.option('-o', '--output', default='.', show_default=True) @click.option('--media-types', '-m', multiple=True, default=[]) -def pull(target, output, media_types): +def pull(plain_http, target, output, media_types): """Pulls an OCI Artifact containing ML model and metadata, filtering if necessary.""" - Helper().pull(target, output, media_types) + Helper(get_OMLMDRegistry(plain_http)).pull(target, output, media_types) @click.group() def get(): pass @click.command() +@plain_http @click.argument('target', required=True) -def config(target): +def config(plain_http, target): """Outputs configuration of the given OCI Artifact for ML model and metadata.""" - click.echo(Helper().get_config(target)) + click.echo(Helper(get_OMLMDRegistry(plain_http)).get_config(target)) @click.command() +@plain_http @click.argument('targets', required=True, nargs=-1) -def crawl(targets): +def crawl(plain_http, targets): """Crawls configuration for the given list of OCI Artifact for ML model and metadata.""" - click.echo(Helper().crawl(targets)) + click.echo(Helper(get_OMLMDRegistry(plain_http)).crawl(targets)) @click.command() +@plain_http @click.argument('target', required=True) @click.argument('path', required=True, type=click.Path()) @click.option('-m', '--metadata', required=True, type=click.Path()) -def push(target, path, metadata): +def push(plain_http, target, path, metadata): """Pushes an OCI Artifact containing ML model and metadata, supplying metadata from file as necessary""" import logging logging.basicConfig(level=logging.DEBUG) md = deserialize_mdfile(metadata) - click.echo(Helper().push(target, path, **md)) + click.echo(Helper(get_OMLMDRegistry(plain_http)).push(target, path, **md)) cli.add_command(pull) cli.add_command(get)