Skip to content

Commit 8939523

Browse files
authoredMay 6, 2020
Misc builder script fixes & refactors (#31)
- Consolidate requirements to top-level - Add sts:GetParametersByPath to CircleCIExecutionRole - Minor refactor of config builder - Moved builder into 'scripts' subdirectory with its own requirements.txt
1 parent 6d318fb commit 8939523

File tree

11 files changed

+75
-28
lines changed

11 files changed

+75
-28
lines changed
 

‎CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Amplify CI support scripts - CHANGELOG
2+
3+
Scripts and tools for managing Amplify projects in continuous integration
4+
environments, and for local developer setup of integration test environments.
5+
6+
## 0.1.0
7+
8+
Initial release
9+

‎requirements.txt

+12
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1+
aws_cdk.aws_apigateway
2+
aws_cdk.aws_cognito
3+
aws_cdk.aws_iam
4+
aws_cdk.aws_kinesisfirehose
5+
aws_cdk.aws_kms
6+
aws_cdk.aws_logs
7+
aws_cdk.aws_pinpoint
8+
aws-cdk.aws_s3
9+
aws_cdk.aws_ssm
10+
aws_cdk.core
111
black
12+
boto3
13+
isort

‎src/integ_test_resources/android/sdk/integration/cdk/requirements.txt

-11
This file was deleted.

‎src/integ_test_resources/common/common_stack.py

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ def __init__(self,
2222
assumed_by=aws_iam.AccountPrincipal(self.account),
2323
max_session_duration=core.Duration.hours(4))
2424

25+
policy_to_add = aws_iam.PolicyStatement(effect=aws_iam.Effect.ALLOW,
26+
actions=[
27+
"ssm:GetParameter", "ssm:GetParametersByPath"
28+
],
29+
resources=["*"])
30+
circleci_execution_role.add_to_policy(policy_to_add)
31+
2532
self._circleci_execution_role = circleci_execution_role
2633
self._supported_in_region = True
2734
self._cognito_support_in_region = self.is_cognito_supported_in_region()

‎src/integ_test_resources/common/scripts/__init__.py

Whitespace-only changes.

‎src/integ_test_resources/common/device_config_builder.py ‎src/integ_test_resources/common/scripts/device_config_builder.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def get_parameters_with_prefix(self, parameter_prefix: str, ssm) -> dict:
8787
for parameter in page['Parameters']:
8888
parameters.append(parameter)
8989
return parameters
90-
90+
9191
def ssm_client(self, aws_config: AWSConfig):
9292
"""
9393
Builds an SSM client using the provided Config.
@@ -99,21 +99,21 @@ def ssm_client(self, aws_config: AWSConfig):
9999
region_name=aws_config.defaultRegion
100100
)
101101
return session.client('ssm')
102-
102+
103103
def aws_config_from_environment(self) -> AWSConfig:
104104
"""
105105
Inpsects the environment for four well-known AWS environment
106106
variables, and populates their value into an Config bundle.
107-
107+
108108
These credentials are used for two purposes:
109109
1. To call get-parameters-by-path against SSM, to understand
110110
the resource outputs of the various CDK scripts;
111111
2. For the execution of the test suites themselves, on the device.
112-
112+
113113
As a consequence, these credentials must have permissions
114114
sufficient to read data out of SSM Parameter Store, as well as
115115
to execute all of the various test suites, both.
116-
116+
117117
The default region is used only while talking to SSM. The
118118
provided region should be the same as what was used while
119119
running the CDK scripts.
@@ -124,7 +124,24 @@ def aws_config_from_environment(self) -> AWSConfig:
124124
os.environ['AWS_SESSION_TOKEN'],
125125
os.environ['AWS_DEFAULT_REGION']
126126
)
127-
127+
128+
def get_package_data(self) -> dict:
129+
aws_config = self.aws_config_from_environment()
130+
parameter_prefix = self.STACK_PREFIX_BASE + '/' + self.platform
131+
ssm = self.ssm_client(aws_config)
132+
parameters = self.get_parameters_with_prefix(parameter_prefix, ssm)
133+
package_data = self.build_package_data(parameter_prefix, parameters)
134+
return package_data
135+
136+
def get_credentials_data(self) -> dict:
137+
aws_config = self.aws_config_from_environment()
138+
credentials_data = {
139+
'accessKey': aws_config.accessKey,
140+
'secretKey': aws_config.secretKey,
141+
'sessionToken': aws_config.sessionToken
142+
}
143+
return credentials_data
144+
128145
def print_device_config(self) -> None:
129146
"""
130147
Obtains credentials from the environment (only). Builds a Simple
@@ -136,17 +153,10 @@ def print_device_config(self) -> None:
136153
device running the SDK integration tests. The output of this
137154
function may be piped to a file.
138155
"""
139-
aws_config = self.aws_config_from_environment()
140-
parameter_prefix = self.STACK_PREFIX_BASE + '/' + self.platform
141-
ssm = self.ssm_client(aws_config)
142-
parameters = self.get_parameters_with_prefix(parameter_prefix, ssm)
143-
package_data = self.build_package_data(parameter_prefix, parameters)
156+
package_data = self.get_package_data()
157+
credentials_data = self.get_credentials_data()
144158
print(json.dumps({
145-
'credentials': {
146-
'accessKey': aws_config.accessKey,
147-
'secretKey': aws_config.secretKey,
148-
'sessionToken': aws_config.sessionToken
149-
},
159+
'credentials': credentials_data,
150160
'packages': package_data
151161
}, indent=2))
152162

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
boto3

‎src/integ_test_resources/common/scripts/test/__init__.py

Whitespace-only changes.

‎src/integ_test_resources/common/test/device_config_builder_test.py ‎src/integ_test_resources/common/scripts/test/device_config_builder_test.py

+20
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ def test_build_package_data_with_nesting(self):
6868
)
6969

7070

71+
def test_get_credential_data(self):
72+
environment_variables = {
73+
'AWS_ACCESS_KEY_ID': 'accessKey',
74+
'AWS_SECRET_ACCESS_KEY': 'secretKey',
75+
'AWS_SESSION_TOKEN': 'sessionToken'
76+
}
77+
for key, value in environment_variables.items():
78+
os.environ[key] = value
79+
80+
credentials_data = self.underTest.get_credentials_data()
81+
82+
self.assertEqual(
83+
{
84+
'accessKey': 'accessKey',
85+
'secretKey': 'secretKey',
86+
'sessionToken': 'sessionToken'
87+
},
88+
credentials_data
89+
)
90+
7191
def test_aws_config_from_environment(self):
7292
environment_variables = {
7393
'AWS_ACCESS_KEY_ID': 'accessKey',

‎src/integ_test_resources/ios/sdk/integration/cdk/requirements.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.