velocity-python 0.9.4__py3-none-any.whl → 0.9.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.
velocity/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = version = "0.9.4"
1
+ __version__ = version = "0.9.5"
2
2
 
3
3
  import importlib as _importlib
4
4
 
@@ -98,15 +98,32 @@ def get_amplify_app_id_and_branch(
98
98
  def initialize_build_environment(
99
99
  project_root: Union[str, Path] = ".",
100
100
  include_run_on_build_env: bool = False,
101
+ *,
102
+ ssm: bool = False,
103
+ ssm_path: str = "/Global/{branch}",
104
+ profile: Optional[str] = None,
101
105
  ) -> Optional[Tuple[str, str]]:
106
+ """Set the build's identity (``AppStage``, ``AWS_BRANCH``, ``AWS_APP_ID``)
107
+ from the Amplify branch, and with ``ssm=True`` also export that branch's
108
+ configuration from SSM (``ssm_path``, see :func:`ssm_config.export_path`).
109
+
110
+ Returns ``(app_id, branch)``, or ``None`` when the branch cannot be
111
+ determined (no ``AWS_BRANCH`` and no Amplify CLI), leaving the
112
+ environment untouched. Configuration never comes from a local file.
113
+ """
102
114
  try:
103
- import env
104
- except ImportError:
115
+ app_id, branch = get_amplify_app_id_and_branch(project_root)
116
+ except RuntimeError as exc:
117
+ print(f"[WARN] Build environment not set: {exc}")
105
118
  return None
106
-
107
- app_id, branch = get_amplify_app_id_and_branch(project_root)
108
119
  print(f"[INFO] Setting environment to: {branch}")
109
- env.set(branch)
120
+ if ssm:
121
+ from velocity.aws import ssm_config
122
+
123
+ names = ssm_config.export_path(
124
+ ssm_path.format(branch=branch), profile=profile, overwrite=True
125
+ )
126
+ print(f"[INFO] Exported {len(names)} settings from SSM")
110
127
  os.environ["AppStage"] = branch
111
128
  os.environ["AWS_BRANCH"] = branch
112
129
  os.environ["AWS_APP_ID"] = app_id
@@ -25,7 +25,7 @@ from __future__ import annotations
25
25
 
26
26
  import logging
27
27
  import os
28
- from typing import Optional
28
+ from typing import MutableMapping, Optional
29
29
 
30
30
  logger = logging.getLogger(__name__)
31
31
 
@@ -253,6 +253,59 @@ def require(key: str) -> str:
253
253
  return value
254
254
 
255
255
 
256
+ def export_path(
257
+ prefix: str,
258
+ environ: Optional[MutableMapping[str, str]] = None,
259
+ *,
260
+ profile: Optional[str] = None,
261
+ region: Optional[str] = None,
262
+ overwrite: bool = False,
263
+ client=None,
264
+ ) -> list[str]:
265
+ """Copy every SSM parameter directly under ``prefix`` into ``environ``.
266
+
267
+ For scripts and builds run outside Lambda that need a whole environment's
268
+ configuration as variables (``export_path("/Global/demo")``), read from
269
+ SSM instead of a local file. Parameters are decrypted, one level deep
270
+ (``/Global/demo/DBHost`` becomes ``DBHost``), and all pages are read.
271
+
272
+ A variable already in ``environ`` is kept unless ``overwrite`` is true.
273
+ Returns the names that were set, sorted, never the values. Raises
274
+ ``LookupError`` when the path holds no parameters, so a mistyped
275
+ environment fails instead of running with nothing set.
276
+
277
+ ``environ`` defaults to ``os.environ``; ``client`` is an SSM client (else
278
+ one is made from ``profile`` and ``region``, default :func:`get_region`).
279
+ """
280
+ target = os.environ if environ is None else environ
281
+ path = "/" + prefix.strip("/")
282
+ if client is None:
283
+ import boto3
284
+
285
+ session = boto3.Session(profile_name=profile) if profile else boto3
286
+ client = session.client("ssm", region_name=region or get_region("us-east-1"))
287
+
288
+ values: dict[str, str] = {}
289
+ kwargs = {"Path": path, "Recursive": False, "WithDecryption": True}
290
+ while True:
291
+ page = client.get_parameters_by_path(**kwargs)
292
+ for parameter in page.get("Parameters", []):
293
+ values[parameter["Name"].rsplit("/", 1)[-1]] = parameter["Value"]
294
+ token = page.get("NextToken")
295
+ if not token:
296
+ break
297
+ kwargs["NextToken"] = token
298
+ if not values:
299
+ raise LookupError(f"SSM path {path} holds no parameters")
300
+
301
+ exported = []
302
+ for key, value in values.items():
303
+ if overwrite or key not in target:
304
+ target[key] = value
305
+ exported.append(key)
306
+ return sorted(exported)
307
+
308
+
256
309
  def clear_cache() -> None:
257
310
  """Clear the SSM cache (useful in tests)."""
258
311
  _cache.clear()
@@ -1,8 +1,5 @@
1
1
  import unittest
2
2
  from velocity.db.servers import postgres
3
- import env
4
-
5
- env.set()
6
3
 
7
4
  test_db = "test_db_postgres"
8
5
  engine = postgres.initialize(database=test_db)
@@ -1,8 +1,8 @@
1
1
  """Collection gate for the PostgreSQL integration suite.
2
2
 
3
- These tests create/drop real databases and call ``env.set()`` (which loads
4
- secrets into ``os.environ``), so they require a live PostgreSQL plus the shared
5
- secrets package. They are skipped by default to keep the unit suite runnable and
3
+ These tests create/drop real databases with the connection settings in the
4
+ environment (``DBHost``, ``DBUser``, ...), so they require a live PostgreSQL.
5
+ They are skipped by default to keep the unit suite runnable and
6
6
  hermetic; opt in with ``VELOCITY_INTEGRATION=1`` (``run_tests.py --integration``
7
7
  sets this automatically).
8
8
  """
@@ -8,9 +8,6 @@ from velocity.db.exceptions import (
8
8
  DbSchemaLockedError,
9
9
  DbTableMissingError,
10
10
  )
11
- import env
12
-
13
- env.set()
14
11
 
15
12
  test_db = "test_db_schema_locking"
16
13
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: velocity-python
3
- Version: 0.9.4
3
+ Version: 0.9.5
4
4
  Summary: A rapid application development library for interfacing with data storage
5
5
  Author-email: Velocity Team <info@codeclubs.org>
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
- velocity/__init__.py,sha256=LQvWrQ_E0n_N5MpD66cec4EmIkVVG4DomZiIyvZIsXA,362
1
+ velocity/__init__.py,sha256=LydmayfShX4hdXo_y2g8VqSvpWvs8FwHc3SdQWzLfYQ,362
2
2
  velocity/cache.py,sha256=pthvw7gDVEXRzkTcQtA5YVf4Q1IxAamWsba4UReT0RE,8933
3
3
  velocity/hooks.py,sha256=jY_qtAapNHvptmryFSD-Zc7RvLhV6e5nJEH3x2xTgCw,20575
4
4
  velocity/logging.py,sha256=MAsZap1cDSdOBNRc_9ezQxup5dHOS0ARxU9NI_-UK3E,4037
@@ -23,7 +23,7 @@ velocity/aws/scheduler.py,sha256=TzhvCcPpgNpRtIdobxQ-A4KsykjAXSM9VUcSr35Lgds,210
23
23
  velocity/aws/schema.py,sha256=k2eaV-WFIs5xrjuFqGKDyYJOkgvqkRJF07sORG2Krfc,5995
24
24
  velocity/aws/settings.py,sha256=aAQL7_dtcC5VSBnk60SX2KwU6jYDmKuyBQVp12Mr5as,39464
25
25
  velocity/aws/sms.py,sha256=2CdcLlIEy_V5K5Qx_pZ2vrakvEK7IhP7y1JUttBgyG4,16253
26
- velocity/aws/ssm_config.py,sha256=xkcBxPuCcdjpeArxdcGnSBiuyG2txlUraSqtCtb_kIo,7987
26
+ velocity/aws/ssm_config.py,sha256=VKjP86WOGBfRZnkMpU22Pu-alxNS1rPUvngyQlTSMcs,10049
27
27
  velocity/aws/tiles.py,sha256=_38EH9ngxQxLeiZnTHBta-TXg1VkO2hPvaoPHWEKAlc,28011
28
28
  velocity/aws/user_data.py,sha256=qLdmzUpkapUToEWaQ_jSeJa6hHgTHIqz0p0Cp2JuFx4,15564
29
29
  velocity/aws/validation.py,sha256=rj1bDYULxR2Wu512vbIhEcmU4Uv_IcwgFX2yS1ZBLf8,18115
@@ -50,7 +50,7 @@ velocity/aws/deploy/frontend_checks.py,sha256=R2y3GlVBKTBqcr46suYn_mpnHkR0s3kgMs
50
50
  velocity/aws/deploy/operations.py,sha256=y5I1otf4gDh37dnPexnjtJhDfYDZQXaP6xC5ZIG-v2o,39406
51
51
  velocity/aws/deploy/policies.py,sha256=aO92HJOCN8L6SE0_BlnTaN6QGywVIPD6FeifvhfdQdM,30747
52
52
  velocity/aws/deploy/reconcile.py,sha256=3xZXXiiVeCw4nUV8lKyk1XCgRbpNCLVYXIXbOLXes9I,20130
53
- velocity/aws/deploy/targets.py,sha256=vmZzGbLDKNtWkwd2ado_ZhT8AT6nXYbJD5nIgDiBzRc,6632
53
+ velocity/aws/deploy/targets.py,sha256=EgeD1f3adnUmefvvBKDVYak9SXLgxB8UeVi9vnvyP-s,7470
54
54
  velocity/aws/handlers/__init__.py,sha256=0yvVADxMHK8JOhgGRxMIz1XkNGlUk08AOmdR4qhNP2U,906
55
55
  velocity/aws/handlers/base_handler.py,sha256=1A_EO_71clM3-h-hAIUJxs_2LL7w3kkwj9Nz33loJMw,19918
56
56
  velocity/aws/handlers/context.py,sha256=Yrq-vtl2-0WeoTaFVMuKOQRM2Cnyq21rNvVtUvGjxx0,61416
@@ -152,8 +152,8 @@ velocity/db/tests/test_sql_builder.py,sha256=6iG-QV24c5KUpc5ZGyt8yEjOlL-JLEucZrg
152
152
  velocity/db/tests/test_tablehelper.py,sha256=1eE9kdGLiXb3mGs_kW7hmCkLTESXFAUzxkV-gdlSELs,19767
153
153
  velocity/db/tests/test_view_helper.py,sha256=IUBXoOJ3x4s8gNy8LM4H8WNeMBZcCCX1WUOZLGkF-VI,2974
154
154
  velocity/db/tests/postgres/__init__.py,sha256=zh28mNshfTljxi_3WAvvmkAxImLduEoHoUT_MAwkzxc,19
155
- velocity/db/tests/postgres/common.py,sha256=i1o6PcZxhamo7EK0CWFP9AqE_EmaA7jzHA2TV6bBjKs,1399
156
- velocity/db/tests/postgres/conftest.py,sha256=OiQH_haNA-zq2Gix90uxz4fnNfrouAeVxjRpclRCWTQ,687
155
+ velocity/db/tests/postgres/common.py,sha256=VtEP0goUWvZ4pcaSg8TskcoQencNJN7P_BEhF3Hrbzg,1377
156
+ velocity/db/tests/postgres/conftest.py,sha256=Azgl-wUkfxmunmPE4dRiFj6HyhyEwuNo6taLDExhpiM,668
157
157
  velocity/db/tests/postgres/test_column.py,sha256=JMIVwZggKbHzLQaB8Ca7Cnt2Q6T1bFwjuiuWxnyxlSU,770
158
158
  velocity/db/tests/postgres/test_connections.py,sha256=Uowjk2Q2BuwyvQ4suZGTMKgIyl5qdMD3P7YOdDoucUc,631
159
159
  velocity/db/tests/postgres/test_database.py,sha256=W5xTQGUUotVakG0t47TjzqOxdZYIEZclM20ZxurtDHY,484
@@ -164,7 +164,7 @@ velocity/db/tests/postgres/test_integrity_triggers.py,sha256=MT_Ia5xAWLE9iGUPyFW
164
164
  velocity/db/tests/postgres/test_result.py,sha256=hD-NyHDBimNAztbOo8SBUu-KOLtHoLQ_0bVJpwnWUCc,461
165
165
  velocity/db/tests/postgres/test_row.py,sha256=cp7zuBiiXvhB-1ZL-gVphKiszvIASHNF7fauDc_YL9o,4518
166
166
  velocity/db/tests/postgres/test_row_comprehensive.py,sha256=O7PJqBjSaEFk5HpXhRPXrxTnfBBqXP8Rd_fEdHLKIyg,24653
167
- velocity/db/tests/postgres/test_schema_locking.py,sha256=hKn1jZeEHyEF4gVhIWp4bZwHfkJXwsS_u3SjmUExdAE,22786
167
+ velocity/db/tests/postgres/test_schema_locking.py,sha256=3OA4TyqJ8pmo6gBWaTj1OHIEl4ewpc2kdtCK4eN9V0A,22764
168
168
  velocity/db/tests/postgres/test_schema_locking_unit.py,sha256=vDll84F1gAJHKEPOwDc4WEpLTuOKU2tfliEY3HkUkIg,3710
169
169
  velocity/db/tests/postgres/test_sequence.py,sha256=5lYQasSkTmPvw3scLbkabr-4d2IKOqQ3-dUi_-l2mPQ,664
170
170
  velocity/db/tests/postgres/test_sql_comprehensive.py,sha256=ZuxKNDKmolysmOHU7l3s5p7AvcA450nxVCBK1zQBedY,19028
@@ -254,9 +254,9 @@ velocity/workflow/points.py,sha256=g_vQ3cdHdx_JloVCS5dVjo_jJoSolO92K5p3suDzxlE,1
254
254
  velocity/workflow/schema.py,sha256=1ZAkGZ_4YrTAfY6TIPCviWQJGLhhmAJmkxisfLyy2og,21597
255
255
  velocity/workflow/traveler.py,sha256=Ik1InoEo69sZB1wVV-UinVo4P0P5QlcV_hh858p3OWE,20562
256
256
  velocity/workflow/views.py,sha256=oTPjpuheND8y4VbcTY8c-4fMdSHKb0jgGzXMuT_G7_s,32175
257
- velocity_python-0.9.4.dist-info/licenses/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
258
- velocity_python-0.9.4.dist-info/METADATA,sha256=-FK2yC9InT4hH-wiYPk3-FX3JgIK0pN-oIR1H950VZc,17789
259
- velocity_python-0.9.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
260
- velocity_python-0.9.4.dist-info/entry_points.txt,sha256=nXUKJHkOGQCSPoagdmMNd_qycrle1LVU-GhYknLGM1M,56
261
- velocity_python-0.9.4.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
262
- velocity_python-0.9.4.dist-info/RECORD,,
257
+ velocity_python-0.9.5.dist-info/licenses/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
258
+ velocity_python-0.9.5.dist-info/METADATA,sha256=chY03lP1fZGDziIoOfldiQr7vXntxyTYUvTdysmn--Q,17789
259
+ velocity_python-0.9.5.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
260
+ velocity_python-0.9.5.dist-info/entry_points.txt,sha256=nXUKJHkOGQCSPoagdmMNd_qycrle1LVU-GhYknLGM1M,56
261
+ velocity_python-0.9.5.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
262
+ velocity_python-0.9.5.dist-info/RECORD,,