acryl-datahub 1.2.0.10rc8__py3-none-any.whl → 1.2.0.11rc2__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.

Potentially problematic release.


This version of acryl-datahub might be problematic. Click here for more details.

@@ -0,0 +1,29 @@
1
+ import os
2
+ from typing import Dict, List, Union
3
+
4
+ from datahub.secret.secret_store import SecretStore
5
+
6
+
7
+ # Simple SecretStore implementation that fetches Secret values from the local environment.
8
+ class EnvironmentSecretStore(SecretStore):
9
+ def __init__(self, config):
10
+ pass
11
+
12
+ def close(self) -> None:
13
+ return
14
+
15
+ def get_secret_values(self, secret_names: List[str]) -> Dict[str, Union[str, None]]:
16
+ values = {}
17
+ for secret_name in secret_names:
18
+ values[secret_name] = os.getenv(secret_name)
19
+ return values
20
+
21
+ def get_secret_value(self, secret_name: str) -> Union[str, None]:
22
+ return os.getenv(secret_name)
23
+
24
+ def get_id(self) -> str:
25
+ return "env"
26
+
27
+ @classmethod
28
+ def create(cls, config: Dict) -> "EnvironmentSecretStore":
29
+ return cls(config)
@@ -0,0 +1,49 @@
1
+ import logging
2
+ import os
3
+ from typing import Any, Dict, List, Union
4
+
5
+ from pydantic import BaseModel
6
+
7
+ from datahub.secret.secret_store import SecretStore
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ class FileSecretStoreConfig(BaseModel):
13
+ basedir: str = "/mnt/secrets"
14
+ max_length: int = 1024768
15
+
16
+
17
+ # Simple SecretStore implementation that fetches Secret values from the local files.
18
+ class FileSecretStore(SecretStore):
19
+ def __init__(self, config: FileSecretStoreConfig):
20
+ self.config = config
21
+
22
+ def get_secret_values(self, secret_names: List[str]) -> Dict[str, Union[str, None]]:
23
+ values = {}
24
+ for secret_name in secret_names:
25
+ values[secret_name] = self.get_secret_value(secret_name)
26
+ return values
27
+
28
+ def get_secret_value(self, secret_name: str) -> Union[str, None]:
29
+ secret_path = os.path.join(self.config.basedir, secret_name)
30
+ if os.path.exists(secret_path):
31
+ with open(secret_path, "r") as f:
32
+ secret_value = f.read(self.config.max_length + 1)
33
+ if len(secret_value) > self.config.max_length:
34
+ logger.warning(
35
+ f"Secret {secret_name} is longer than {self.config.max_length} and will be truncated."
36
+ )
37
+ return secret_value[: self.config.max_length].rstrip()
38
+ return None
39
+
40
+ def get_id(self) -> str:
41
+ return "file"
42
+
43
+ def close(self) -> None:
44
+ return
45
+
46
+ @classmethod
47
+ def create(cls, config: Any) -> "FileSecretStore":
48
+ config = FileSecretStoreConfig.parse_obj(config)
49
+ return cls(config)
@@ -33,13 +33,12 @@ from datahub.utilities.sentinels import Unset, unset
33
33
 
34
34
  logger: logging.Logger = logging.getLogger(__name__)
35
35
 
36
- OVERRIDE_SQLITE_VERSION_REQUIREMENT_STR = (
37
- os.environ.get("OVERRIDE_SQLITE_VERSION_REQ") or ""
38
- )
39
- OVERRIDE_SQLITE_VERSION_REQUIREMENT = (
40
- OVERRIDE_SQLITE_VERSION_REQUIREMENT_STR
41
- and OVERRIDE_SQLITE_VERSION_REQUIREMENT_STR.lower() != "false"
42
- )
36
+
37
+ def _get_sqlite_version_override() -> bool:
38
+ """Check if SQLite version requirement should be overridden at runtime."""
39
+ override_str = os.environ.get("OVERRIDE_SQLITE_VERSION_REQ") or ""
40
+ return bool(override_str and override_str.lower() != "false")
41
+
43
42
 
44
43
  _DEFAULT_FILE_NAME = "sqlite.db"
45
44
  _DEFAULT_TABLE_NAME = "data"
@@ -231,7 +230,7 @@ class FileBackedDict(MutableMapping[str, _VT], Closeable, Generic[_VT]):
231
230
  # We use the ON CONFLICT clause to implement UPSERTs with sqlite.
232
231
  # This was added in 3.24.0 from 2018-06-04.
233
232
  # See https://www.sqlite.org/lang_conflict.html
234
- if OVERRIDE_SQLITE_VERSION_REQUIREMENT:
233
+ if _get_sqlite_version_override():
235
234
  self._use_sqlite_on_conflict = False
236
235
  else:
237
236
  raise RuntimeError("SQLite version 3.24.0 or later is required")