Refactor ARNs to remove hardcoded account id (#3701)
This commit is contained in:
parent
afdab66218
commit
6f1eae6f02
@ -2,8 +2,9 @@ import weakref
|
|||||||
|
|
||||||
from boto3 import Session
|
from boto3 import Session
|
||||||
|
|
||||||
from moto.core import BaseBackend, BaseModel
|
from moto.core import BaseBackend, BaseModel, ACCOUNT_ID
|
||||||
from .exceptions import InvalidParameterValueError, ResourceNotFoundException
|
from .exceptions import InvalidParameterValueError, ResourceNotFoundException
|
||||||
|
from .utils import make_arn
|
||||||
|
|
||||||
|
|
||||||
class FakeEnvironment(BaseModel):
|
class FakeEnvironment(BaseModel):
|
||||||
@ -23,15 +24,8 @@ class FakeEnvironment(BaseModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def environment_arn(self):
|
def environment_arn(self):
|
||||||
return (
|
resource_path = "%s/%s" % (self.application_name, self.environment_name)
|
||||||
"arn:aws:elasticbeanstalk:{region}:{account_id}:"
|
return make_arn(self.region, ACCOUNT_ID, "environment", resource_path)
|
||||||
"environment/{application_name}/{environment_name}".format(
|
|
||||||
region=self.region,
|
|
||||||
account_id="123456789012",
|
|
||||||
application_name=self.application_name,
|
|
||||||
environment_name=self.environment_name,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def platform_arn(self):
|
def platform_arn(self):
|
||||||
@ -68,6 +62,10 @@ class FakeApplication(BaseModel):
|
|||||||
def region(self):
|
def region(self):
|
||||||
return self.backend.region
|
return self.backend.region
|
||||||
|
|
||||||
|
@property
|
||||||
|
def arn(self):
|
||||||
|
return make_arn(self.region, ACCOUNT_ID, "application", self.application_name)
|
||||||
|
|
||||||
|
|
||||||
class EBBackend(BaseBackend):
|
class EBBackend(BaseBackend):
|
||||||
def __init__(self, region):
|
def __init__(self, region):
|
||||||
|
@ -91,7 +91,7 @@ EB_CREATE_APPLICATION = """
|
|||||||
</MaxCountRule>
|
</MaxCountRule>
|
||||||
</VersionLifecycleConfig>
|
</VersionLifecycleConfig>
|
||||||
</ResourceLifecycleConfig>
|
</ResourceLifecycleConfig>
|
||||||
<ApplicationArn>arn:aws:elasticbeanstalk:{{ region_name }}:111122223333:application/{{ application.application_name }}</ApplicationArn>
|
<ApplicationArn>{{ application.arn }}</ApplicationArn>
|
||||||
<ApplicationName>{{ application.application_name }}</ApplicationName>
|
<ApplicationName>{{ application.application_name }}</ApplicationName>
|
||||||
<DateUpdated>2019-09-03T13:08:29.049Z</DateUpdated>
|
<DateUpdated>2019-09-03T13:08:29.049Z</DateUpdated>
|
||||||
</Application>
|
</Application>
|
||||||
@ -125,7 +125,7 @@ EB_DESCRIBE_APPLICATIONS = """
|
|||||||
</MaxCountRule>
|
</MaxCountRule>
|
||||||
</VersionLifecycleConfig>
|
</VersionLifecycleConfig>
|
||||||
</ResourceLifecycleConfig>
|
</ResourceLifecycleConfig>
|
||||||
<ApplicationArn>arn:aws:elasticbeanstalk:{{ region_name }}:111122223333:application/{{ application.application_name }}</ApplicationArn>
|
<ApplicationArn>{{ application.arn }}</ApplicationArn>
|
||||||
<ApplicationName>{{ application.application_name }}</ApplicationName>
|
<ApplicationName>{{ application.application_name }}</ApplicationName>
|
||||||
<DateUpdated>2019-09-03T13:08:29.049Z</DateUpdated>
|
<DateUpdated>2019-09-03T13:08:29.049Z</DateUpdated>
|
||||||
</member>
|
</member>
|
||||||
|
11
moto/elasticbeanstalk/utils.py
Normal file
11
moto/elasticbeanstalk/utils.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
def make_arn(region, account_id, resource_type, resource_path):
|
||||||
|
arn_template = (
|
||||||
|
"arn:aws:elasticbeanstalk:{region}:{account_id}:{resource_type}/{resource_path}"
|
||||||
|
)
|
||||||
|
arn = arn_template.format(
|
||||||
|
region=region,
|
||||||
|
account_id=account_id,
|
||||||
|
resource_type=resource_type,
|
||||||
|
resource_path=resource_path,
|
||||||
|
)
|
||||||
|
return arn
|
@ -42,6 +42,7 @@ def test_create_environment():
|
|||||||
app = conn.create_application(ApplicationName="myapp",)
|
app = conn.create_application(ApplicationName="myapp",)
|
||||||
env = conn.create_environment(ApplicationName="myapp", EnvironmentName="myenv",)
|
env = conn.create_environment(ApplicationName="myapp", EnvironmentName="myenv",)
|
||||||
env["EnvironmentName"].should.equal("myenv")
|
env["EnvironmentName"].should.equal("myenv")
|
||||||
|
env["EnvironmentArn"].should.contain("myapp/myenv")
|
||||||
|
|
||||||
|
|
||||||
@mock_elasticbeanstalk
|
@mock_elasticbeanstalk
|
||||||
@ -58,6 +59,7 @@ def test_describe_environments():
|
|||||||
len(envs).should.equal(1)
|
len(envs).should.equal(1)
|
||||||
envs[0]["ApplicationName"].should.equal("myapp")
|
envs[0]["ApplicationName"].should.equal("myapp")
|
||||||
envs[0]["EnvironmentName"].should.equal("myenv")
|
envs[0]["EnvironmentName"].should.equal("myenv")
|
||||||
|
envs[0]["EnvironmentArn"].should.contain("myapp/myenv")
|
||||||
|
|
||||||
|
|
||||||
def tags_dict_to_list(tag_dict):
|
def tags_dict_to_list(tag_dict):
|
||||||
|
Loading…
Reference in New Issue
Block a user