in src/buildstream/_remotespec.py [0:0]
def new_from_string(cls, string: str, purpose: int = RemoteSpecPurpose.ALL) -> "RemoteSpec":
url: Optional[str] = None
instance_name: Optional[str] = None
remote_type: str = RemoteType.ALL
push: bool = True
server_cert: Optional[str] = None
client_key: Optional[str] = None
client_cert: Optional[str] = None
access_token: Optional[str] = None
if purpose == RemoteSpecPurpose.PULL:
push = False
split = string.split(",")
if len(split) > 1:
for split_string in split:
subsplit = split_string.split("=")
if len(subsplit) != 2:
raise RemoteError(
"Invalid format '{}' found in remote specification: {}".format(split_string, string)
)
key: str = subsplit[0]
val: str = subsplit[1]
if key == "url":
url = val
elif key == "instance-name":
instance_name = val
elif key == "type":
remote_type = cast(str, RemoteType(val))
allowed_types = [RemoteType.INDEX, RemoteType.STORAGE, RemoteType.ALL]
if remote_type not in allowed_types:
raise RemoteError(
"Value for remote 'type' must be one of: {}".format(
", ".join([str(_type) for _type in allowed_types])
)
)
elif key == "push":
# Provide a sensible error for `bst artifact push --remote url=http://pony.com,push=False ...`
if purpose != RemoteSpecPurpose.ALL:
raise RemoteError("The 'push' key is invalid and assumed to be {}".format(push))
if val in ("True", "true"):
push = True
elif val in ("False", "false"):
push = False
else:
raise RemoteError("Value for 'push' must be 'True' or 'False'")
elif key == "server-cert":
server_cert = cls._resolve_path(val, os.getcwd())
elif key == "client-key":
client_key = cls._resolve_path(val, os.getcwd())
elif key == "client-cert":
client_cert = cls._resolve_path(val, os.getcwd())
elif key == "access-token":
access_token = cls._resolve_path(val, os.getcwd())
else:
raise RemoteError("Unexpected key '{}' encountered".format(key))
else:
# No commas, only the URL was specified
url = string
if not url:
raise RemoteError("No URL specified in remote")
return cls(
remote_type,
url,
push=push,
server_cert=server_cert,
client_key=client_key,
client_cert=client_cert,
access_token=access_token,
instance_name=instance_name,
)