Skip to content

Commit

Permalink
Add quilt config for Teams registries (#793)
Browse files Browse the repository at this point in the history
## Adding a quilt config for Teams registries
This feature allows using `quilt config` to set a custom url for a Teams Registry--that allows using the team namespace to address packages.
  • Loading branch information
kevinemoore authored Jan 9, 2019
1 parent a5aed4c commit 2289b3d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
3 changes: 2 additions & 1 deletion compiler/quilt/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
[0, 'check', '--env'],
[0, 'check', 0],
[0, 'config'],
[0, 'config', 0],
[0, 'delete'],
[0, 'delete', 0],
[0, 'export'],
Expand Down Expand Up @@ -616,7 +617,7 @@ def test_cli_command_config(self):
cmd = ['config']
result = self.execute_with_checks(cmd, funcname='config')

assert not result['kwargs']
assert result['kwargs']['team'] is None

def test_cli_command_login(self):
"""Ensures the 'login' command calls a specific API"""
Expand Down
42 changes: 31 additions & 11 deletions compiler/quilt/tools/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
generate_contents, get_or_create_package, BuildException, load_yaml)
from .compat import pathlib
from .const import DEFAULT_BUILDFILE, DTIMEF, QuiltException, SYSTEM_METADATA, TargetType
from .core import (LATEST_TAG, GroupNode, RootNode, decode_node, encode_node,
from .core import (LATEST_TAG, GroupNode, decode_node, encode_node,
find_object_hashes, hash_contents)
from .data_transfer import download_fragments, upload_fragments
from .store import PackageStore, StoreException
Expand Down Expand Up @@ -131,7 +131,12 @@ def _save_auth(cfg):

def get_registry_url(team):
if team is not None:
return "https://%s-registry.team.quiltdata.com" % team
# Check config
cfg = _load_config()
if team and cfg.get('team_id') == team and cfg.get('team_registry_url'):
return cfg['team_registry_url']
else:
return "https://%s-registry.team.quiltdata.com" % team

global _registry_url
if _registry_url is not None:
Expand All @@ -148,21 +153,35 @@ def get_registry_url(team):
_registry_url = url or DEFAULT_REGISTRY_URL
return _registry_url

def config():
answer = input("Please enter the URL for your custom Quilt registry (ask your administrator),\n"
"or leave this line blank to use the default registry: ")
def config(team=None):
if team is None:
message = "Please enter the URL for your custom Quilt registry " \
"(ask your administrator),\n" \
"or leave this line blank to use the default registry: "
else:
_check_team_id(team)
message = "Please enter the URL for the Quilt Team registry [%s] " \
"(ask your administrator),\n" \
"or leave this line blank to use the default: " % team
answer = input(message)

# When saving the config, store '' instead of the actual URL in case we ever change it.
cfg = _load_config()
if answer:
url = urlparse(answer.rstrip('/'))
if (url.scheme not in ['http', 'https'] or not url.netloc or
url.path or url.params or url.query or url.fragment):
raise CommandException("Invalid URL: %s" % answer)
canonical_url = urlunparse(url)
else:
# When saving the config, store '' instead of the actual URL in case we ever change it.
canonical_url = ''

cfg = _load_config()
cfg['registry_url'] = canonical_url

if team:
cfg['team_registry_url'] = canonical_url
cfg['team_id'] = team
else:
cfg['registry_url'] = canonical_url
cfg['team_id'] = ''
_save_config(cfg)

# Clear the cached URL.
Expand Down Expand Up @@ -360,7 +379,7 @@ def _check_team_exists(team):
if team is None:
return

hostname = '%s-registry.team.quiltdata.com' % team
hostname = urlparse(get_registry_url(team)).hostname
try:
socket.gethostbyname(hostname)
except IOError:
Expand Down Expand Up @@ -542,7 +561,8 @@ def _build_internal(package, path, dry_run, env, build_file):
assert not dry_run # TODO?
build_from_node(package, nodes.GroupNode({}))
else:
raise ValueError("Expected a GroupNode, path, git URL, DataFrame, ndarray, or None, but got %r" % path)
raise ValueError("Expected a GroupNode, path, git URL, DataFrame, ndarray, or None, " \
"but got %r" % path)


def build_from_node(package, node):
Expand Down
1 change: 1 addition & 0 deletions compiler/quilt/tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def check_hash(group, hashstr):
# quilt config
shorthelp = "Configure Quilt"
config_p = subparsers.add_parser("config", description=shorthelp, help=shorthelp)
config_p.add_argument("team", type=str, nargs='?', help="Specify team to configure")
config_p.set_defaults(func=command.config)

# quilt delete
Expand Down
4 changes: 2 additions & 2 deletions compiler/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def readme():
'tests': [
'funcsigs; python_version<"3.4"', # stdlib backport
'mock; python_version<"3.3"',
'pytest',
'pytest-cov',
'pytest==3.3.2',
'pytest-cov==2.4.0',
'responses>=0.7.0',
],
'torchvision': [
Expand Down

0 comments on commit 2289b3d

Please sign in to comment.