Skip to content

Commit e9fdec2

Browse files
committed
credentials: store the location of a custom tools folder
Add the option to store the location of a custom tools folder to the infuse-iot credentials. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 98f51d1 commit e9fdec2

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/infuse_iot/credentials.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import yaml
55

66

7-
def set_api_key(api_key: str):
7+
def set_api_key(api_key: str) -> None:
88
"""
99
Save the Infuse-IoT API key to the keyring module
1010
"""
1111
keyring.set_password("infuse-iot", "api-key", api_key)
1212

1313

14-
def get_api_key():
14+
def get_api_key() -> str:
1515
"""
1616
Retrieve the Infuse-IoT API key from the keyring module
1717
"""
@@ -20,8 +20,14 @@ def get_api_key():
2020
raise FileNotFoundError("API key does not exist in keyring")
2121
return key
2222

23+
def delete_api_key() -> None:
24+
"""
25+
Delete the Infuse-IoT API key from the keyring module
26+
"""
27+
keyring.delete_password("infuse-iot", "api-key")
2328

24-
def save_network(network_id: int, network_info: str):
29+
30+
def save_network(network_id: int, network_info: str) -> None:
2531
"""
2632
Save an Infuse-IoT network key to the keyring module
2733
"""
@@ -38,3 +44,24 @@ def load_network(network_id: int):
3844
if key is None:
3945
raise FileNotFoundError(f"Network key {network_id:06x} does not exist in keyring")
4046
return yaml.safe_load(key)
47+
48+
49+
def set_custom_tool_path(path: str):
50+
"""
51+
Save the location of custom Infuse-IoT tools on the filesystem
52+
"""
53+
keyring.set_password("infuse-iot", "custom-tools", path)
54+
55+
56+
def get_custom_tool_path() -> str | None:
57+
"""
58+
Retrieve the location of custom Infuse-IoT tools on the filesystem
59+
"""
60+
return keyring.get_password("infuse-iot", "custom-tools")
61+
62+
63+
def delete_custom_tool_path() -> None:
64+
"""
65+
Delete the location of custom Infuse-IoT tools on the filesystem
66+
"""
67+
return keyring.delete_password("infuse-iot", "custom-tools")

src/infuse_iot/tools/credentials.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from infuse_iot import credentials
1111
from infuse_iot.commands import InfuseCommand
12-
from infuse_iot.util.argparse import ValidFile
12+
from infuse_iot.util.argparse import ValidDir, ValidFile
1313

1414

1515
class SubCommand(InfuseCommand):
@@ -22,6 +22,7 @@ def add_parser(cls, parser):
2222
parser.add_argument("--api-key", type=str, help="Set Infuse-IoT API key")
2323
parser.add_argument("--api-key-print", action="store_true", help="Print Infuse-IoT API key")
2424
parser.add_argument("--network", type=ValidFile, help="Load network credentials from file")
25+
parser.add_argument("--custom-tools", type=ValidDir, help="Location of custom tools")
2526

2627
def __init__(self, args):
2728
self.args = args
@@ -30,11 +31,16 @@ def run(self):
3031
if self.args.api_key is not None:
3132
credentials.set_api_key(self.args.api_key)
3233
if self.args.api_key_print:
33-
print(f"API Key: {credentials.get_api_key()}")
34+
try:
35+
print(f"API Key: {credentials.get_api_key()}")
36+
except FileNotFoundError:
37+
print("API Key: N/A")
3438
if self.args.network is not None:
3539
# Read the file
3640
with self.args.network.open("r") as f:
3741
content = f.read()
3842
# Validate it is valid yaml
3943
network_info = yaml.safe_load(content)
4044
credentials.save_network(network_info["id"], content)
45+
if self.args.custom_tools:
46+
credentials.set_custom_tool_path(str(self.args.custom_tools.absolute()))

0 commit comments

Comments
 (0)