Moved files, refactored calls, added credentials warning
This commit is contained in:
parent
58aea47921
commit
c00aa232fc
5 changed files with 23 additions and 24 deletions
1
dockge_cli/.gitignore
vendored
1
dockge_cli/.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
.temp/*
|
|
|
@ -39,6 +39,7 @@ class FunctionBindings():
|
||||||
"""
|
"""
|
||||||
login command binding
|
login command binding
|
||||||
"""
|
"""
|
||||||
|
print(f"WARNING! These credentials will be saved unencrypted in {storage._file.absolute()}")
|
||||||
if len(extra_args) > 0:
|
if len(extra_args) > 0:
|
||||||
credentials = credential_parser_factory().parse_args(extra_args, namespace=Credentials)
|
credentials = credential_parser_factory().parse_args(extra_args, namespace=Credentials)
|
||||||
storage.put("username", credentials.username, encoded=True)
|
storage.put("username", credentials.username, encoded=True)
|
||||||
|
@ -76,8 +77,6 @@ class FunctionBindings():
|
||||||
"""
|
"""
|
||||||
status command binding
|
status command binding
|
||||||
"""
|
"""
|
||||||
if extra_args is None:
|
|
||||||
raise ValueError
|
|
||||||
con = FunctionBindings.__setup()
|
con = FunctionBindings.__setup()
|
||||||
status_formatter(con.list_stack(extra_args[0]))
|
status_formatter(con.list_stack(extra_args[0]))
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
|
@ -87,8 +86,6 @@ class FunctionBindings():
|
||||||
"""
|
"""
|
||||||
restart command binding
|
restart command binding
|
||||||
"""
|
"""
|
||||||
if extra_args is None:
|
|
||||||
raise ValueError
|
|
||||||
con = FunctionBindings.__setup()
|
con = FunctionBindings.__setup()
|
||||||
generic_formatter(con.restart(extra_args[0]))
|
generic_formatter(con.restart(extra_args[0]))
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
|
@ -98,8 +95,6 @@ class FunctionBindings():
|
||||||
"""
|
"""
|
||||||
update command binding
|
update command binding
|
||||||
"""
|
"""
|
||||||
if extra_args is None:
|
|
||||||
raise ValueError
|
|
||||||
con = FunctionBindings.__setup()
|
con = FunctionBindings.__setup()
|
||||||
generic_formatter(con.update(extra_args[0]))
|
generic_formatter(con.update(extra_args[0]))
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
|
@ -109,8 +104,6 @@ class FunctionBindings():
|
||||||
"""
|
"""
|
||||||
stop command binding
|
stop command binding
|
||||||
"""
|
"""
|
||||||
if extra_args is None:
|
|
||||||
raise ValueError
|
|
||||||
con = FunctionBindings.__setup()
|
con = FunctionBindings.__setup()
|
||||||
generic_formatter(con.stop(extra_args[0]))
|
generic_formatter(con.stop(extra_args[0]))
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
|
@ -120,8 +113,6 @@ class FunctionBindings():
|
||||||
"""
|
"""
|
||||||
start command binding
|
start command binding
|
||||||
"""
|
"""
|
||||||
if extra_args is None:
|
|
||||||
raise ValueError
|
|
||||||
con = FunctionBindings.__setup()
|
con = FunctionBindings.__setup()
|
||||||
generic_formatter(con.start(extra_args[0]))
|
generic_formatter(con.start(extra_args[0]))
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
|
@ -131,8 +122,6 @@ class FunctionBindings():
|
||||||
"""
|
"""
|
||||||
down command binding
|
down command binding
|
||||||
"""
|
"""
|
||||||
if extra_args is None:
|
|
||||||
raise ValueError
|
|
||||||
con = FunctionBindings.__setup()
|
con = FunctionBindings.__setup()
|
||||||
generic_formatter(con.down(extra_args[0]))
|
generic_formatter(con.down(extra_args[0]))
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
|
|
1
dockge_cli/service/.gitignore
vendored
Normal file
1
dockge_cli/service/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.storage/*
|
|
@ -3,18 +3,18 @@ import pathlib
|
||||||
import base64
|
import base64
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
_storagepath = pathlib.Path(__file__).parents[1] / ".temp"
|
_storagepath = pathlib.Path(__file__).parent / ".storage"
|
||||||
|
_storagepath.mkdir(exist_ok=True, parents=True)
|
||||||
_file = _storagepath / "storage.yaml"
|
_file = _storagepath / "storage.yaml"
|
||||||
|
|
||||||
_storagepath.mkdir(exist_ok=True, parents=True)
|
def create_file_when_missing():
|
||||||
|
|
||||||
def fileexists():
|
|
||||||
"""
|
"""
|
||||||
Checks if storage file does exist, creates it when necessary
|
Checks if storage file does exist, creates it when necessary
|
||||||
"""
|
"""
|
||||||
if not _file.exists():
|
if _file.exists():
|
||||||
with open(_file, 'a', encoding="utf-8"):
|
return
|
||||||
os.utime(_file, None)
|
with open(_file, 'a', encoding="utf-8"):
|
||||||
|
os.utime(_file, None)
|
||||||
|
|
||||||
def exists(key: str) -> bool:
|
def exists(key: str) -> bool:
|
||||||
"""
|
"""
|
||||||
|
@ -34,10 +34,13 @@ def put(key: str, value: str, encoded=False):
|
||||||
Puts a given value with a given key into the storage file
|
Puts a given value with a given key into the storage file
|
||||||
Encodes the data as base64 when encoded is set to true
|
Encodes the data as base64 when encoded is set to true
|
||||||
"""
|
"""
|
||||||
fileexists()
|
if not _file.exists():
|
||||||
with open(_file, "r+", encoding="utf-8") as file:
|
create_file_when_missing()
|
||||||
|
|
||||||
|
with open(_file, "r", encoding="utf-8") as file:
|
||||||
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader) or {}
|
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader) or {}
|
||||||
content.update({ key: str(base64.b64encode(value.encode()), "utf-8") if encoded else value })
|
content.update({ key: str(base64.b64encode(value.encode()), "utf-8") if encoded else value })
|
||||||
|
|
||||||
with open(_file, "w+", encoding="utf-8") as file:
|
with open(_file, "w+", encoding="utf-8") as file:
|
||||||
yaml.dump(content, file, Dumper=yaml.SafeDumper)
|
yaml.dump(content, file, Dumper=yaml.SafeDumper)
|
||||||
|
|
||||||
|
@ -45,10 +48,13 @@ def remove(key: str):
|
||||||
"""
|
"""
|
||||||
Removed a given key from the storage file
|
Removed a given key from the storage file
|
||||||
"""
|
"""
|
||||||
fileexists()
|
if not _file.exists():
|
||||||
|
create_file_when_missing()
|
||||||
|
|
||||||
with open(_file, "r", encoding="utf-8") as file:
|
with open(_file, "r", encoding="utf-8") as file:
|
||||||
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader) or {}
|
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader) or {}
|
||||||
content.pop(key, None)
|
content.pop(key, None)
|
||||||
|
|
||||||
with open(_file, "w+", encoding="utf-8") as file:
|
with open(_file, "w+", encoding="utf-8") as file:
|
||||||
yaml.dump(content, file, Dumper=yaml.SafeDumper)
|
yaml.dump(content, file, Dumper=yaml.SafeDumper)
|
||||||
|
|
||||||
|
@ -60,9 +66,11 @@ def get(key: str, encoded=False):
|
||||||
value: str | None = None
|
value: str | None = None
|
||||||
if not _file.exists():
|
if not _file.exists():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
with open(_file, "r", encoding="utf-8") as file:
|
with open(_file, "r", encoding="utf-8") as file:
|
||||||
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader)
|
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader)
|
||||||
value = content.get(key, None)
|
value = content.get(key, None)
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
return base64.b64decode(value.encode()).decode() if encoded else value
|
return base64.b64decode(value.encode()).decode() if encoded else value
|
||||||
|
@ -71,4 +79,6 @@ def clear():
|
||||||
"""
|
"""
|
||||||
Deletes the storage file
|
Deletes the storage file
|
||||||
"""
|
"""
|
||||||
|
if not _file.exists():
|
||||||
|
return
|
||||||
_file.unlink()
|
_file.unlink()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "dockge_cli"
|
name = "dockge_cli"
|
||||||
version = "0.1.0-c.2"
|
version = "0.1.0-c.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pyyaml~=6.0.1",
|
"pyyaml~=6.0.1",
|
||||||
"pydantic~=2.8.0",
|
"pydantic~=2.8.0",
|
||||||
|
|
Loading…
Reference in a new issue