script: Added support for different protocols

master
Felix Stupp 4 years ago
parent 190c36c456
commit 72ca988988
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -47,7 +47,7 @@ def parse(args):
return configure_parser().parse_args(args=args)
def main():
URL_REGEX = re.compile(r'^(?P<proto>(https?://)?)(?P<host>[^:/ ]+)(:(?P<port>\d+))?(?P<path>.*)$')
URL_REGEX = re.compile(r'^(?P<proto>[a-z]+://)?(?P<host>[^:/ ]+)(:(?P<port>\d+))?(?P<path>.*)$')
# Retrieve args from config and shell
storedArgs = sys.argv.copy()
storedArgs.pop(0)
@ -65,11 +65,11 @@ def main():
raise ValueError("Password is missing!") # TODO make more beautiful for user
# Parse url
urlM = URL_REGEX.match(args.url).groupdict()
proto = urlM.get('proto') or 'https'
host = urlM['host']
# Call api
# TODO Support scheme (http / https)
# TODO Support port
server = Connection(host)
server = Connection(proto=proto, host=host)
server.login(args.user, passwd)
args.func(server, args)

@ -98,13 +98,14 @@ class Connection:
}
def __init__(self, proto, host, endpoint="/api/"):
if proto not in SUPPORTED_PROTO:
protos = self.__class__.SUPPORTED_PROTO
if proto not in protos:
raise ValueError(f"Protocol '{proto}' not supported")
self._proto = proto
self._host = host
self._endpoint = endpoint
self._sid = None
self.__conn = SUPPORTED_PROTO[proto](host=host)
self.__conn = protos[proto](host=host)
atexit.register(lambda: self.__conn.close())
def __raiseError(self, op, info):

Loading…
Cancel
Save