clear-skies-aws 2.0.3__tar.gz → 2.0.5__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.
Files changed (84) hide show
  1. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.pre-commit-config.yaml +1 -4
  2. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/CHANGELOG.md +20 -0
  3. clear_skies_aws-2.0.5/LATEST_CHANGELOG.md +5 -0
  4. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/PKG-INFO +4 -2
  5. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/pyproject.toml +6 -4
  6. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/__init__.py +2 -0
  7. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/backends/__init__.py +3 -3
  8. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/backends/dynamo_db_backend.py +1 -0
  9. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/backends/dynamo_db_condition_parser.py +1 -0
  10. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/backends/dynamo_db_parti_ql_backend.py +2 -0
  11. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/contexts/lambda_api_gateway_web_socket.py +2 -2
  12. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/contexts/lambda_invoke.py +2 -2
  13. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/contexts/lambda_sqs_standard.py +2 -2
  14. clear_skies_aws-2.0.5/src/clearskies_aws/cursors/__init__.py +3 -0
  15. clear_skies_aws-2.0.5/src/clearskies_aws/cursors/iam/__init__.py +7 -0
  16. clear_skies_aws-2.0.5/src/clearskies_aws/cursors/iam/rds_mysql.py +125 -0
  17. clear_skies_aws-2.0.5/src/clearskies_aws/cursors/port_forwarding/__init__.py +3 -0
  18. clear_skies_aws-2.0.5/src/clearskies_aws/cursors/port_forwarding/ssm.py +137 -0
  19. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/di/aws_additional_config_auto_import.py +1 -1
  20. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/di/inject/boto3.py +1 -1
  21. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/endpoints/secrets_manager_rotation.py +1 -1
  22. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/uv.lock +409 -380
  23. clear_skies_aws-2.0.3/LATEST_CHANGELOG.md +0 -34
  24. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.copier-answers.yml +0 -0
  25. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.editorconfig +0 -0
  26. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.github/workflows/create-version.yaml +0 -0
  27. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.github/workflows/docs.yaml +0 -0
  28. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.github/workflows/run-tests.yml +0 -0
  29. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.github/workflows/tests-matrix.yaml +0 -0
  30. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.github/workflows/tests.yaml +0 -0
  31. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.gitignore +0 -0
  32. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/.python-version +0 -0
  33. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/LICENSE +0 -0
  34. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/README.md +0 -0
  35. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/cliff.toml +0 -0
  36. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/ruff.toml +0 -0
  37. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/actions/__init__.py +0 -0
  38. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/actions/action_aws.py +0 -0
  39. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/actions/assume_role.py +0 -0
  40. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/actions/ses.py +0 -0
  41. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/actions/sns.py +0 -0
  42. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/actions/sqs.py +0 -0
  43. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/actions/step_function.py +0 -0
  44. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/backends/backend.py +0 -0
  45. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/backends/sqs_backend.py +0 -0
  46. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/configs/__init__.py +0 -0
  47. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/contexts/__init__.py +0 -0
  48. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/contexts/cli_web_socket_mock.py +0 -0
  49. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/contexts/lambda_alb.py +0 -0
  50. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/contexts/lambda_api_gateway.py +0 -0
  51. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/contexts/lambda_sns.py +0 -0
  52. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/di/__init__.py +0 -0
  53. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/di/inject/__init__.py +0 -0
  54. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/di/inject/boto3_session.py +0 -0
  55. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/di/inject/parameter_store.py +0 -0
  56. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/endpoints/__init__.py +0 -0
  57. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/endpoints/simple_body_routing.py +0 -0
  58. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/__init__.py +0 -0
  59. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/cli_web_socket_mock.py +0 -0
  60. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/lambda_alb.py +0 -0
  61. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/lambda_api_gateway.py +0 -0
  62. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/lambda_api_gateway_web_socket.py +0 -0
  63. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/lambda_input_output.py +0 -0
  64. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/lambda_invoke.py +0 -0
  65. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/lambda_sns.py +0 -0
  66. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/input_outputs/lambda_sqs_standard.py +0 -0
  67. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/mocks/__init__.py +0 -0
  68. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/mocks/actions/__init__.py +0 -0
  69. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/mocks/actions/ses.py +0 -0
  70. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/mocks/actions/sns.py +0 -0
  71. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/mocks/actions/sqs.py +0 -0
  72. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/mocks/actions/step_function.py +0 -0
  73. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/models/__init__.py +0 -0
  74. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/models/web_socket_connection_model.py +0 -0
  75. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/__init__.py +0 -0
  76. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/additional_configs/__init__.py +0 -0
  77. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/additional_configs/iam_db_auth.py +0 -0
  78. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/additional_configs/iam_db_auth_with_ssm.py +0 -0
  79. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/additional_configs/mysql_connection_dynamic_producer_via_ssh_cert_bastion.py +0 -0
  80. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/additional_configs/mysql_connection_dynamic_producer_via_ssm_bastion.py +0 -0
  81. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/akeyless_with_ssm_cache.py +0 -0
  82. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/parameter_store.py +0 -0
  83. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/secrets.py +0 -0
  84. {clear_skies_aws-2.0.3 → clear_skies_aws-2.0.5}/src/clearskies_aws/secrets/secrets_manager.py +0 -0
@@ -8,9 +8,6 @@ ci:
8
8
  default_install_hook_types:
9
9
  - pre-commit
10
10
  - commit-msg
11
- - post-checkout
12
- - post-merge
13
- - post-rewrite
14
11
 
15
12
  default_stages: ["pre-commit"]
16
13
 
@@ -69,7 +66,7 @@ repos:
69
66
  hooks:
70
67
  - id: pytest
71
68
  name: pytest
72
- entry: uv run pytest .
69
+ entry: uv run pytest . -m "not broken"
73
70
  language: system
74
71
  types: [python]
75
72
  pass_filenames: false
@@ -5,9 +5,27 @@ 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.5] - 2026-01-12
9
+
10
+ ### Added
11
+ - Add ssm portforwarder in [#9](https://github.com/clearskies-py/aws/pull/9)
12
+
13
+ ## [2.0.4] - 2026-01-09
14
+
15
+ ### Added
16
+ - Add rds mysql cursor
17
+
18
+ ### Changed
19
+ - Bump version to v2.0.4 by @github-actions[bot]
20
+ - Use the port forwarder class in [#8](https://github.com/clearskies-py/aws/pull/8)
21
+
22
+ ### Fixed
23
+ - Make age dynamic instead of fixed
24
+
8
25
  ## [2.0.3] - 2026-01-05
9
26
 
10
27
  ### Changed
28
+ - Bump version to v2.0.3 by @github-actions[bot]
11
29
  - Merge pull request #7 from clearskies-py/contexts by @cmancone in [#7](https://github.com/clearskies-py/aws/pull/7)
12
30
  - Require latest clearskies version per added feature by @cmancone
13
31
  - Bring up-to-date by @cmancone
@@ -77,6 +95,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
95
  * @cmancone made their first contribution
78
96
  * @ made their first contribution
79
97
  * @github-actions[bot] made their first contribution
98
+ [2.0.5]: https://github.com/clearskies-py/aws/compare/v2.0.4..v2.0.5
99
+ [2.0.4]: https://github.com/clearskies-py/aws/compare/v2.0.3..v2.0.4
80
100
  [2.0.3]: https://github.com/clearskies-py/aws/compare/v2.0.2..v2.0.3
81
101
  [2.0.2]: https://github.com/clearskies-py/aws/compare/v2.0.1..v2.0.2
82
102
 
@@ -0,0 +1,5 @@
1
+ ## [2.0.5] - 2026-01-12
2
+
3
+ ### Added
4
+ - Add ssm portforwarder in [#9](https://github.com/clearskies-py/aws/pull/9)
5
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clear-skies-aws
3
- Version: 2.0.3
3
+ Version: 2.0.5
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,10 +17,12 @@ Classifier: Programming Language :: Python :: 3
17
17
  Requires-Python: <4.0,>=3.11
18
18
  Requires-Dist: boto3<2.0.0,>=1.26.148
19
19
  Requires-Dist: clear-skies<3.0.0,>=2.0.20
20
- Requires-Dist: types-boto3[dynamodb,sns,sqs]<2.0.0,>=1.38.13
20
+ Requires-Dist: types-boto3[dynamodb,secretsmanager,ses,sns,sqs,ssm,stepfunctions]<2.0.0,>=1.38.13
21
21
  Provides-Extra: akeyless
22
22
  Requires-Dist: akeyless-cloud-id<0.5.0,>=0.2.3; extra == 'akeyless'
23
23
  Requires-Dist: akeyless<6.0.0,>=5.0.0; extra == 'akeyless'
24
+ Provides-Extra: mysql
25
+ Requires-Dist: clear-skies[mysql]; extra == 'mysql'
24
26
  Provides-Extra: ses
25
27
  Requires-Dist: jinja2<4.0.0,>=3.1.2; extra == 'ses'
26
28
  Description-Content-Type: text/markdown
@@ -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.3"
6
+ version = "2.0.5"
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
  'boto3 (>=1.26.148,<2.0.0)',
12
- 'clear-skies (>=2.0.20,<3.0.0)',
13
- 'types-boto3[dynamodb,sns,sqs] (>=1.38.13,<2.0.0)',
12
+ "clear-skies>=2.0.20,<3.0.0",
13
+ 'types-boto3[dynamodb,sns,sqs,ses,ssm,secretsmanager,stepfunctions] (>=1.38.13,<2.0.0)',
14
14
  ]
15
15
  classifiers = [
16
16
  "Development Status :: 5 - Production/Stable",
@@ -28,6 +28,7 @@ Documentation = "https://clearskies.info/modules/clearskies-aws/"
28
28
  [project.optional-dependencies]
29
29
  akeyless = ['akeyless-cloud-id (>=0.2.3,<0.5.0)', 'akeyless (>=5.0.0,<6.0.0)']
30
30
  ses = ['jinja2 (>=3.1.2,<4.0.0)']
31
+ mysql = ['clear-skies[mysql]']
31
32
 
32
33
  [build-system]
33
34
  requires = ["hatchling"]
@@ -55,7 +56,8 @@ python_version = "3.11"
55
56
 
56
57
  exclude = [
57
58
  ".*_test\\.py$",
58
- "docs/.*"
59
+ "docs/.*",
60
+ "tests/.*"
59
61
  ]
60
62
 
61
63
  [tool.pytest.ini_options]
@@ -4,6 +4,7 @@ from clearskies_aws import (
4
4
  actions,
5
5
  backends,
6
6
  contexts,
7
+ cursors,
7
8
  di,
8
9
  endpoints,
9
10
  handlers,
@@ -17,6 +18,7 @@ __all__ = [
17
18
  "actions",
18
19
  "backends",
19
20
  "contexts",
21
+ "cursors",
20
22
  "di",
21
23
  "endpoints",
22
24
  "handlers",
@@ -1,9 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from clearskies_aws.backends.backend import Backend
4
- from clearskies_aws.backends.dynamo_db_backend import DynamoDBBackend
5
- from clearskies_aws.backends.dynamo_db_condition_parser import DynamoDBConditionParser
6
- from clearskies_aws.backends.dynamo_db_parti_ql_backend import (
4
+ from clearskies_aws.backends.dynamo_db_backend import DynamoDBBackend # type: ignore
5
+ from clearskies_aws.backends.dynamo_db_condition_parser import DynamoDBConditionParser # type: ignore
6
+ from clearskies_aws.backends.dynamo_db_parti_ql_backend import ( # type: ignore
7
7
  DynamoDBPartiQLBackend,
8
8
  DynamoDBPartiQLCursor,
9
9
  )
@@ -1,3 +1,4 @@
1
+ # type: ignore
1
2
  from __future__ import annotations
2
3
 
3
4
  import base64
@@ -1,3 +1,4 @@
1
+ # type: ignore
1
2
  from __future__ import annotations
2
3
 
3
4
  import base64
@@ -1,3 +1,5 @@
1
+ # type: ignore
2
+
1
3
  from __future__ import annotations
2
4
 
3
5
  import base64
@@ -73,7 +73,7 @@ class LambdaApiGatewayWebSocket(Context):
73
73
 
74
74
  """
75
75
 
76
- def __call__(
76
+ def __call__( # type: ignore[override]
77
77
  self, event: dict[str, Any], context: dict[str, Any], url: str = "", request_method: str = ""
78
- ) -> dict[str, Any]: # type: ignore[override]
78
+ ) -> dict[str, Any]:
79
79
  return self.execute_application(LambdaApiGatewayWebSocketInputOutput(event, context, url))
@@ -125,9 +125,9 @@ class LambdaInvoke(Context):
125
125
 
126
126
  """
127
127
 
128
- def __call__(
128
+ def __call__( # type: ignore[override]
129
129
  self, event: dict[str, Any], context: dict[str, Any], request_method: str = "", url: str = ""
130
- ) -> dict[str, Any]: # type: ignore[override]
130
+ ) -> dict[str, Any]:
131
131
  return self.execute_application(
132
132
  LambdaInvokeInputOutput(
133
133
  event,
@@ -120,9 +120,9 @@ class LambdaSqsStandard(Context):
120
120
 
121
121
  """
122
122
 
123
- def __call__(
123
+ def __call__( # type: ignore[override]
124
124
  self, event: dict[str, Any], context: dict[str, Any], url: str = "", request_method: str = ""
125
- ) -> dict[str, Any]: # type: ignore[override]
125
+ ) -> dict[str, Any]:
126
126
  item_failures = []
127
127
  for record in event["Records"]:
128
128
  try:
@@ -0,0 +1,3 @@
1
+ from clearskies_aws.cursors import iam, port_forwarding
2
+
3
+ __all__ = ["iam", "port_forwarding"]
@@ -0,0 +1,7 @@
1
+ import logging
2
+
3
+ from clearskies_aws.cursors.iam.rds_mysql import RdsMysql
4
+
5
+ logging.getLogger(__name__)
6
+
7
+ __all__ = ["RdsMysql"]
@@ -0,0 +1,125 @@
1
+ """
2
+ RdsMySql: MySQL cursor with AWS RDS IAM authentication.
3
+
4
+ This class provides a MySQL cursor that uses AWS RDS IAM DB authentication.
5
+ It loads connection parameters from environment variables and generates a temporary
6
+ IAM authentication token for secure database access.
7
+
8
+ Configuration fields:
9
+ - boto3: Injected boto3 provider for AWS API access.
10
+ - environment: Injected environment variable provider.
11
+ - hostname_environment_key: Environment variable for DB host (default: "DATABASE_HOST").
12
+ - username_environment_key: Environment variable for DB user (default: "DATABASE_USERNAME").
13
+ - database_environment_key: Environment variable for DB name (default: "DATABASE_NAME").
14
+ - port_environment_key: Environment variable for DB port (default: "DATABASE_PORT").
15
+ - cert_path_environment_key: Environment variable for SSL CA cert (default: "DATABASE_CERT_PATH").
16
+ - autocommit_environment_key: Environment variable for autocommit (default: "DATABASE_AUTOCOMMIT").
17
+ - connect_timeout_environment_key: Environment variable for connect timeout (default: "DATABASE_CONNECT_TIMEOUT").
18
+ - database_region_key: Environment variable for AWS region (default: "DATABASE_REGION").
19
+
20
+ Example:
21
+ import clearskies_aws.cursors.iam.rds_mysql
22
+
23
+ cursor = clearskies_aws.cursors.iam.rds_mysql.RdsMySql()
24
+ cursor.execute("SELECT 1")
25
+ """
26
+
27
+ import os
28
+ from typing import Any
29
+
30
+ import clearskies
31
+ from clearskies import decorators
32
+ from clearskies.cursors import Mysql
33
+
34
+ from clearskies_aws.di import inject
35
+
36
+
37
+ class RdsMysql(Mysql):
38
+ """MySQL cursor with AWS RDS IAM DB authentication."""
39
+
40
+ """Injected boto3 provider for AWS API access."""
41
+ boto3 = inject.Boto3()
42
+
43
+ """Injected environment variable provider."""
44
+ environment = clearskies.di.inject.Environment()
45
+
46
+ """Environment variable for DB host (default: "DATABASE_HOST")."""
47
+ hostname_environment_key = clearskies.configs.String(default="DATABASE_HOST")
48
+
49
+ """Environment variable for DB user (default: "DATABASE_USERNAME")."""
50
+ username_environment_key = clearskies.configs.String(default="DATABASE_USERNAME")
51
+
52
+ """Environment variable for DB name (default: "DATABASE_NAME")."""
53
+ database_environment_key = clearskies.configs.String(default="DATABASE_NAME")
54
+
55
+ """Environment variable for DB port (default: "DATABASE_PORT")."""
56
+ port_environment_key = clearskies.configs.String(default="DATABASE_PORT")
57
+
58
+ """Environment variable for SSL CA cert (default: "DATABASE_CERT_PATH")."""
59
+ cert_path_environment_key = clearskies.configs.String(default="DATABASE_CERT_PATH")
60
+
61
+ """Environment variable for autocommit (default: "DATABASE_AUTOCOMMIT")."""
62
+ autocommit_environment_key = clearskies.configs.String(default="DATABASE_AUTOCOMMIT")
63
+
64
+ """Environment variable for connect timeout (default: "DATABASE_CONNECT_TIMEOUT")."""
65
+ connect_timeout_environment_key = clearskies.configs.String(default="DATABASE_CONNECT_TIMEOUT")
66
+
67
+ """Environment variable for AWS region (default: "DATABASE_REGION")."""
68
+ database_region_key = clearskies.configs.String(default="DATABASE_REGION")
69
+
70
+ @decorators.parameters_to_properties
71
+ def __init__(
72
+ self,
73
+ hostname_environment_key: str | None = None,
74
+ username_environment_key: str | None = None,
75
+ database_environment_key: str | None = None,
76
+ port_environment_key: str | None = None,
77
+ cert_path_environment_key: str | None = None,
78
+ autocommit_environment_key: str | None = None,
79
+ database_region_key: str | None = None,
80
+ connect_timeout_environment_key: str | None = None,
81
+ port_forwarding: Any | None = None,
82
+ ):
83
+ self.finalize_and_validate_configuration()
84
+
85
+ def build_connection_kwargs(self) -> dict:
86
+ """
87
+ Build the connection kwargs for the MySQL client, using IAM DB authentication.
88
+
89
+ Returns
90
+ -------
91
+ dict
92
+ Connection parameters for the MySQL client.
93
+ """
94
+ connection_kwargs = {
95
+ "user": self.environment.get(self.username_environment_key),
96
+ "host": self.environment.get(self.hostname_environment_key),
97
+ "database": self.environment.get(self.database_environment_key),
98
+ "port": int(self.environment.get(self.port_environment_key, silent=True) or self.port),
99
+ "ssl_ca": self.environment.get(self.cert_path_environment_key, silent=True),
100
+ "autocommit": self.environment.get(self.autocommit_environment_key, silent=True),
101
+ "connect_timeout": int(
102
+ self.environment.get(self.connect_timeout_environment_key, silent=True) or self.connect_timeout
103
+ ),
104
+ }
105
+ region: str = self.environment.get(self.database_region_key, True) or self.environment.get("AWS_REGION", True)
106
+ if not region:
107
+ raise ValueError(
108
+ "To use RDS IAM DB auth you must set DATABASE_REGION or AWS_REGION in the .env file or an environment variable"
109
+ )
110
+ os.environ["LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN"] = "1"
111
+
112
+ rds_api = self.boto3.Session().client("rds")
113
+ rds_token = rds_api.generate_db_auth_token(
114
+ DBHostname=connection_kwargs.get("host"),
115
+ Port=connection_kwargs.get("port", 3306),
116
+ DBUsername=connection_kwargs.get("user"),
117
+ Region=region,
118
+ )
119
+ connection_kwargs["password"] = rds_token
120
+
121
+ for kwarg in ["autocommit", "connect_timeout", "port", "ssl_ca"]:
122
+ if not connection_kwargs[kwarg]:
123
+ del connection_kwargs[kwarg]
124
+
125
+ return {**super().build_connection_kwargs(), **connection_kwargs}
@@ -0,0 +1,3 @@
1
+ from clearskies_aws.cursors.port_forwarding.ssm import Ssm
2
+
3
+ __all__ = ["Ssm"]
@@ -0,0 +1,137 @@
1
+ import time
2
+
3
+ import clearskies.configs
4
+ from clearskies import decorators
5
+ from clearskies.cursors.port_forwarding.port_forwarder import PortForwarder
6
+
7
+ from clearskies_aws.di import inject
8
+
9
+
10
+ class Ssm(PortForwarder):
11
+ """
12
+ Port forwarder using AWS SSM Session Manager.
13
+
14
+ This class sets up a local port forwarding tunnel to a remote host using AWS SSM.
15
+ If instance_id is not provided, it will search for a running instance by Name tag.
16
+ """
17
+
18
+ """
19
+ The EC2 instance ID to connect to. If not provided, instance_name will be used to look up the instance.
20
+ """
21
+ instance_id = clearskies.configs.String(default=None)
22
+
23
+ """
24
+ The Name tag of the EC2 instance to search for if instance_id is not provided.
25
+ """
26
+ instance_name = clearskies.configs.String(default=None)
27
+
28
+ """
29
+ The remote port to forward to.
30
+ """
31
+ remote_port = clearskies.configs.Integer()
32
+
33
+ """
34
+ The local port to bind for the forwarding tunnel (default: 0, auto-selects a free port).
35
+ """
36
+ local_port = clearskies.configs.Integer(default=0)
37
+
38
+ """
39
+ AWS region.
40
+ """
41
+ region = clearskies.configs.String(default=None)
42
+
43
+ """
44
+ AWS CLI profile.
45
+ """
46
+ profile = clearskies.configs.String(default=None)
47
+
48
+ """
49
+ Boto3 session or client provider
50
+ """
51
+ boto3 = inject.Boto3()
52
+
53
+ @decorators.parameters_to_properties
54
+ def __init__(
55
+ self,
56
+ instance_id=None,
57
+ instance_name=None,
58
+ remote_port=None,
59
+ local_port=0,
60
+ region=None,
61
+ profile=None,
62
+ ):
63
+ self._proc = None
64
+ self.finalize_and_validate_configuration()
65
+
66
+ def setup(self, original_host: str, original_port: int) -> tuple[str, int]:
67
+ """
68
+ Establish the port forwarding tunnel and return the local endpoint.
69
+
70
+ If instance_id is not set, searches for a running instance by Name tag.
71
+
72
+ Returns:
73
+ A tuple containing the local host and local port to connect to (e.g., ("localhost", 12345)).
74
+ """
75
+ # Resolve instance_id if needed
76
+ if not self.instance_id and self.instance_name:
77
+ ec2_api = self.boto3.client("ec2", region_name=self.region)
78
+ running_instances = ec2_api.describe_instances(
79
+ Filters=[
80
+ {"Name": "tag:Name", "Values": [self.instance_name]},
81
+ {"Name": "instance-state-name", "Values": ["running"]},
82
+ ]
83
+ )
84
+ instance_ids = []
85
+ for reservation in running_instances["Reservations"]:
86
+ for instance in reservation["Instances"]:
87
+ instance_ids.append(instance["InstanceId"])
88
+ if len(instance_ids) == 0:
89
+ raise ValueError("Failed to launch SSM tunnel! Cannot find bastion!")
90
+ self.instance_id = instance_ids.pop()
91
+
92
+ if self.local_port == 0:
93
+ self.local_port = self.pick_free_port("127.0.0.1")
94
+
95
+ if self.is_port_open("127.0.0.1", self.local_port):
96
+ return "127.0.0.1", self.local_port
97
+
98
+ ssm_cmd = [
99
+ "aws",
100
+ "ssm",
101
+ "start-session",
102
+ "--target",
103
+ self.instance_id,
104
+ "--document-name",
105
+ "AWS-StartPortForwardingSession",
106
+ "--parameters",
107
+ f"portNumber={self.remote_port},localPort={self.local_port}",
108
+ ]
109
+ if self.region:
110
+ ssm_cmd += ["--region", self.region]
111
+ if self.profile:
112
+ ssm_cmd += ["--profile", self.profile]
113
+
114
+ self._proc = self.subprocess.Popen(ssm_cmd, stdout=self.subprocess.PIPE, stderr=self.subprocess.PIPE)
115
+
116
+ start = time.time()
117
+ while True:
118
+ try:
119
+ test_sock = self.socket.socket(self.socket.AF_INET, self.socket.SOCK_STREAM)
120
+ test_sock.settimeout(0.2)
121
+ test_sock.connect(("127.0.0.1", self.local_port))
122
+ test_sock.close()
123
+ break
124
+ except Exception:
125
+ if self._proc is not None and self._proc.poll() is not None:
126
+ raise RuntimeError("SSM process exited unexpectedly")
127
+ if time.time() - start > 10:
128
+ raise TimeoutError(f"Timeout waiting for port {self.local_port} to open")
129
+ time.sleep(0.1)
130
+
131
+ return "127.0.0.1", self.local_port
132
+
133
+ def teardown(self):
134
+ if self._proc:
135
+ self._proc.terminate()
136
+ self._proc.wait()
137
+ self._proc = None
@@ -17,7 +17,7 @@ class AwsAdditionalConfigAutoImport(AdditionalConfigAutoImport):
17
17
  This DI auto injects boto3, boto3 Session and the parameter store.
18
18
  """
19
19
 
20
- def provide_boto3(self) -> ModuleType:
20
+ def provide_boto3_sdk(self) -> ModuleType:
21
21
  import boto3
22
22
 
23
23
  return boto3
@@ -12,4 +12,4 @@ class Boto3(Injectable):
12
12
  def __get__(self, instance, parent) -> ModuleType:
13
13
  if instance is None:
14
14
  return self # type: ignore
15
- return self._di.build_from_name("boto3", cache=self.cache)
15
+ return self._di.build_from_name("boto3_sdk", cache=self.cache)
@@ -91,7 +91,7 @@ class SecretsManagerRotation(Endpoint):
91
91
  pending_secret_data = json.loads(pending_secret["SecretString"])
92
92
  except botocore.exceptions.ClientError as error:
93
93
  if error.response["Error"]["Code"] == "ResourceNotFoundException":
94
- pending_secret_data = None
94
+ pending_secret_data = {}
95
95
  else:
96
96
  raise error
97
97