Added better uri parsing, updated README

This commit is contained in:
Firq-ow 2024-07-09 14:34:07 +02:00
parent c00aa232fc
commit 5628e4f062
Signed by: Firq
GPG key ID: BC5CE35A72BDB4AB
2 changed files with 36 additions and 3 deletions
dockge_cli/client/commands

View file

@ -1,5 +1,6 @@
from urllib.parse import urlparse
from getpass import getpass
import re
from ...models import Credentials
from ...service import storage
@ -26,10 +27,12 @@ class FunctionBindings():
host command binding
"""
if len(extra_args) > 0:
res = urlparse(extra_args[0])
mat = re.search(r"((\w+\.)?\w+\.\w+(\/.+)?)", extra_args[0], re.IGNORECASE)
if mat is None:
raise ValueError("Given host did not match regex")
res = urlparse(f"https://{mat[0]}")
if all([res.scheme, res.netloc]):
host = extra_args[0].rstrip("/").replace("https://", "").replace("wss://", "")
storage.put("host", host)
storage.put("host", mat[0])
else:
raise ValueError(f"Malformed URL {extra_args[0]}")
print(storage.get("host"))