clear-skies-aws 1.9.14__py3-none-any.whl → 1.9.15__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clear-skies-aws
3
- Version: 1.9.14
3
+ Version: 1.9.15
4
4
  Summary: clearskies bindings for working in AWS
5
5
  Home-page: https://github.com/cmancone/clearskies-aws
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  clearskies_aws/__init__.py,sha256=BZKL4SIyxx4MXpyP5hmwsMo2oJatyv5c2wjJOPzKBQ4,134
2
2
  clearskies_aws/actions/__init__.py,sha256=w_IWJg4UHV9Opv69zheH7ZHj1BnCzYLlm2JhFvHQCf8,2998
3
- clearskies_aws/actions/action_aws.py,sha256=hWYnYA0QNegWp2LDMYILs0Dk1TOsFykW5JgSEMwfDE8,3877
3
+ clearskies_aws/actions/action_aws.py,sha256=zBXsvhBDDm2dAU4MVlub84Ld1YNZ6ey8_zf4OeTe8go,4254
4
4
  clearskies_aws/actions/assume_role.py,sha256=tZHKMTQaImj_EAWormFZdIPkR_db7yBwOJxYaUyuGdA,4085
5
5
  clearskies_aws/actions/assume_role_test.py,sha256=MDMGePZLVyDNTjdAlGBDJzBlfMpGIpA3Q1Ur0qEPl1w,2450
6
6
  clearskies_aws/actions/ses.py,sha256=xJ0NEFPP-8kARPGjDv1yf_bhAiaIIM1mDzMxY22GE5E,7925
@@ -9,8 +9,8 @@ clearskies_aws/actions/sns.py,sha256=00E-eCQuq3Ygscyia928K8jX8rhDZrl5kyasM0st_uI
9
9
  clearskies_aws/actions/sns_test.py,sha256=iqlaZOA-0YHPOu52-XqpCIAgAv1JZodDdlm4YYYhj8U,2306
10
10
  clearskies_aws/actions/sqs.py,sha256=i-QyyFy-ImivXk-m-Bn9Mh5BF5qODthUyZAQVRsb8vs,3392
11
11
  clearskies_aws/actions/sqs_test.py,sha256=aazVN-bY6E17Pu3hDwLldj6YPirbqXjM6LfYFomUVmQ,4040
12
- clearskies_aws/actions/step_function.py,sha256=0Sz1CVVeKJi3IohtLnnNmhAbuxR7Gl9ic56ml0K3Qmg,2363
13
- clearskies_aws/actions/step_function_test.py,sha256=3xrNYFQ8fCe3CqPEnVnJsE0rIUlnnFez4rfPzphYVUU,2742
12
+ clearskies_aws/actions/step_function.py,sha256=wiDgGdOWdY0zVoClDsX08YFZqTR0bK3ydpyj0Qa7w_s,2599
13
+ clearskies_aws/actions/step_function_test.py,sha256=0gRYLDVRt2R-Cv-5Pr2ui4Gbp8rg9nPhQY4ERALg6qU,3837
14
14
  clearskies_aws/backends/__init__.py,sha256=kS6pmMKZuWzBefO7qQu1fkFdcXo180t76-a-pPc1YX8,83
15
15
  clearskies_aws/backends/dynamo_db_backend.py,sha256=Ng8IORbYVSh6Sj-mjpret3qmdSeI1U9t3GJ1uUdaGd4,29574
16
16
  clearskies_aws/backends/dynamo_db_backend_test.py,sha256=iAT8d5lOho8Kv70up7wkLuf2VJhdR7qdJ-TxHsupjQI,13150
@@ -61,7 +61,7 @@ clearskies_aws/secrets/parameter_store_test.py,sha256=UyqKE4AZYlldj9ww5f0fR15qsV
61
61
  clearskies_aws/secrets/secrets_manager.py,sha256=jlpfAFC23EeSpm50L8B-yrXg4IROQq-M_90zzXDp_ak,3056
62
62
  clearskies_aws/secrets/secrets_manager_test.py,sha256=mlNWtDm1wWS5C8aV0vJAzZVZB82KFR6NGRAPEkLtTyk,786
63
63
  clearskies_aws/web_socket_connection_model.py,sha256=d_Au_Pu7YXBfc7_lbuI7zz4MZ8ZOOwGM0oooppEofcI,1776
64
- clear_skies_aws-1.9.14.dist-info/LICENSE,sha256=3Ehd0g3YOpCj8sqj0Xjq5qbOtjjgk9qzhhD9YjRQgOA,1053
65
- clear_skies_aws-1.9.14.dist-info/METADATA,sha256=gPkZNsxHvCkVWlFvRQ14clUyY4qI7rACNt95gLHRbgA,8583
66
- clear_skies_aws-1.9.14.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
67
- clear_skies_aws-1.9.14.dist-info/RECORD,,
64
+ clear_skies_aws-1.9.15.dist-info/LICENSE,sha256=3Ehd0g3YOpCj8sqj0Xjq5qbOtjjgk9qzhhD9YjRQgOA,1053
65
+ clear_skies_aws-1.9.15.dist-info/METADATA,sha256=8HgfoQ9ZjijwkHbdR8y8NEwxrVBM71eIL4OU2gi5U1k,8583
66
+ clear_skies_aws-1.9.15.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
67
+ clear_skies_aws-1.9.15.dist-info/RECORD,,
@@ -62,9 +62,10 @@ class ActionAws(ABC):
62
62
  self._logging.exception(f"Failed to retrieve client for {self._name}")
63
63
  raise e
64
64
 
65
- def _getClient(self) -> boto3.client:
65
+ def _getClient(self, region=None) -> boto3.client:
66
66
  """Retrieve the boto3 client."""
67
- if self._client:
67
+ can_cache = not region
68
+ if self._client and can_cache:
68
69
  return self._client
69
70
 
70
71
  if self.assume_role:
@@ -72,12 +73,25 @@ class ActionAws(ABC):
72
73
  else:
73
74
  boto3 = self.boto3
74
75
 
75
- region = self.environment.get('AWS_REGION', silent=True)
76
+ if not region:
77
+ region = self.default_region()
76
78
  if region:
77
- self._client = boto3.client(self._name, region_name=region)
79
+ client = boto3.client(self._name, region_name=region)
78
80
  else:
79
- self._client = boto3.client(self._name)
80
- return self._client
81
+ client = boto3.client(self._name)
82
+
83
+ if can_cache:
84
+ self._client = client
85
+ return client
86
+
87
+ def default_region(self):
88
+ region = self.environment.get('AWS_REGION', silent=True)
89
+ if region:
90
+ return region
91
+ region = self.environment.get('DEFAULT_AWS_REGION', silent=True)
92
+ if region:
93
+ return region
94
+ return None
81
95
 
82
96
  def _execute_action(self, client: boto3.client, model: Models) -> None:
83
97
  """Run the action."""
@@ -45,6 +45,11 @@ class StepFunction(ActionAws):
45
45
 
46
46
  def _execute_action(self, client: ModuleType, model: Models) -> None:
47
47
  """Send a notification as configured."""
48
+ arn = self.get_arn(model)
49
+ default_region = self.default_region()
50
+ arn_region = arn.split(':')[3]
51
+ if default_region and default_region != arn_region:
52
+ client = self._getClient(region=arn_region)
48
53
  response = client.start_execution(
49
54
  stateMachineArn=self.get_arn(model),
50
55
  input=self.get_message_body(model),
@@ -30,7 +30,7 @@ class StepFunctionTest(unittest.TestCase):
30
30
  self.boto3.client = MagicMock(return_value=self.step_function)
31
31
  self.when = None
32
32
  self.environment = MagicMock()
33
- self.environment.get = MagicMock(return_value='us-east-1')
33
+ self.environment.get = MagicMock(return_value='us-east-2')
34
34
 
35
35
  def always(self, model):
36
36
  self.when = model
@@ -43,14 +43,14 @@ class StepFunctionTest(unittest.TestCase):
43
43
  def test_execute(self):
44
44
  step_function = StepFunction(self.environment, self.boto3, self.di)
45
45
  step_function.configure(
46
- arn='aws::arn::step/asdf-er',
46
+ arn='aws::arn:us-east-2:step/asdf-er',
47
47
  when=self.always,
48
48
  column_to_store_execution_arn="execution_arn",
49
49
  )
50
50
  step_function(self.user)
51
51
  self.step_function.start_execution.assert_has_calls([
52
52
  call(
53
- stateMachineArn='aws::arn::step/asdf-er',
53
+ stateMachineArn='aws::arn:us-east-2:step/asdf-er',
54
54
  input=json.dumps({
55
55
  "id": self.user.id,
56
56
  "email": self.user.email,
@@ -61,10 +61,36 @@ class StepFunctionTest(unittest.TestCase):
61
61
  self.assertEqual(id(self.user), id(self.when))
62
62
  self.assertEqual("aws:arn:execution", self.user.execution_arn)
63
63
 
64
+ def test_region_switch(self):
65
+ self.boto3.client.side_effect = [self.step_function, self.step_function]
66
+ step_function = StepFunction(self.environment, self.boto3, self.di)
67
+ step_function.configure(
68
+ arn='aws::arn:eu-west-1:step/asdf-er',
69
+ when=self.always,
70
+ column_to_store_execution_arn="execution_arn",
71
+ )
72
+ step_function(self.user)
73
+ self.step_function.start_execution.assert_has_calls([
74
+ call(
75
+ stateMachineArn='aws::arn:eu-west-1:step/asdf-er',
76
+ input=json.dumps({
77
+ "id": self.user.id,
78
+ "email": self.user.email,
79
+ "execution_arn": None,
80
+ }),
81
+ ),
82
+ ])
83
+ self.assertEqual(id(self.user), id(self.when))
84
+ self.assertEqual("aws:arn:execution", self.user.execution_arn)
85
+ self.boto3.client.assert_has_calls([
86
+ call("stepfunctions", region_name="us-east-2"),
87
+ call("stepfunctions", region_name="eu-west-1"),
88
+ ])
89
+
64
90
  def test_not_now(self):
65
91
  step_function = StepFunction(self.environment, self.boto3, self.di)
66
92
  step_function.configure(
67
- arn='arn::aws:step-function/asdf-er',
93
+ arn='aws::arn:us-east-2:step-function/asdf-er',
68
94
  when=self.never,
69
95
  )
70
96
  user = self.users.model({