boto3-assist 0.12.0__tar.gz → 0.13.0__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.
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/PKG-INFO +1 -1
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/pyproject.toml +1 -1
- boto3_assist-0.13.0/src/boto3_assist/boto3session.py +87 -0
- boto3_assist-0.13.0/src/boto3_assist/role_assumption_mixin.py +38 -0
- boto3_assist-0.13.0/src/boto3_assist/session_setup_mixin.py +29 -0
- boto3_assist-0.13.0/src/boto3_assist/version.py +1 -0
- boto3_assist-0.12.0/src/boto3_assist/boto3session.py +0 -190
- boto3_assist-0.12.0/src/boto3_assist/version.py +0 -1
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/.env.docker +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/.env.docker.001 +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/.env.docker.nosql.workbench +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/.env.unittest +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/.gitignore +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/.vscode/launch.json +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/.vscode/settings.json +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/.vscode/tasks.json +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/LICENSE-EXPLAINED.txt +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/LICENSE.txt +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/README.md +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/aws_regions_with_status.csv +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/aws_regions_with_status.json +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/devops/build.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/devops/readme.md +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/cloudwatch/log_report.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/models/order_item_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/models/order_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/models/product_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/models/user_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/models/user_post_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/order_example/main.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/order_example/products.json +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/order_item_service.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/order_service.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/product_service.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/table_service.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/user_post_service.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/user_service.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/user_service_client_example.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/user_service_resource_example.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/user_post_example/main.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/ec2/regions_report.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/module-headers.txt +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/mypy.ini +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/requirements-dev.txt +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/requirements.txt +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/run-checks.sh +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/run_unit_tests.sh +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/aws_lambda/event_info.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/aws_lambda/mock_context.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cloudwatch/cloudwatch_connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cloudwatch/cloudwatch_connection_tracker.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cloudwatch/cloudwatch_log_connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cloudwatch/cloudwatch_logs.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cloudwatch/cloudwatch_query.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cognito/cognito_authorizer.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cognito/cognito_connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cognito/cognito_utility.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cognito/jwks_cache.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cognito/user.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/connection_tracker.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_helpers.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_importer.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_index.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_iservice.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_key.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_model_base.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_model_base_interfaces.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_reindexer.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_reserved_words.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_reserved_words.txt +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/readme.md +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/troubleshooting.md +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/ec2/ec2_connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/environment_services/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/environment_services/environment_loader.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/environment_services/environment_variables.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/errors/custom_exceptions.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/http_status_codes.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/models/serializable_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/s3/s3.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/s3/s3_bucket.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/s3/s3_connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/s3/s3_event_data.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/s3/s3_object.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/securityhub/securityhub.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/securityhub/securityhub_connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/ssm/connection.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/ssm/parameter_store/parameter_store.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/datetime_utility.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/dictionary_utility.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/file_operations.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/http_utility.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/logging_utility.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/numbers_utility.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/serialization_utility.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/string_utility.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/integration/cross_account_connection_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/integration/tenant.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/integration/tenant_services.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/cms/base.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/cms/content_block.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/cms/page.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/cms/template.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/simple_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/user_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/user_required_fields_model.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dynamodb_model_base_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dynamodb_model_projections_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dynamodb_model_serializtion_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dynamodb_moto_sorting_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dynamodb_reindex_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/examples_test/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/examples_test/user_service_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/lambda_tests/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/lambda_tests/event_info_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/models_tests/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/models_tests/models/person.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/models_tests/models/user.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/models_tests/serializable_model_person_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/models_tests/serializable_model_user_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/models_tests/serializable_model_wide_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/parameter_store/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/parameter_store/parameter_store_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/s3/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/s3/files/test.txt +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/s3/s3_event_data_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/s3/s3_file_delete_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/s3/s3_file_upload_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/utilities/__init__.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/utilities/serialization_utility_test.py +0 -0
- {boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/utilities/string_utility_test.py +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Geek Cafe, LLC
|
|
3
|
+
Maintainers: Eric Wilson
|
|
4
|
+
MIT License. See Project Root for the license information.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Optional, List, Any
|
|
8
|
+
import boto3
|
|
9
|
+
from botocore.config import Config
|
|
10
|
+
from .session_setup_mixin import SessionSetupMixin
|
|
11
|
+
from .role_assumption_mixin import RoleAssumptionMixin
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Boto3SessionManager(SessionSetupMixin, RoleAssumptionMixin):
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
service_name: str,
|
|
18
|
+
*,
|
|
19
|
+
aws_profile: Optional[str] = None,
|
|
20
|
+
aws_region: Optional[str] = None,
|
|
21
|
+
assume_role_arn: Optional[str] = None,
|
|
22
|
+
assume_role_chain: Optional[List[str]] = None,
|
|
23
|
+
assume_role_session_name: Optional[str] = None,
|
|
24
|
+
assume_role_duration_seconds: Optional[int] = 3600,
|
|
25
|
+
config: Optional[Config] = None,
|
|
26
|
+
aws_endpoint_url: Optional[str] = None,
|
|
27
|
+
aws_access_key_id: Optional[str] = None,
|
|
28
|
+
aws_secret_access_key: Optional[str] = None,
|
|
29
|
+
aws_session_token: Optional[str] = None,
|
|
30
|
+
):
|
|
31
|
+
self.service_name = service_name
|
|
32
|
+
self.aws_profile = aws_profile
|
|
33
|
+
self.aws_region = aws_region
|
|
34
|
+
self.config = config
|
|
35
|
+
self.endpoint_url = aws_endpoint_url
|
|
36
|
+
self.assume_role_chain = assume_role_chain or (
|
|
37
|
+
[assume_role_arn] if assume_role_arn else []
|
|
38
|
+
)
|
|
39
|
+
self.assume_role_session_name = (
|
|
40
|
+
assume_role_session_name or f"AssumeRoleSessionFor{service_name}"
|
|
41
|
+
)
|
|
42
|
+
self.assume_role_duration_seconds = assume_role_duration_seconds
|
|
43
|
+
self.aws_access_key_id = aws_access_key_id
|
|
44
|
+
self.aws_secret_access_key = aws_secret_access_key
|
|
45
|
+
self.aws_session_token = aws_session_token
|
|
46
|
+
|
|
47
|
+
self.__session: Optional[boto3.Session] = None
|
|
48
|
+
self.__client: Any = None
|
|
49
|
+
self.__resource: Any = None
|
|
50
|
+
|
|
51
|
+
self.__initialize()
|
|
52
|
+
|
|
53
|
+
def __initialize(self):
|
|
54
|
+
base_session = self._create_base_session(
|
|
55
|
+
self.aws_profile,
|
|
56
|
+
self.aws_region,
|
|
57
|
+
self.aws_access_key_id,
|
|
58
|
+
self.aws_secret_access_key,
|
|
59
|
+
self.aws_session_token,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
if self.assume_role_chain:
|
|
63
|
+
self.__session = self._assume_roles_in_chain(
|
|
64
|
+
base_session,
|
|
65
|
+
self.assume_role_chain,
|
|
66
|
+
self.assume_role_session_name,
|
|
67
|
+
self.assume_role_duration_seconds,
|
|
68
|
+
self.aws_region,
|
|
69
|
+
)
|
|
70
|
+
else:
|
|
71
|
+
self.__session = base_session
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def client(self) -> Any:
|
|
75
|
+
if not self.__client:
|
|
76
|
+
self.__client = self.__session.client(
|
|
77
|
+
self.service_name, config=self.config, endpoint_url=self.endpoint_url
|
|
78
|
+
)
|
|
79
|
+
return self.__client
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def resource(self) -> Any:
|
|
83
|
+
if not self.__resource:
|
|
84
|
+
self.__resource = self.__session.resource(
|
|
85
|
+
self.service_name, config=self.config, endpoint_url=self.endpoint_url
|
|
86
|
+
)
|
|
87
|
+
return self.__resource
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Geek Cafe, LLC
|
|
3
|
+
Maintainers: Eric Wilson
|
|
4
|
+
MIT License. See Project Root for the license information.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import boto3
|
|
8
|
+
from typing import List
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RoleAssumptionMixin:
|
|
12
|
+
def _assume_roles_in_chain(
|
|
13
|
+
self,
|
|
14
|
+
base_session: boto3.Session,
|
|
15
|
+
role_chain: List[str],
|
|
16
|
+
session_name: str,
|
|
17
|
+
duration_seconds: int,
|
|
18
|
+
region: str,
|
|
19
|
+
) -> boto3.Session:
|
|
20
|
+
session = base_session
|
|
21
|
+
|
|
22
|
+
for role_arn in role_chain:
|
|
23
|
+
sts_client = session.client("sts")
|
|
24
|
+
response = sts_client.assume_role(
|
|
25
|
+
RoleArn=role_arn,
|
|
26
|
+
RoleSessionName=session_name,
|
|
27
|
+
DurationSeconds=duration_seconds,
|
|
28
|
+
)
|
|
29
|
+
creds = response["Credentials"]
|
|
30
|
+
|
|
31
|
+
session = boto3.Session(
|
|
32
|
+
aws_access_key_id=creds["AccessKeyId"],
|
|
33
|
+
aws_secret_access_key=creds["SecretAccessKey"],
|
|
34
|
+
aws_session_token=creds["SessionToken"],
|
|
35
|
+
region_name=region,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return session
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Geek Cafe, LLC
|
|
3
|
+
Maintainers: Eric Wilson
|
|
4
|
+
MIT License. See Project Root for the license information.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import boto3
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SessionSetupMixin:
|
|
12
|
+
def _create_base_session(
|
|
13
|
+
self,
|
|
14
|
+
aws_profile: Optional[str],
|
|
15
|
+
aws_region: Optional[str],
|
|
16
|
+
aws_access_key_id: Optional[str],
|
|
17
|
+
aws_secret_access_key: Optional[str],
|
|
18
|
+
aws_session_token: Optional[str],
|
|
19
|
+
) -> boto3.Session:
|
|
20
|
+
try:
|
|
21
|
+
return boto3.Session(
|
|
22
|
+
profile_name=aws_profile,
|
|
23
|
+
region_name=aws_region,
|
|
24
|
+
aws_access_key_id=aws_access_key_id,
|
|
25
|
+
aws_secret_access_key=aws_secret_access_key,
|
|
26
|
+
aws_session_token=aws_session_token,
|
|
27
|
+
)
|
|
28
|
+
except Exception as e:
|
|
29
|
+
raise RuntimeError(f"Failed to create boto3 session: {e}") from e
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.13.0'
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Geek Cafe, LLC
|
|
3
|
-
Maintainers: Eric Wilson
|
|
4
|
-
MIT License. See Project Root for the license information.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from typing import Any, Optional
|
|
8
|
-
|
|
9
|
-
import boto3
|
|
10
|
-
from aws_lambda_powertools import Logger
|
|
11
|
-
from botocore.config import Config
|
|
12
|
-
from botocore.exceptions import ProfileNotFound
|
|
13
|
-
from boto3_assist.environment_services.environment_variables import EnvironmentVariables
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
logger = Logger(__name__)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class Boto3SessionManager:
|
|
20
|
-
"""Manages Boto3 Sessions"""
|
|
21
|
-
|
|
22
|
-
def __init__(
|
|
23
|
-
self,
|
|
24
|
-
service_name: str,
|
|
25
|
-
*,
|
|
26
|
-
aws_profile: Optional[str] = None,
|
|
27
|
-
aws_region: Optional[str] = None,
|
|
28
|
-
assume_role_arn: Optional[str] = None,
|
|
29
|
-
assume_role_session_name: Optional[str] = None,
|
|
30
|
-
# cross_account_role_arn: Optional[str] = None,
|
|
31
|
-
config: Optional[Config] = None,
|
|
32
|
-
aws_endpoint_url: Optional[str] = None,
|
|
33
|
-
aws_access_key_id: Optional[str] = None,
|
|
34
|
-
aws_secret_access_key: Optional[str] = None,
|
|
35
|
-
aws_session_token: Optional[str] = None,
|
|
36
|
-
):
|
|
37
|
-
self.service_name = service_name
|
|
38
|
-
self.aws_profile = aws_profile
|
|
39
|
-
self.aws_region = aws_region
|
|
40
|
-
self.assume_role_arn = assume_role_arn
|
|
41
|
-
self.assume_role_session_name = assume_role_session_name
|
|
42
|
-
self.config = config
|
|
43
|
-
# # self.cross_account_role_arn = cross_account_role_arn
|
|
44
|
-
self.endpoint_url = aws_endpoint_url
|
|
45
|
-
self.aws_access_key_id = aws_access_key_id
|
|
46
|
-
self.aws_secret_access_key = aws_secret_access_key
|
|
47
|
-
self.aws_session_token = aws_session_token
|
|
48
|
-
|
|
49
|
-
self.__session: Any = None
|
|
50
|
-
self.__client: Any = None
|
|
51
|
-
self.__resource: Any = None
|
|
52
|
-
|
|
53
|
-
self.__setup()
|
|
54
|
-
|
|
55
|
-
def __setup(self):
|
|
56
|
-
"""Setup AWS session, client, and resource."""
|
|
57
|
-
|
|
58
|
-
profile = self.aws_profile or EnvironmentVariables.AWS.profile()
|
|
59
|
-
region = self.aws_region or EnvironmentVariables.AWS.region()
|
|
60
|
-
|
|
61
|
-
logger.debug("Connecting without assuming a role.")
|
|
62
|
-
self.__session = self.__get_aws_session(profile, region)
|
|
63
|
-
|
|
64
|
-
if profile:
|
|
65
|
-
print(f"Connecting with a profile: {profile}")
|
|
66
|
-
|
|
67
|
-
if self.assume_role_arn:
|
|
68
|
-
self.__assume_role()
|
|
69
|
-
|
|
70
|
-
def __assume_role(self):
|
|
71
|
-
"""Assume an AWS IAM role."""
|
|
72
|
-
try:
|
|
73
|
-
if not self.__session:
|
|
74
|
-
raise RuntimeError(
|
|
75
|
-
"Session must be established before assuming a role."
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
logger.debug(f"Assuming role {self.assume_role_arn}")
|
|
79
|
-
|
|
80
|
-
sts_client = self.__session.client("sts")
|
|
81
|
-
session_name = (
|
|
82
|
-
self.assume_role_session_name
|
|
83
|
-
or f"AssumeRoleSessionFor{self.service_name}"
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
assumed_role_response = sts_client.assume_role(
|
|
87
|
-
RoleArn=self.assume_role_arn,
|
|
88
|
-
RoleSessionName=session_name,
|
|
89
|
-
)
|
|
90
|
-
credentials = assumed_role_response["Credentials"]
|
|
91
|
-
|
|
92
|
-
# Now override the session with assumed credentials
|
|
93
|
-
self.__session = boto3.Session(
|
|
94
|
-
aws_access_key_id=credentials["AccessKeyId"],
|
|
95
|
-
aws_secret_access_key=credentials["SecretAccessKey"],
|
|
96
|
-
aws_session_token=credentials["SessionToken"],
|
|
97
|
-
region_name=self.aws_region,
|
|
98
|
-
)
|
|
99
|
-
logger.debug("Successfully assumed role and created new session.")
|
|
100
|
-
|
|
101
|
-
except Exception as e:
|
|
102
|
-
logger.error(f"Error assuming role: {e}")
|
|
103
|
-
raise RuntimeError(f"Failed to assume role {self.assume_role_arn}") from e
|
|
104
|
-
|
|
105
|
-
def __get_aws_session(
|
|
106
|
-
self, aws_profile: Optional[str] = None, aws_region: Optional[str] = None
|
|
107
|
-
) -> boto3.Session | None:
|
|
108
|
-
"""Get a boto3 session for AWS."""
|
|
109
|
-
logger.debug({"profile": aws_profile, "region": aws_region})
|
|
110
|
-
try:
|
|
111
|
-
self.aws_profile = aws_profile or EnvironmentVariables.AWS.profile()
|
|
112
|
-
self.aws_region = aws_region or EnvironmentVariables.AWS.region()
|
|
113
|
-
tmp_access_key_id = self.aws_access_key_id
|
|
114
|
-
tmp_secret_access_key = self.aws_secret_access_key
|
|
115
|
-
if not EnvironmentVariables.AWS.display_aws_access_key_id():
|
|
116
|
-
tmp_access_key_id = (
|
|
117
|
-
"None" if tmp_access_key_id is None else "***************"
|
|
118
|
-
)
|
|
119
|
-
if not EnvironmentVariables.AWS.display_aws_secret_access_key():
|
|
120
|
-
tmp_secret_access_key = (
|
|
121
|
-
"None" if tmp_secret_access_key is None else "***************"
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
logger.debug(
|
|
125
|
-
{
|
|
126
|
-
"profile": self.aws_profile,
|
|
127
|
-
"region": self.aws_region,
|
|
128
|
-
"aws_access_key_id": tmp_access_key_id,
|
|
129
|
-
"aws_secret_access_key": tmp_secret_access_key,
|
|
130
|
-
"aws_session_token": (
|
|
131
|
-
"*******" if self.aws_session_token is not None else ""
|
|
132
|
-
),
|
|
133
|
-
}
|
|
134
|
-
)
|
|
135
|
-
logger.debug("Creating boto3 session")
|
|
136
|
-
session = self.__create_boto3_session()
|
|
137
|
-
# if self.aws_profile or self.aws_region
|
|
138
|
-
# else boto3.Session()
|
|
139
|
-
|
|
140
|
-
except Exception as e:
|
|
141
|
-
logger.error(e)
|
|
142
|
-
raise RuntimeError("Failed to create a boto3 session.") from e
|
|
143
|
-
|
|
144
|
-
logger.debug({"session": session})
|
|
145
|
-
return session
|
|
146
|
-
|
|
147
|
-
@property
|
|
148
|
-
def client(self) -> Any:
|
|
149
|
-
"""Return the boto3 client connection."""
|
|
150
|
-
if not self.__client:
|
|
151
|
-
logger.debug(f"Creating {self.service_name} client")
|
|
152
|
-
self.__client = self.__session.client(
|
|
153
|
-
self.service_name,
|
|
154
|
-
config=self.config,
|
|
155
|
-
endpoint_url=self.endpoint_url,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
return self.__client
|
|
159
|
-
|
|
160
|
-
@property
|
|
161
|
-
def resource(self) -> Any:
|
|
162
|
-
"""Return the boto3 resource connection."""
|
|
163
|
-
if not self.__resource:
|
|
164
|
-
logger.debug(f"Creating {self.service_name} resource")
|
|
165
|
-
self.__resource = self.__session.resource(
|
|
166
|
-
self.service_name,
|
|
167
|
-
config=self.config,
|
|
168
|
-
endpoint_url=self.endpoint_url,
|
|
169
|
-
)
|
|
170
|
-
return self.__resource
|
|
171
|
-
|
|
172
|
-
def __create_boto3_session(self) -> boto3.Session | None:
|
|
173
|
-
try:
|
|
174
|
-
logger.debug(f"Creating session for {self.service_name}")
|
|
175
|
-
session = boto3.Session(
|
|
176
|
-
profile_name=self.aws_profile,
|
|
177
|
-
region_name=self.aws_region,
|
|
178
|
-
aws_access_key_id=self.aws_access_key_id,
|
|
179
|
-
aws_secret_access_key=self.aws_secret_access_key,
|
|
180
|
-
aws_session_token=self.aws_session_token,
|
|
181
|
-
)
|
|
182
|
-
return session
|
|
183
|
-
except ProfileNotFound as e:
|
|
184
|
-
print(
|
|
185
|
-
f"An error occurred setting up the boto3 sessions. Profile not found: {e}"
|
|
186
|
-
)
|
|
187
|
-
raise e
|
|
188
|
-
except Exception as e:
|
|
189
|
-
print(f"An error occurred setting up the boto3 sessions: {e}")
|
|
190
|
-
raise e
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.12.0'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/examples/dynamodb/services/order_item_service.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cloudwatch/cloudwatch_connection.py
RENAMED
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/cloudwatch/cloudwatch_log_connection.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_connection.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_model_base.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_reserved_words.py
RENAMED
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/dynamodb/dynamodb_reserved_words.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/environment_services/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/securityhub/securityhub_connection.py
RENAMED
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/ssm/parameter_store/parameter_store.py
RENAMED
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/dictionary_utility.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/src/boto3_assist/utilities/serialization_utility.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/integration/cross_account_connection_test.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/cms/content_block.py
RENAMED
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/cms/template.py
RENAMED
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/simple_model.py
RENAMED
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dbmodels/user_model.py
RENAMED
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dynamodb_model_base_test.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dynamodb_moto_sorting_test.py
RENAMED
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/dynamodb_tests/dynamodb_reindex_test.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/models_tests/serializable_model_user_test.py
RENAMED
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/models_tests/serializable_model_wide_test.py
RENAMED
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/parameter_store/parameter_store_test.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.12.0 → boto3_assist-0.13.0}/tests/unit/utilities/serialization_utility_test.py
RENAMED
|
File without changes
|
|
File without changes
|