-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: Support new CodeDeploy ManagedPolicy #1858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ class RegionConfiguration(object): | |
class abstracts all region/partition specific configuration. | ||
""" | ||
|
||
partitions = {"govcloud": "aws-us-gov", "china": "aws-cn"} | ||
|
||
@classmethod | ||
def is_apigw_edge_configuration_supported(cls): | ||
""" | ||
|
@@ -18,4 +16,9 @@ def is_apigw_edge_configuration_supported(cls): | |
:return: True, if API Gateway does not support Edge configuration | ||
""" | ||
|
||
return ArnGenerator.get_partition_name() not in [cls.partitions["govcloud"], cls.partitions["china"]] | ||
return ArnGenerator.get_partition_name() not in [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: Looks like the list can be replaced by cls.partitions.values(), so we don't change two places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for using it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes indeed, I removed my comment :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Not sure why this is defined this way in general. Will simplify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was no need for the dictionary that I could find. So I just pushed everything into the |
||
"aws-us-gov", | ||
"aws-iso", | ||
"aws-iso-b", | ||
"aws-cn", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from unittest import TestCase | ||
|
||
from mock import patch | ||
from parameterized import parameterized | ||
|
||
from samtranslator.model.preferences.deployment_preference_collection import DeploymentPreferenceCollection | ||
|
||
|
||
class TestDeploymentPreferenceCollection(TestCase): | ||
@parameterized.expand( | ||
[ | ||
["aws-iso"], | ||
["aws-iso-b"], | ||
] | ||
) | ||
def test_codedeploy_iam_role_contains_AWSCodeDeployRoleForLambdaLimited_managedpolicy(self, partition): | ||
|
||
with patch( | ||
"samtranslator.translator.arn_generator.ArnGenerator.get_partition_name" | ||
) as get_partition_name_patch: | ||
get_partition_name_patch.return_value = partition | ||
|
||
iam_role = DeploymentPreferenceCollection().codedeploy_iam_role | ||
|
||
self.assertIn( | ||
"arn:{}:iam::aws:policy/service-role/AWSCodeDeployRoleForLambdaLimited".format(partition), | ||
iam_role.ManagedPolicyArns, | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
["aws"], | ||
["aws-cn"], | ||
["aws-us-gov"], | ||
] | ||
) | ||
def test_codedeploy_iam_role_contains_AWSCodeDeployRoleForLambda_managedpolicy(self, partition): | ||
|
||
with patch( | ||
"samtranslator.translator.arn_generator.ArnGenerator.get_partition_name" | ||
) as get_partition_name_patch: | ||
get_partition_name_patch.return_value = partition | ||
|
||
iam_role = DeploymentPreferenceCollection().codedeploy_iam_role | ||
|
||
self.assertIn( | ||
"arn:{}:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda".format(partition), | ||
iam_role.ManagedPolicyArns, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest import TestCase | ||
|
||
from mock import patch | ||
from parameterized import parameterized | ||
|
||
from samtranslator.region_configuration import RegionConfiguration | ||
|
||
|
||
class TestRegionConfiguration(TestCase): | ||
@parameterized.expand( | ||
[ | ||
["aws"], | ||
] | ||
) | ||
def test_when_apigw_edge_configuration_supported(self, partition): | ||
|
||
with patch( | ||
"samtranslator.translator.arn_generator.ArnGenerator.get_partition_name" | ||
) as get_partition_name_patch: | ||
get_partition_name_patch.return_value = partition | ||
|
||
self.assertTrue(RegionConfiguration.is_apigw_edge_configuration_supported()) | ||
|
||
@parameterized.expand( | ||
[ | ||
["aws-cn"], | ||
["aws-us-gov"], | ||
["aws-iso"], | ||
["aws-iso-b"], | ||
] | ||
) | ||
def test_when_apigw_edge_configuration_is_not_supported(self, partition): | ||
with patch( | ||
"samtranslator.translator.arn_generator.ArnGenerator.get_partition_name" | ||
) as get_partition_name_patch: | ||
get_partition_name_patch.return_value = partition | ||
|
||
self.assertFalse(RegionConfiguration.is_apigw_edge_configuration_supported()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from unittest import TestCase | ||
|
||
from mock import patch | ||
from parameterized import parameterized | ||
|
||
from samtranslator.translator.arn_generator import ArnGenerator | ||
|
||
|
||
class TestArnGenerator(TestCase): | ||
@parameterized.expand( | ||
[ | ||
["us-east-1", "aws"], | ||
["eu-west-1", "aws"], | ||
["cn-north-1", "aws-cn"], | ||
["us-gov-west-1", "aws-us-gov"], | ||
["us-iso-east-1", "aws-iso"], | ||
["us-isob-east-1", "aws-iso-b"], | ||
] | ||
) | ||
def test_get_partition_name(self, region, expected_partition): | ||
self.assertEqual(expected_partition, ArnGenerator.get_partition_name(region=region)) | ||
|
||
@parameterized.expand( | ||
[ | ||
["us-east-1", "aws"], | ||
["eu-west-1", "aws"], | ||
["cn-north-1", "aws-cn"], | ||
["us-gov-west-1", "aws-us-gov"], | ||
["us-iso-east-1", "aws-iso"], | ||
["us-isob-east-1", "aws-iso-b"], | ||
] | ||
) | ||
def test_get_partition_name_when_region_not_provided(self, region, expected_partition): | ||
with patch("boto3.session.Session.region_name", region): | ||
self.assertEqual(expected_partition, ArnGenerator.get_partition_name()) |
Uh oh!
There was an error while loading. Please reload this page.