moose-lib 0.6.176__py3-none-any.whl → 0.6.188__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.
- moose_lib/secrets.py +26 -6
- {moose_lib-0.6.176.dist-info → moose_lib-0.6.188.dist-info}/METADATA +1 -1
- {moose_lib-0.6.176.dist-info → moose_lib-0.6.188.dist-info}/RECORD +6 -6
- tests/test_secrets.py +10 -0
- {moose_lib-0.6.176.dist-info → moose_lib-0.6.188.dist-info}/WHEEL +0 -0
- {moose_lib-0.6.176.dist-info → moose_lib-0.6.188.dist-info}/top_level.txt +0 -0
moose_lib/secrets.py
CHANGED
|
@@ -20,11 +20,13 @@ MOOSE_RUNTIME_ENV_PREFIX = "__MOOSE_RUNTIME_ENV__:"
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def get(env_var_name: str) -> str:
|
|
23
|
-
"""
|
|
23
|
+
"""Gets a value from an environment variable, with behavior depending on context.
|
|
24
24
|
|
|
25
|
-
When
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
When IS_LOADING_INFRA_MAP=true (infrastructure loading):
|
|
26
|
+
Returns a marker string that Moose CLI will resolve later
|
|
27
|
+
|
|
28
|
+
When IS_LOADING_INFRA_MAP is unset (function/workflow runtime):
|
|
29
|
+
Returns the actual value from the environment variable
|
|
28
30
|
|
|
29
31
|
This is useful for:
|
|
30
32
|
- Credentials that should never be embedded in Docker images
|
|
@@ -36,10 +38,11 @@ def get(env_var_name: str) -> str:
|
|
|
36
38
|
env_var_name: Name of the environment variable to resolve
|
|
37
39
|
|
|
38
40
|
Returns:
|
|
39
|
-
|
|
41
|
+
Either a marker string or the actual environment variable value
|
|
40
42
|
|
|
41
43
|
Raises:
|
|
42
44
|
ValueError: If the environment variable name is empty
|
|
45
|
+
KeyError: If the environment variable is not set (runtime mode only)
|
|
43
46
|
|
|
44
47
|
Example:
|
|
45
48
|
>>> # Instead of this (evaluated at build time):
|
|
@@ -49,9 +52,26 @@ def get(env_var_name: str) -> str:
|
|
|
49
52
|
>>> # Use this (evaluated at runtime):
|
|
50
53
|
>>> aws_key = moose_runtime_env.get("AWS_ACCESS_KEY_ID")
|
|
51
54
|
"""
|
|
55
|
+
import os
|
|
56
|
+
|
|
52
57
|
if not env_var_name or not env_var_name.strip():
|
|
53
58
|
raise ValueError("Environment variable name cannot be empty")
|
|
54
|
-
|
|
59
|
+
|
|
60
|
+
# Check if we're loading infrastructure map
|
|
61
|
+
is_loading_infra_map = os.environ.get("IS_LOADING_INFRA_MAP") == "true"
|
|
62
|
+
|
|
63
|
+
if is_loading_infra_map:
|
|
64
|
+
# Return marker string for later resolution by Moose CLI
|
|
65
|
+
return f"{MOOSE_RUNTIME_ENV_PREFIX}{env_var_name}"
|
|
66
|
+
else:
|
|
67
|
+
# Return actual value from environment for runtime execution
|
|
68
|
+
value = os.environ.get(env_var_name)
|
|
69
|
+
if value is None:
|
|
70
|
+
raise KeyError(
|
|
71
|
+
f"Environment variable '{env_var_name}' is not set. "
|
|
72
|
+
f"This is required for runtime execution of functions/workflows."
|
|
73
|
+
)
|
|
74
|
+
return value
|
|
55
75
|
|
|
56
76
|
|
|
57
77
|
class MooseRuntimeEnv:
|
|
@@ -7,7 +7,7 @@ moose_lib/internal.py,sha256=7T6PQyU2QLquSSPujO37e9t0tC_QYXpIK2CQom69li4,30453
|
|
|
7
7
|
moose_lib/main.py,sha256=JWsgza52xEh25AyF61cO1ItJ8VXJHHz8j-4HG445Whg,20380
|
|
8
8
|
moose_lib/query_builder.py,sha256=-L5p2dArBx3SBA-WZPkcCJPemKXnqJw60NHy-wn5wa4,6619
|
|
9
9
|
moose_lib/query_param.py,sha256=kxcR09BMIsEg4o2qetjKrVu1YFRaLfMEzwzyGsKUpvA,6474
|
|
10
|
-
moose_lib/secrets.py,sha256=
|
|
10
|
+
moose_lib/secrets.py,sha256=Ykt_iJZrozMRXAirC_NclDerSJVE5WmGTSyyHrfsTFE,4249
|
|
11
11
|
moose_lib/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
moose_lib/clients/redis_client.py,sha256=BDYjJ582V-rW92qVQ4neZ9Pu7JtDNt8x8jBWApt1XUg,11895
|
|
13
13
|
moose_lib/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -42,10 +42,10 @@ tests/test_olap_table_versioning.py,sha256=ffuJsO5TYKBd2aWV0GWDmosCwL4j518Y_MqYJ
|
|
|
42
42
|
tests/test_query_builder.py,sha256=O3imdFSaqU13kbK1jSQaHbBgynhVmJaApT8DlRqYwJU,1116
|
|
43
43
|
tests/test_redis_client.py,sha256=d9_MLYsJ4ecVil_jPB2gW3Q5aWnavxmmjZg2uYI3LVo,3256
|
|
44
44
|
tests/test_s3queue_config.py,sha256=A-17Lir2kvYoUA0qEaNczOkLKhHPzyp3glka7YqnPws,14490
|
|
45
|
-
tests/test_secrets.py,sha256=
|
|
45
|
+
tests/test_secrets.py,sha256=WFvmVsxwYsl5bD0SiOUR9ZELMBZ3CgY0NR4h7s9Oaww,8707
|
|
46
46
|
tests/test_simple_aggregate.py,sha256=yyFSYHUXskA1aTcwC-KQ9XmgOikeQ8wKXzntsUBIC6w,4055
|
|
47
47
|
tests/test_web_app.py,sha256=iL86sg0NS2k6nP8jIGKZvrtg0BjvaqNTRp7-4T1TTck,6557
|
|
48
|
-
moose_lib-0.6.
|
|
49
|
-
moose_lib-0.6.
|
|
50
|
-
moose_lib-0.6.
|
|
51
|
-
moose_lib-0.6.
|
|
48
|
+
moose_lib-0.6.188.dist-info/METADATA,sha256=pA-Ch_--rOTI4JeT55sonZEv1wMLE2sOQVVAMXGGym0,827
|
|
49
|
+
moose_lib-0.6.188.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
50
|
+
moose_lib-0.6.188.dist-info/top_level.txt,sha256=XEns2-4aCmGp2XjJAeEH9TAUcGONLnSLy6ycT9FSJh8,16
|
|
51
|
+
moose_lib-0.6.188.dist-info/RECORD,,
|
tests/test_secrets.py
CHANGED
|
@@ -5,10 +5,20 @@ which allows users to defer secret resolution until runtime rather than
|
|
|
5
5
|
embedding secrets at build time.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
import os
|
|
8
9
|
import pytest
|
|
9
10
|
from moose_lib.secrets import moose_runtime_env, get, MOOSE_RUNTIME_ENV_PREFIX
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
@pytest.fixture(scope="module", autouse=True)
|
|
14
|
+
def set_infra_map_loading_for_secrets_tests():
|
|
15
|
+
"""Set IS_LOADING_INFRA_MAP=true for secrets tests so moose_runtime_env.get() returns markers."""
|
|
16
|
+
os.environ["IS_LOADING_INFRA_MAP"] = "true"
|
|
17
|
+
yield
|
|
18
|
+
# Clean up after all tests in this module
|
|
19
|
+
os.environ.pop("IS_LOADING_INFRA_MAP", None)
|
|
20
|
+
|
|
21
|
+
|
|
12
22
|
class TestMooseRuntimeEnvGet:
|
|
13
23
|
"""Tests for the moose_runtime_env.get() method."""
|
|
14
24
|
|
|
File without changes
|
|
File without changes
|