acryl-datahub 1.2.0.11rc1__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)