Skip to content

Commit

Permalink
cli: add --plain-http option (#6)
Browse files Browse the repository at this point in the history
* cli: add --plain-http option

Signed-off-by: tarilabs <[email protected]>

* align CLI test cases to registry on plain http

Signed-off-by: tarilabs <[email protected]>

---------

Signed-off-by: tarilabs <[email protected]>
  • Loading branch information
tarilabs authored Aug 10, 2024
1 parent f479d36 commit d5fb577
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
12 changes: 6 additions & 6 deletions e2e/test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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."
Expand All @@ -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 \
Expand Down
29 changes: 21 additions & 8 deletions omlmd/cli.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit d5fb577

Please sign in to comment.