splight-cli 5.1.4.dev0__py3-none-any.whl → 5.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,6 @@ from splight_cli.constants import (
8
8
  DEFAULT_WORKSPACE_NAME,
9
9
  DEFAULT_WORKSPACES,
10
10
  )
11
- from splight_cli.context.exceptions import MissingConfigurationFile
12
11
  from splight_cli.settings import SplightCLIConfig, SplightCLISettings
13
12
  from splight_cli.utils.yaml import get_yaml_from_file, save_yaml_to_file
14
13
 
@@ -32,21 +31,39 @@ class NotExistingWorkspace(Exception):
32
31
  return self._msg
33
32
 
34
33
 
34
+ class ConfigurationError(Exception):
35
+ pass
36
+
37
+
35
38
  class WorkspaceManager:
36
39
  def __init__(self, new_workspace: bool = False):
37
- if not os.path.exists(CONFIG_FILE) and not new_workspace:
38
- raise MissingConfigurationFile("Config file does not exist")
39
40
  self.config_file = CONFIG_FILE
40
- path = Path(self.config_file)
41
- path.parent.mkdir(parents=True, exist_ok=True)
42
- path.touch()
43
41
  self._config = self.__load_config()
44
42
  self._workspaces = self._config.workspaces
45
43
  self._current_workspace = self._config.current_workspace
46
44
  self._settings = self._workspaces[self._current_workspace]
45
+ if not self._settings.is_configured():
46
+ raise ConfigurationError(
47
+ (
48
+ "There is at least one variable missing. "
49
+ "Use command 'splight configure'"
50
+ )
51
+ )
47
52
 
48
53
  def __load_config(self):
49
- config = get_yaml_from_file(self.config_file)
54
+ try:
55
+ if os.path.exists(self.config_file):
56
+ config = self._load_from_file(self.config_file)
57
+ else:
58
+ config = self._load_from_env()
59
+ except Exception as exc:
60
+ raise ConfigurationError(
61
+ "An error ocurred while loading configuration"
62
+ ) from exc
63
+ return config
64
+
65
+ def _load_from_file(self, file_path: str) -> SplightCLIConfig:
66
+ config = get_yaml_from_file(file_path)
50
67
  # Default values
51
68
  config["workspaces"] = config.get("workspaces", DEFAULT_WORKSPACES)
52
69
  workspace_name = config.get(
@@ -59,10 +76,21 @@ class WorkspaceManager:
59
76
  else list(config["workspaces"].keys())[0]
60
77
  )
61
78
  config["current_workspace"] = workspace_name
62
- save_yaml_to_file(config, self.config_file)
79
+ save_yaml_to_file(config, file_path)
63
80
  config = SplightCLIConfig.model_validate(config)
64
81
  return config
65
82
 
83
+ def _load_from_env(self) -> SplightCLIConfig:
84
+ config = SplightCLIConfig(
85
+ current_workspace=DEFAULT_WORKSPACE_NAME,
86
+ workspaces=DEFAULT_WORKSPACES,
87
+ )
88
+ path = Path(self.config_file)
89
+ path.parent.mkdir(parents=True, exist_ok=True)
90
+ path.touch()
91
+ save_yaml_to_file(config.model_dump(), self.config_file)
92
+ return config
93
+
66
94
  @property
67
95
  def settings(self) -> SplightCLISettings:
68
96
  return self._settings
splight_cli/settings.py CHANGED
@@ -7,16 +7,22 @@ from splight_cli.version import __version__
7
7
 
8
8
 
9
9
  class SplightCLISettings(BaseSettings):
10
- SPLIGHT_ACCESS_ID: str = ""
11
- SPLIGHT_SECRET_KEY: str = ""
10
+ SPLIGHT_ACCESS_ID: str | None = None
11
+ SPLIGHT_SECRET_KEY: str | None = None
12
12
  SPLIGHT_PLATFORM_API_HOST: str = "https://api.splight-ai.com"
13
- SPLIGHT_GRPC_HOST: str = "grpc.splight-ai.com:443"
14
13
 
15
14
  model_config: ConfigDict = ConfigDict(extra="ignore")
16
15
 
16
+ def is_configured(self) -> bool:
17
+ return (
18
+ False
19
+ if not self.SPLIGHT_ACCESS_ID or not self.SPLIGHT_SECRET_KEY
20
+ else True
21
+ )
22
+
17
23
 
18
24
  class SplightCLIConfig(BaseModel):
19
- current_workspace: str
25
+ current_workspace: str = "default"
20
26
  workspaces: Dict[str, SplightCLISettings]
21
27
 
22
28
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: splight-cli
3
- Version: 5.1.4.dev0
3
+ Version: 5.1.5
4
4
  Summary: Splight Command Line Interface
5
5
  Author: Splight Dev
6
6
  Author-email: dev@splight-ae.com
@@ -17,9 +17,8 @@ splight_cli/component/utils.py,sha256=b0y1rYU-xdJMnaU11eX9yoZtr33jkVyyu24m725Nx1
17
17
  splight_cli/config/__init__.py,sha256=0E5tAC4AKR-Mkdg1KiPrFweZI9HemiCxKFTIUTFmGXs,2678
18
18
  splight_cli/constants.py,sha256=M-Ce3F5TVzM_Z1T06SytUckXtpiaLsLDkbk-jbOe0GA,1605
19
19
  splight_cli/context/__init__.py,sha256=BxEVhXTM7jKAOw05yu8o426mvqpX-hVVAS98-okoBhE,848
20
- splight_cli/context/context.py,sha256=CdW8xP76iBESaFpCP8q9fQ34KN47IV55Qj84MAYuOqM,383
21
20
  splight_cli/context/exceptions.py,sha256=eoFdjWcaQaT5s04yflesFYwCgMwaYIbnoZ-Ix13WI5k,110
22
- splight_cli/context/workspace.py,sha256=piQmVDJeWD-LRU6StKF1ZWHJBsmfYSpYJsWMisl4lAo,4165
21
+ splight_cli/context/workspace.py,sha256=gDpYm2Wecm_eR8wpfBXYaRbvsfKxXsCqAScGw_Pfbu8,4962
23
22
  splight_cli/engine/__init__.py,sha256=nYCVy9OmJUj8xLffLLLGrC7gvhyaS6jtDMAgZp9ibcs,1016
24
23
  splight_cli/engine/alert/__init__.py,sha256=zIVscSIG6mSAkjX5IBGOn8NmpYFahGk7eQgA_oAxJOU,2004
25
24
  splight_cli/engine/asset/__init__.py,sha256=-mgaA9FVFZGdhklX3FWQqG1m-g8-0Olr5-GZEMi5mdE,1950
@@ -50,7 +49,7 @@ splight_cli/hub/solution/__init__.py,sha256=058hv5MTw0jZ3b96UUm2o2kj5F2z0zNGzNlG
50
49
  splight_cli/hub/solution/constants.py,sha256=nmWdgB4BuFeGpWfXpc78gUTPVeO2ZSptK5IaUDzWka0,113
51
50
  splight_cli/hub/solution/exceptions.py,sha256=9opbWY1_I4ziccnlerfrZlCvtS__5FBpr_3Uog5nlaA,861
52
51
  splight_cli/hub/solution/solution_manager.py,sha256=izeXTTbqlZWlDtQ-dAJvlDc6tJO12TKVRRpk0ZaDWa4,3670
53
- splight_cli/settings.py,sha256=uCup6j2lt4LygJu4k8cfYXVPVT3-K0m20K1OiUNt_hI,720
52
+ splight_cli/settings.py,sha256=58_Eu-tUUR4T5b--dXXu9JJEICAZnxG9Ex_a7SE-Lu4,873
54
53
  splight_cli/solution/__init__.py,sha256=oyIsCBczZ6bpWhufej7ySVCEO3u0qSAXgEZvwy1os4I,2287
55
54
  splight_cli/solution/dict.py,sha256=fA_5f-N-raTtg0G1WjFvq9YgDGEjbIKPrLBtaX2mNo8,1342
56
55
  splight_cli/solution/parser.py,sha256=19jNYiwL3NhbncgxJa66QogBXaNYDn0Qq4W5YdpplSo,3845
@@ -85,7 +84,7 @@ splight_cli/utils/template.py,sha256=VHm2EM_xBLge0bZ3iOCkyAIAl7j2tOC3-O2yEV1Kljs
85
84
  splight_cli/utils/yaml.py,sha256=jhNdQa_ExlSaXsPnlfLKKMOKbF1fJLpx0o264AdCNrg,754
86
85
  splight_cli/version.py,sha256=Oa-bywO4Gja4qAmE1fgo99yJvRzJwQ0psMFMB7CmjMo,78
87
86
  splight_cli/workspace/__init__.py,sha256=-7_p7glSPFqSg5zzQR8uMlAD0r1R6q1mPjNXlRtnkls,2839
88
- splight_cli-5.1.4.dev0.dist-info/METADATA,sha256=gM6gsPMvKKper3KiVVDf71hEzlUAzSsecWRTwp4jC0Y,12438
89
- splight_cli-5.1.4.dev0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
90
- splight_cli-5.1.4.dev0.dist-info/entry_points.txt,sha256=lcQvpsOL_pP12pneurzqzFByIzr8SkgL70sjI0esTyM,47
91
- splight_cli-5.1.4.dev0.dist-info/RECORD,,
87
+ splight_cli-5.1.5.dist-info/METADATA,sha256=Ym1B6TXOmoA5W4Fd9KvSjG6Nn0J7Cadsv5M9kTdFyjQ,12433
88
+ splight_cli-5.1.5.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
89
+ splight_cli-5.1.5.dist-info/entry_points.txt,sha256=lcQvpsOL_pP12pneurzqzFByIzr8SkgL70sjI0esTyM,47
90
+ splight_cli-5.1.5.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- import typer
2
-
3
-
4
- def local_environment_context(ctx: typer.Context, local_dev: bool):
5
- if local_dev:
6
- db_client_mod = "splight_lib.client.database.LocalDatabaseClient"
7
- dl_client_mod = "splight_lib.client.datalake.LocalDatalakeClient"
8
- ctx.obj.workspace.settings.DATABASE_CLIENT = db_client_mod
9
- ctx.obj.workspace.settings.DATALAKE_CLIENT = dl_client_mod