8000 Modify the behavior of public and private by mapleeit · Pull Request #2672 · jina-ai/serve · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Modify the behavior of public and private #2672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 44 additions & 31 deletions jina/hubble/hubio.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
from .helper import archive_package


JINA_HUBBLE_REGISTRY = os.environ.get('JINA_HUBBLE_REGISTRY', 'https://hubble.jina.ai')
JINA_HUBBLE_PUSH_URL = urljoin(JINA_HUBBLE_REGISTRY, '/v1/executors/push')
JINA_HUBBLE_REGISTRY = os.environ.get(
'JINA_HUBBLE_REGISTRY', 'https://api.hubble.jina.ai'
)
JINA_HUBBLE_PUSH_URL = urljoin(JINA_HUBBLE_REGISTRY, '/v1/executors')


class HubIO:
Expand Down Expand Up @@ -61,44 +63,55 @@ def push(self) -> None:
form_data = {
'meta': json.dumps(meta),
'env': json.dumps(env),
'is_public': self.args.public,
'public': self.args.public,
'private': self.args.private,
'md5sum': md5_digest,
'force': self.args.force,
'secret': self.args.secret,
}

method = 'put' if self.args.force else 'post'
# upload the archived executor to Jina Hub
with TimeContext(f'uploading to {JINA_HUBBLE_PUSH_URL}', self.logger):
resp = requests.post(
with TimeContext(
f'uploading to {method.upper()} {JINA_HUBBLE_PUSH_URL}', self.logger
):
request = getattr(requests, method)
resp = request(
JINA_HUBBLE_PUSH_URL, files={'file': content}, data=form_data
)

if resp.status_code == 201:
if resp.json()['success']:
# TODO: only support single executor now
image = resp.json()['data']['images'][0]

uuid8 = image['id']
secret = image['secret']
docker_image = image['pullPath']

info_table = [
f'\t🔑 ID:\t' + colored(f'{uuid8}', 'cyan'),
f'\t🔒 Secret:\t'
+ colored(
f'{secret}',
'cyan',
),
f'\t🐳 Image:\t' + colored(f'{docker_image}', 'cyan'),
]
self.logger.success(
f'🎉 The executor at {pkg_path} is now published successfully!'
)
self.logger.info('\n' + '\n'.join(info_table))
self.logger.info(
'You can use this Executor in the Flow via '
+ colored(f'jinahub://{uuid8}', 'cyan', attrs='underline')
)
if 200 <= resp.status_code < 300:
# TODO: only support single executor now
image = resp.json()['executors'][0]

uuid8 = image['id']
secret = image['secret']
docker_image = image['pullPath']
visibility = image['visibility']
usage = (
f'jinahub://{uuid8}'
if visibility == 'public'
else f'jinahub://{uuid8}:{secret}'
)

info_table = [
f'\t🔑 ID:\t\t' + colored(f'{uuid8}', 'cyan'),
f'\t🔒 Secret:\t'
+ colored(
f'{secret}',
'cyan',
),
f'\t🐳 Image:\t' + colored(f'{docker_image}', 'cyan'),
f'\t👀 Visibility:\t' + colored(f'{visibility}', 'cyan'),
]
self.logger.success(
f'🎉 The executor at {pkg_path} is now published successfully!'
)
self.logger.info('\n' + '\n'.join(info_table))
self.logger.info(
'You can use this Executor in the Flow via '
+ colored(usage, 'cyan', attrs='underline')
)

else:
raise Exception(resp.text)
Expand Down
22 changes: 16 additions & 6 deletions jina/parsers/hubble/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ def mixin_hub_push_parser(parser):
- a directory containing Dockerfile, manifest.yml, README.md, zero or more yaml config, zero or more Python file.
''',
)
gp.add_argument(
'--public',
action='store_true',
default=False,
help='If set, the published executor is visible to public',
)
gp.add_argument(
'--force',
type=str,
Expand All @@ -31,3 +25,19 @@ def mixin_hub_push_parser(parser):
type=str,
help='The secret key of the identified Jina Hub executor',
)

mutually_exclusive_group = parser.add_mutually_exclusive_group()

mutually_exclusive_group.add_argument(
'--public',
action='store_true',
default=False,
help='If set, the published executor is visible to public',
)

mutually_exclusive_group.add_argument(
'--private',
action='store_true',
default=False,
help='If set, the published executor is invisible to public',
)
18 changes: 15 additions & 3 deletions tests/unit/parsers/hubble/test_pushpull.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import pytest
from jina.parsers.hubble.push import mixin_hub_push_parser


Expand All @@ -12,14 +13,25 @@ def test_push_parser():
args = parser.parse_args(['foo/'])
assert args.path == 'foo/'
assert args.public is False
assert args.private is False
assert args.force is None
assert args.secret is None

args = parser.parse_args(['foo/', '--public'])
assert args.public is True
assert args.private is False

args = parser.parse_args(['foo/', '--force', '8iag38yu'])
assert args.force == '8iag38yu'
args = parser.parse_args(['foo/', '--private'])
assert args.public is False
assert args.private is True

with pytest.raises(SystemExit) as pytest_wrapped_e:
args = parser.parse_args(['foo/', '--private', '--public'])
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 2

args = parser.parse_args(['foo/', '--secret', '8iag38yu'])
args = parser.parse_args(['foo/', '--force', '8iag38yu', '--secret', '8iag38yu'])
assert args.force == '8iag38yu'
assert args.secret == '8iag38yu'
assert args.public is False
assert args.private is False
0