clear-skies-aws 2.0.12__tar.gz → 2.0.14__tar.gz
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.
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.copier-answers.yml +1 -1
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.github/workflows/docs.yaml +2 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.pre-commit-config.yaml +1 -2
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/CHANGELOG.md +21 -0
- clear_skies_aws-2.0.14/LATEST_CHANGELOG.md +8 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/PKG-INFO +2 -2
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/pyproject.toml +5 -7
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/di/inject/__init__.py +2 -1
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/secrets/__init__.py +4 -4
- clear_skies_aws-2.0.14/src/clearskies_aws/secrets/cache_storage/__init__.py +9 -0
- clear_skies_aws-2.0.14/src/clearskies_aws/secrets/cache_storage/parameter_store_cache.py +118 -0
- clear_skies_aws-2.0.14/src/clearskies_aws/secrets/parameter_store.py +208 -0
- clear_skies_aws-2.0.14/src/clearskies_aws/secrets/secrets.py +33 -0
- clear_skies_aws-2.0.14/src/clearskies_aws/secrets/secrets_manager.py +193 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/uv.lock +39 -23
- clear_skies_aws-2.0.12/LATEST_CHANGELOG.md +0 -16
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/additional_configs/__init__.py +0 -62
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/additional_configs/iam_db_auth.py +0 -39
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/additional_configs/iam_db_auth_with_ssm.py +0 -96
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/additional_configs/mysql_connection_dynamic_producer_via_ssh_cert_bastion.py +0 -80
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/additional_configs/mysql_connection_dynamic_producer_via_ssm_bastion.py +0 -162
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/akeyless_with_ssm_cache.py +0 -60
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/parameter_store.py +0 -52
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/secrets.py +0 -16
- clear_skies_aws-2.0.12/src/clearskies_aws/secrets/secrets_manager.py +0 -96
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.editorconfig +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.github/workflows/create-version.yaml +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.github/workflows/run-tests.yml +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.github/workflows/tests-matrix.yaml +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.github/workflows/tests.yaml +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.gitignore +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.python-version +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/.vscode/settings.json +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/LICENSE +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/README.md +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/cliff.toml +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/ruff.toml +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/actions/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/actions/action_aws.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/actions/assume_role.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/actions/ses.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/actions/sns.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/actions/sqs.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/actions/step_function.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/backends/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/backends/backend.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/backends/dynamo_db_backend.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/backends/dynamo_db_condition_parser.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/backends/dynamo_db_parti_ql_backend.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/backends/sqs_backend.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/configs/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/cli_web_socket_mock.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/lambda_alb.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/lambda_api_gateway.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/lambda_api_gateway_web_socket.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/lambda_invoke.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/lambda_sns.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/lambda_sqs_standard.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/contexts/lambda_step_function.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/cursors/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/cursors/iam/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/cursors/iam/rds_mysql.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/cursors/port_forwarding/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/cursors/port_forwarding/ssm.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/di/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/di/aws_additional_config_auto_import.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/di/inject/boto3.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/di/inject/boto3_session.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/di/inject/parameter_store.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/endpoints/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/endpoints/secrets_manager_rotation.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/endpoints/simple_body_routing.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/cli_web_socket_mock.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/lambda_alb.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/lambda_api_gateway.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/lambda_api_gateway_web_socket.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/lambda_input_output.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/lambda_invoke.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/lambda_sns.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/lambda_sqs_standard.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/input_outputs/lambda_step_function.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/mocks/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/mocks/actions/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/mocks/actions/ses.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/mocks/actions/sns.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/mocks/actions/sqs.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/mocks/actions/step_function.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/models/__init__.py +0 -0
- {clear_skies_aws-2.0.12 → clear_skies_aws-2.0.14}/src/clearskies_aws/models/web_socket_connection_model.py +0 -0
|
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.14] - 2026-01-28
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Add retry for parameter store
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- Docs by updating to latest copier version
|
|
15
|
+
|
|
16
|
+
## [2.0.13] - 2026-01-28
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- Add support for aws secrets
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Bump version to v2.0.13 by @github-actions[bot]
|
|
23
|
+
- Update dependencies in [#13](https://github.com/clearskies-py/aws/pull/13)
|
|
24
|
+
- Update to clearskies >=2.0.39
|
|
25
|
+
|
|
8
26
|
## [2.0.12] - 2026-01-27
|
|
9
27
|
|
|
10
28
|
### Added
|
|
@@ -12,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
12
30
|
- Add stepfucntions context with variables to ENV vars
|
|
13
31
|
|
|
14
32
|
### Changed
|
|
33
|
+
- Bump version to v2.0.12 by @github-actions[bot]
|
|
15
34
|
- Merge pull request #11 from clearskies-py/stepfunctions-variables by @cmancone in [#11](https://github.com/clearskies-py/aws/pull/11)
|
|
16
35
|
- Update docstrings of stepfunctions
|
|
17
36
|
- Move Environment to the input output of step functions
|
|
@@ -166,6 +185,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
166
185
|
* @cmancone made their first contribution
|
|
167
186
|
* @ made their first contribution
|
|
168
187
|
* @github-actions[bot] made their first contribution
|
|
188
|
+
[2.0.14]: https://github.com/clearskies-py/aws/compare/v2.0.13..v2.0.14
|
|
189
|
+
[2.0.13]: https://github.com/clearskies-py/aws/compare/v2.0.12..v2.0.13
|
|
169
190
|
[2.0.12]: https://github.com/clearskies-py/aws/compare/v2.0.11..v2.0.12
|
|
170
191
|
[2.0.11]: https://github.com/clearskies-py/aws/compare/v2.0.10..v2.0.11
|
|
171
192
|
[2.0.10]: https://github.com/clearskies-py/aws/compare/v2.0.9..v2.0.10
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clear-skies-aws
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.14
|
|
4
4
|
Summary: clearskies bindings for working in AWS
|
|
5
5
|
Project-URL: Repository, https://github.com/clearskies-py/clearskies-aws
|
|
6
6
|
Project-URL: Issues, https://github.com/clearskies-py/clearskies-aws/issues
|
|
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
17
17
|
Requires-Python: <4.0,>=3.11
|
|
18
18
|
Requires-Dist: awslambdaric>=3.1.1
|
|
19
19
|
Requires-Dist: boto3<2.0.0,>=1.26.148
|
|
20
|
-
Requires-Dist: clear-skies<3.0.0,>=2.0.
|
|
20
|
+
Requires-Dist: clear-skies<3.0.0,>=2.0.39
|
|
21
21
|
Requires-Dist: jinja2>=3.1.6
|
|
22
22
|
Requires-Dist: types-boto3[dynamodb,secretsmanager,ses,sns,sqs,ssm,stepfunctions]<2.0.0,>=1.38.13
|
|
23
23
|
Provides-Extra: akeyless
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
name = "clear-skies-aws"
|
|
4
4
|
description = "clearskies bindings for working in AWS"
|
|
5
5
|
license = "MIT"
|
|
6
|
-
version = "2.0.
|
|
6
|
+
version = "2.0.14"
|
|
7
7
|
readme = "./README.md"
|
|
8
8
|
authors = [{name = "tnijboer"}, {name = "Conor Mancone", email = "cmancone@gmail.com"}]
|
|
9
9
|
requires-python = '>=3.11,<4.0'
|
|
10
10
|
dependencies = [
|
|
11
11
|
"awslambdaric>=3.1.1",
|
|
12
12
|
'boto3 (>=1.26.148,<2.0.0)',
|
|
13
|
-
"clear-skies>=2.0.
|
|
13
|
+
"clear-skies>=2.0.39,<3.0.0",
|
|
14
14
|
"jinja2>=3.1.6",
|
|
15
15
|
'types-boto3[dynamodb,sns,sqs,ses,ssm,secretsmanager,stepfunctions] (>=1.38.13,<2.0.0)',
|
|
16
16
|
]
|
|
@@ -47,11 +47,6 @@ exclude = [
|
|
|
47
47
|
"tests/**"
|
|
48
48
|
]
|
|
49
49
|
|
|
50
|
-
[tool.black]
|
|
51
|
-
line-length = 120
|
|
52
|
-
skip-magic-trailing-comma = false
|
|
53
|
-
preview = false
|
|
54
|
-
|
|
55
50
|
[tool.mypy]
|
|
56
51
|
python_version = "3.11"
|
|
57
52
|
|
|
@@ -86,3 +81,6 @@ dev = [
|
|
|
86
81
|
"types-boto3[boto3,essential,secretsmanager,ses,ssm,stepfunctions]>=1.40.40",
|
|
87
82
|
"types-requests>=2.32.4",
|
|
88
83
|
]
|
|
84
|
+
doc = [
|
|
85
|
+
"clear-skies-doc-builder>=2.0.7",
|
|
86
|
+
]
|
|
@@ -2,5 +2,6 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from clearskies_aws.di.inject.boto3 import Boto3
|
|
4
4
|
from clearskies_aws.di.inject.boto3_session import Boto3Session
|
|
5
|
+
from clearskies_aws.di.inject.parameter_store import ParameterStore
|
|
5
6
|
|
|
6
|
-
__all__ = ["Boto3", "Boto3Session"]
|
|
7
|
+
__all__ = ["Boto3", "Boto3Session", "ParameterStore"]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import importlib
|
|
2
|
+
|
|
3
|
+
from clearskies_aws.secrets import cache_storage
|
|
3
4
|
from clearskies_aws.secrets.parameter_store import ParameterStore
|
|
4
5
|
from clearskies_aws.secrets.secrets import Secrets
|
|
5
6
|
from clearskies_aws.secrets.secrets_manager import SecretsManager
|
|
@@ -8,6 +9,5 @@ __all__ = [
|
|
|
8
9
|
"Secrets",
|
|
9
10
|
"ParameterStore",
|
|
10
11
|
"SecretsManager",
|
|
11
|
-
"
|
|
12
|
-
"additional_configs",
|
|
12
|
+
"cache_storage",
|
|
13
13
|
]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AWS-specific secret cache implementations.
|
|
3
|
+
|
|
4
|
+
This module provides cache storage backends for secrets using AWS services.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from clearskies_aws.secrets.cache_storage.parameter_store_cache import ParameterStoreCache
|
|
8
|
+
|
|
9
|
+
__all__ = ["ParameterStoreCache"]
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AWS Parameter Store implementation of SecretCache.
|
|
3
|
+
|
|
4
|
+
This module provides a cache storage backend using AWS Systems Manager Parameter Store.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from clearskies.configs import Boolean, String
|
|
10
|
+
from clearskies.decorators import parameters_to_properties
|
|
11
|
+
from clearskies.di.inject import ByClass
|
|
12
|
+
from clearskies.secrets.cache_storage import SecretCache
|
|
13
|
+
|
|
14
|
+
from clearskies_aws.di import inject
|
|
15
|
+
from clearskies_aws.secrets import parameter_store
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ParameterStoreCache(SecretCache):
|
|
19
|
+
"""
|
|
20
|
+
Cache storage backend using AWS Systems Manager Parameter Store.
|
|
21
|
+
|
|
22
|
+
This class implements the SecretCache interface to store cached secrets in AWS
|
|
23
|
+
Parameter Store. Paths are automatically sanitized by the underlying ParameterStore
|
|
24
|
+
to comply with SSM parameter naming requirements.
|
|
25
|
+
|
|
26
|
+
### Example Usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from clearskies.secrets import Akeyless
|
|
30
|
+
from clearskies_aws.secrets.secrets_cache import ParameterStoreCache
|
|
31
|
+
|
|
32
|
+
cache = ParameterStoreCache(prefix="/cache/secrets")
|
|
33
|
+
akeyless = Akeyless(
|
|
34
|
+
access_id="p-xxx",
|
|
35
|
+
access_type="aws_iam",
|
|
36
|
+
cache_storage=cache,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# First call fetches from Akeyless and caches in Parameter Store
|
|
40
|
+
secret = akeyless.get("/path/to/secret")
|
|
41
|
+
|
|
42
|
+
# Subsequent calls return from Parameter Store cache
|
|
43
|
+
secret = akeyless.get("/path/to/secret")
|
|
44
|
+
|
|
45
|
+
# Force refresh bypasses cache
|
|
46
|
+
secret = akeyless.get("/path/to/secret", refresh=True)
|
|
47
|
+
```
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
boto3 = inject.Boto3()
|
|
51
|
+
|
|
52
|
+
parameter_store = ByClass(parameter_store.ParameterStore)
|
|
53
|
+
|
|
54
|
+
prefix = String(default=None)
|
|
55
|
+
allow_cleanup = Boolean(default=False)
|
|
56
|
+
|
|
57
|
+
@parameters_to_properties
|
|
58
|
+
def __init__(self, prefix: str | None = None, allow_cleanup: bool = False) -> None:
|
|
59
|
+
"""
|
|
60
|
+
Initialize the Parameter Store cache.
|
|
61
|
+
|
|
62
|
+
The prefix is prepended to all secret paths when storing in Parameter Store.
|
|
63
|
+
This helps organize cached secrets and avoid conflicts with other parameters.
|
|
64
|
+
"""
|
|
65
|
+
super().__init__()
|
|
66
|
+
|
|
67
|
+
def _build_path(self, path: str) -> str:
|
|
68
|
+
"""
|
|
69
|
+
Build the full parameter path by prepending the prefix.
|
|
70
|
+
|
|
71
|
+
The path is sanitized by the underlying ParameterStore.
|
|
72
|
+
"""
|
|
73
|
+
return f"{self.prefix}/{path.lstrip('/')}"
|
|
74
|
+
|
|
75
|
+
def get(self, path: str) -> str | None:
|
|
76
|
+
"""
|
|
77
|
+
Retrieve a cached secret value from Parameter Store.
|
|
78
|
+
|
|
79
|
+
Returns the cached secret value for the given path, or None if not found.
|
|
80
|
+
"""
|
|
81
|
+
ssm_name = self._build_path(path)
|
|
82
|
+
return self.parameter_store.get(ssm_name, silent_if_not_found=True)
|
|
83
|
+
|
|
84
|
+
def set(self, path: str, value: str, ttl: int | None = None) -> None:
|
|
85
|
+
"""
|
|
86
|
+
Store a secret value in Parameter Store.
|
|
87
|
+
|
|
88
|
+
Stores the secret value as a SecureString parameter. Note that Parameter Store
|
|
89
|
+
does not natively support TTL, so the ttl parameter is ignored. Consider using
|
|
90
|
+
a cleanup process or Lambda function to remove stale cached secrets.
|
|
91
|
+
"""
|
|
92
|
+
ssm_name = self._build_path(path)
|
|
93
|
+
self.parameter_store.update(ssm_name, value)
|
|
94
|
+
|
|
95
|
+
def delete(self, path: str) -> None:
|
|
96
|
+
"""
|
|
97
|
+
Remove a secret from the Parameter Store cache.
|
|
98
|
+
|
|
99
|
+
Deletes the parameter at the given path. Does nothing if the parameter
|
|
100
|
+
doesn't exist.
|
|
101
|
+
"""
|
|
102
|
+
ssm_name = self._build_path(path)
|
|
103
|
+
self.parameter_store.delete(ssm_name)
|
|
104
|
+
|
|
105
|
+
def clear(self) -> None:
|
|
106
|
+
"""
|
|
107
|
+
Remove all cached secrets from Parameter Store under the configured prefix.
|
|
108
|
+
|
|
109
|
+
This method deletes all parameters under the cache prefix. Use with caution
|
|
110
|
+
in production environments.
|
|
111
|
+
"""
|
|
112
|
+
if not self.allow_cleanup:
|
|
113
|
+
raise RuntimeError(
|
|
114
|
+
"Clearing the Parameter Store cache is not allowed. Set allow_cleanup=True to enable this operation."
|
|
115
|
+
)
|
|
116
|
+
names = self.parameter_store.list_by_path(self.prefix, recursive=True)
|
|
117
|
+
if names:
|
|
118
|
+
self.parameter_store.delete_many(names)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from botocore.config import Config
|
|
7
|
+
from botocore.exceptions import ClientError
|
|
8
|
+
from clearskies.exceptions.not_found import NotFound
|
|
9
|
+
from types_boto3_ssm import SSMClient
|
|
10
|
+
|
|
11
|
+
from clearskies_aws.secrets import secrets
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ParameterStore(secrets.Secrets[SSMClient]):
|
|
15
|
+
"""
|
|
16
|
+
Backend for managing secrets using AWS Systems Manager Parameter Store.
|
|
17
|
+
|
|
18
|
+
This class provides integration with AWS SSM Parameter Store, allowing you to store,
|
|
19
|
+
retrieve, update, and delete secrets. All values are stored as SecureString by default
|
|
20
|
+
for security.
|
|
21
|
+
|
|
22
|
+
Paths are automatically sanitized to comply with SSM parameter naming requirements.
|
|
23
|
+
AWS SSM parameter paths only allow: a-z, A-Z, 0-9, -, _, ., /, @, and :
|
|
24
|
+
Any disallowed characters in the path are replaced with hyphens.
|
|
25
|
+
|
|
26
|
+
The client is configured with adaptive retry mode which automatically handles
|
|
27
|
+
throttling exceptions with exponential backoff (up to 10 retries).
|
|
28
|
+
|
|
29
|
+
### Example Usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from clearskies_aws.secrets import ParameterStore
|
|
33
|
+
|
|
34
|
+
secrets = ParameterStore()
|
|
35
|
+
|
|
36
|
+
# Create/update a secret (stored as SecureString)
|
|
37
|
+
secrets.update("/my-app/database-password", "super-secret")
|
|
38
|
+
|
|
39
|
+
# Get a secret
|
|
40
|
+
password = secrets.get("/my-app/database-password")
|
|
41
|
+
|
|
42
|
+
# Delete a secret
|
|
43
|
+
secrets.delete("/my-app/database-password")
|
|
44
|
+
```
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
ssm: SSMClient
|
|
48
|
+
|
|
49
|
+
def __init__(self):
|
|
50
|
+
"""Initialize the Parameter Store backend."""
|
|
51
|
+
super().__init__()
|
|
52
|
+
|
|
53
|
+
def _sanitize_path(self, path: str) -> str:
|
|
54
|
+
"""
|
|
55
|
+
Sanitize a secret path for use as an SSM parameter name.
|
|
56
|
+
|
|
57
|
+
AWS SSM parameter paths only allow a-z, A-Z, 0-9, -, _, ., /, @, and :
|
|
58
|
+
Any disallowed characters are replaced with hyphens.
|
|
59
|
+
"""
|
|
60
|
+
return re.sub(r"[^a-zA-Z0-9\-_\./@:]", "-", path)
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def boto3_client(self) -> SSMClient:
|
|
64
|
+
"""
|
|
65
|
+
Return the boto3 SSM client.
|
|
66
|
+
|
|
67
|
+
Creates a new client if one doesn't exist yet, using the AWS_REGION environment variable.
|
|
68
|
+
Configured with adaptive retry mode for better throttling handling.
|
|
69
|
+
"""
|
|
70
|
+
if hasattr(self, "ssm"):
|
|
71
|
+
return self.ssm
|
|
72
|
+
|
|
73
|
+
# Configure adaptive retry mode with increased max attempts for throttling
|
|
74
|
+
# Adaptive mode automatically adjusts retry behavior based on error responses
|
|
75
|
+
# and includes exponential backoff with jitter
|
|
76
|
+
retry_config = Config(
|
|
77
|
+
retries={
|
|
78
|
+
"max_attempts": 10,
|
|
79
|
+
"mode": "adaptive",
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
self.ssm = self.boto3.client(
|
|
84
|
+
"ssm",
|
|
85
|
+
region_name=self.environment.get("AWS_REGION"),
|
|
86
|
+
config=retry_config,
|
|
87
|
+
)
|
|
88
|
+
return self.ssm
|
|
89
|
+
|
|
90
|
+
def create(self, path: str, value: str) -> bool:
|
|
91
|
+
"""
|
|
92
|
+
Create a new parameter in Parameter Store.
|
|
93
|
+
|
|
94
|
+
This is an alias for update() since Parameter Store uses upsert semantics.
|
|
95
|
+
"""
|
|
96
|
+
return self.update(path, value)
|
|
97
|
+
|
|
98
|
+
def get(self, path: str, silent_if_not_found: bool = False) -> str | None: # type: ignore[override]
|
|
99
|
+
"""
|
|
100
|
+
Retrieve a parameter value from Parameter Store.
|
|
101
|
+
|
|
102
|
+
Returns the decrypted parameter value for the given path. If silent_if_not_found
|
|
103
|
+
is True, returns None when the parameter is not found instead of raising NotFound.
|
|
104
|
+
|
|
105
|
+
Throttling is handled automatically by boto3's adaptive retry mode configured
|
|
106
|
+
on the client (up to 10 retries with exponential backoff and jitter).
|
|
107
|
+
"""
|
|
108
|
+
sanitized_path = self._sanitize_path(path)
|
|
109
|
+
try:
|
|
110
|
+
result = self.boto3_client.get_parameter(Name=sanitized_path, WithDecryption=True)
|
|
111
|
+
except ClientError as e:
|
|
112
|
+
error = e.response.get("Error", {})
|
|
113
|
+
if error.get("Code") == "ResourceNotFoundException":
|
|
114
|
+
if silent_if_not_found:
|
|
115
|
+
return None
|
|
116
|
+
raise NotFound(f"Could not find secret '{path}' in parameter store")
|
|
117
|
+
raise e
|
|
118
|
+
return result["Parameter"].get("Value", "")
|
|
119
|
+
|
|
120
|
+
def list_secrets(self, path: str) -> list[str]:
|
|
121
|
+
"""
|
|
122
|
+
List parameters at the given path.
|
|
123
|
+
|
|
124
|
+
Returns a list of parameter names at the specified path (non-recursive).
|
|
125
|
+
"""
|
|
126
|
+
sanitized_path = self._sanitize_path(path)
|
|
127
|
+
response = self.boto3_client.get_parameters_by_path(Path=sanitized_path, Recursive=False)
|
|
128
|
+
return [parameter["Name"] for parameter in response["Parameters"] if "Name" in parameter]
|
|
129
|
+
|
|
130
|
+
def update(self, path: str, value: str) -> bool: # type: ignore[override]
|
|
131
|
+
"""
|
|
132
|
+
Update or create a secret as a SecureString.
|
|
133
|
+
|
|
134
|
+
Creates the parameter if it doesn't exist, or updates it if it does.
|
|
135
|
+
The value is stored as an encrypted SecureString using the default KMS key.
|
|
136
|
+
"""
|
|
137
|
+
sanitized_path = self._sanitize_path(path)
|
|
138
|
+
self.boto3_client.put_parameter(
|
|
139
|
+
Name=sanitized_path,
|
|
140
|
+
Value=value,
|
|
141
|
+
Type="SecureString",
|
|
142
|
+
Overwrite=True,
|
|
143
|
+
)
|
|
144
|
+
return True
|
|
145
|
+
|
|
146
|
+
def upsert(self, path: str, value: str) -> bool: # type: ignore[override]
|
|
147
|
+
"""
|
|
148
|
+
Create or update a secret.
|
|
149
|
+
|
|
150
|
+
This is an alias for update() since Parameter Store uses upsert semantics.
|
|
151
|
+
"""
|
|
152
|
+
return self.update(path, value)
|
|
153
|
+
|
|
154
|
+
def delete(self, path: str) -> bool:
|
|
155
|
+
"""
|
|
156
|
+
Delete a parameter from Parameter Store.
|
|
157
|
+
|
|
158
|
+
Returns True if the parameter was deleted, False if it didn't exist.
|
|
159
|
+
"""
|
|
160
|
+
sanitized_path = self._sanitize_path(path)
|
|
161
|
+
try:
|
|
162
|
+
self.boto3_client.delete_parameter(Name=sanitized_path)
|
|
163
|
+
return True
|
|
164
|
+
except ClientError as e:
|
|
165
|
+
error = e.response.get("Error", {})
|
|
166
|
+
if error.get("Code") == "ParameterNotFound":
|
|
167
|
+
return False
|
|
168
|
+
raise e
|
|
169
|
+
|
|
170
|
+
def delete_many(self, paths: list[str]) -> bool:
|
|
171
|
+
"""
|
|
172
|
+
Delete multiple parameters from Parameter Store.
|
|
173
|
+
|
|
174
|
+
Deletes up to 10 parameters at a time (SSM limit). For larger lists,
|
|
175
|
+
recursively calls itself to delete in batches.
|
|
176
|
+
"""
|
|
177
|
+
if not paths:
|
|
178
|
+
return True
|
|
179
|
+
sanitized_paths = [self._sanitize_path(p) for p in paths]
|
|
180
|
+
self.boto3_client.delete_parameters(Names=sanitized_paths[:10])
|
|
181
|
+
if len(sanitized_paths) > 10:
|
|
182
|
+
return self.delete_many(paths[10:])
|
|
183
|
+
return True
|
|
184
|
+
|
|
185
|
+
def list_by_path(self, path: str, recursive: bool = True) -> list[str]:
|
|
186
|
+
"""
|
|
187
|
+
List all parameter names under a given path.
|
|
188
|
+
|
|
189
|
+
Returns a list of parameter names (not values) under the specified path.
|
|
190
|
+
Uses pagination to handle large result sets.
|
|
191
|
+
"""
|
|
192
|
+
sanitized_path = self._sanitize_path(path)
|
|
193
|
+
names: list[str] = []
|
|
194
|
+
paginator = self.boto3_client.get_paginator("get_parameters_by_path")
|
|
195
|
+
for page in paginator.paginate(Path=sanitized_path, Recursive=recursive):
|
|
196
|
+
names.extend([param["Name"] for param in page.get("Parameters", [])])
|
|
197
|
+
return names
|
|
198
|
+
|
|
199
|
+
def list_sub_folders(
|
|
200
|
+
self,
|
|
201
|
+
path: str,
|
|
202
|
+
) -> list[Any]:
|
|
203
|
+
"""
|
|
204
|
+
List sub-folders at the given path.
|
|
205
|
+
|
|
206
|
+
This operation is not supported by Parameter Store.
|
|
207
|
+
"""
|
|
208
|
+
raise NotImplementedError("Parameter store doesn't support list_sub_folders.")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import profile
|
|
4
|
+
from typing import Generic, Protocol, TypeVar
|
|
5
|
+
|
|
6
|
+
from clearskies.di.inject import Di, Environment
|
|
7
|
+
from clearskies.secrets import Secrets as BaseSecrets
|
|
8
|
+
|
|
9
|
+
from clearskies_aws.di import inject
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Boto3Client(Protocol):
|
|
13
|
+
"""Protocol for boto3 clients to enable type-safe generic return types."""
|
|
14
|
+
|
|
15
|
+
...
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
ClientT = TypeVar("ClientT", bound=Boto3Client)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Secrets(BaseSecrets, Generic[ClientT]):
|
|
22
|
+
boto3 = inject.Boto3()
|
|
23
|
+
environment = Environment()
|
|
24
|
+
|
|
25
|
+
def __init__(self):
|
|
26
|
+
super().__init__()
|
|
27
|
+
if not self.environment.get("AWS_REGION", True):
|
|
28
|
+
raise ValueError("To use secrets manager you must use set the 'AWS_REGION' environment variable")
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def boto3_client(self) -> ClientT:
|
|
32
|
+
"""Return the boto3 client for the secrets manager implementation."""
|
|
33
|
+
raise NotImplementedError("You must implement the client property in subclasses")
|