diff options
Diffstat (limited to 'lib/spack/spack/mirror.py')
-rw-r--r-- | lib/spack/spack/mirror.py | 93 |
1 files changed, 84 insertions, 9 deletions
diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py index a4ec57ab5b..2d1a3e819e 100644 --- a/lib/spack/spack/mirror.py +++ b/lib/spack/spack/mirror.py @@ -41,6 +41,10 @@ from spack.util.spack_yaml import syaml_dict from spack.version import VersionList +def _is_string(url): + return isinstance(url, six.string_types) + + def _display_mirror_entry(size, name, url, type_=None): if type_: type_ = "".join((" (", type_, ")")) @@ -59,7 +63,8 @@ class Mirror(object): to them. These two URLs are usually the same. """ - def __init__(self, fetch_url, push_url=None, name=None): + def __init__(self, fetch_url, push_url=None, + name=None): self._fetch_url = fetch_url self._push_url = push_url self._name = name @@ -96,7 +101,7 @@ class Mirror(object): if isinstance(d, six.string_types): return Mirror(d, name=name) else: - return Mirror(d['fetch'], d['push'], name) + return Mirror(d['fetch'], d['push'], name=name) def display(self, max_len=0): if self._push_url is None: @@ -137,24 +142,83 @@ class Mirror(object): def name(self): return self._name or "<unnamed>" + def get_profile(self, url_type): + if isinstance(self._fetch_url, dict): + if url_type == "push": + return self._push_url['profile'] + return self._fetch_url['profile'] + else: + return None + + def set_profile(self, url_type, profile): + if url_type == "push": + self._push_url["profile"] = profile + else: + self._fetch_url["profile"] = profile + + def get_access_pair(self, url_type): + if isinstance(self._fetch_url, dict): + if url_type == "push": + return self._push_url['access_pair'] + return self._fetch_url['access_pair'] + else: + return None + + def set_access_pair(self, url_type, connection_tuple): + if url_type == "push": + self._push_url["access_pair"] = connection_tuple + else: + self._fetch_url["access_pair"] = connection_tuple + + def get_endpoint_url(self, url_type): + if isinstance(self._fetch_url, dict): + if url_type == "push": + return self._push_url['endpoint_url'] + return self._fetch_url['endpoint_url'] + else: + return None + + def set_endpoint_url(self, url_type, url): + if url_type == "push": + self._push_url["endpoint_url"] = url + else: + self._fetch_url["endpoint_url"] = url + + def get_access_token(self, url_type): + if isinstance(self._fetch_url, dict): + if url_type == "push": + return self._push_url['access_token'] + return self._fetch_url['access_token'] + else: + return None + + def set_access_token(self, url_type, connection_token): + if url_type == "push": + self._push_url["access_token"] = connection_token + else: + self._fetch_url["access_token"] = connection_token + @property def fetch_url(self): - return self._fetch_url + return self._fetch_url if _is_string(self._fetch_url) \ + else self._fetch_url["url"] @fetch_url.setter def fetch_url(self, url): - self._fetch_url = url + self._fetch_url["url"] = url self._normalize() @property def push_url(self): if self._push_url is None: - return self._fetch_url - return self._push_url + return self._fetch_url if _is_string(self._fetch_url) \ + else self._fetch_url["url"] + return self._push_url if _is_string(self._push_url) \ + else self._push_url["url"] @push_url.setter def push_url(self, url): - self._push_url = url + self._push_url["url"] = url self._normalize() def _normalize(self): @@ -453,7 +517,7 @@ def create(path, specs, skip_unstable_versions=False): return mirror_stats.stats() -def add(name, url, scope): +def add(name, url, scope, args={}): """Add a named mirror in the given scope""" mirrors = spack.config.get('mirrors', scope=scope) if not mirrors: @@ -463,7 +527,18 @@ def add(name, url, scope): tty.die("Mirror with name %s already exists." % name) items = [(n, u) for n, u in mirrors.items()] - items.insert(0, (name, url)) + mirror_data = url + key_values = ["s3_access_key_id", "s3_access_token", "s3_profile"] + # On creation, assume connection data is set for both + if any(value for value in key_values if value in args): + url_dict = {"url": url, + "access_pair": (args.s3_access_key_id, args.s3_access_key_secret), + "access_token": args.s3_access_token, + "profile": args.s3_profile, + "endpoint_url": args.s3_endpoint_url} + mirror_data = {"fetch": url_dict, "push": url_dict} + + items.insert(0, (name, mirror_data)) mirrors = syaml_dict(items) spack.config.set('mirrors', mirrors, scope=scope) |