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 moto.core import BaseBackend, BaseModel
|
||||
from moto.core import BaseBackend, BaseModel, ACCOUNT_ID
|
||||
from .exceptions import InvalidParameterValueError, ResourceNotFoundException
|
||||
from .utils import make_arn
|
||||
|
||||
|
||||
class FakeEnvironment(BaseModel):
|
||||
@ -23,15 +24,8 @@ class FakeEnvironment(BaseModel):
|
||||
|
||||
@property
|
||||
def environment_arn(self):
|
||||
return (
|
||||
"arn:aws:elasticbeanstalk:{region}:{account_id}:"
|
||||
"environment/{application_name}/{environment_name}".format(
|
||||
region=self.region,
|
||||
account_id="123456789012",
|
||||
application_name=self.application_name,
|
||||
environment_name=self.environment_name,
|
||||
)
|
||||
)
|
||||
resource_path = "%s/%s" % (self.application_name, self.environment_name)
|
||||
return make_arn(self.region, ACCOUNT_ID, "environment", resource_path)
|
||||
|
||||
@property
|
||||
def platform_arn(self):
|
||||
@ -68,6 +62,10 @@ class FakeApplication(BaseModel):
|
||||
def region(self):
|
||||
return self.backend.region
|
||||
|
||||
@property
|
||||
def arn(self):
|
||||
return make_arn(self.region, ACCOUNT_ID, "application", self.application_name)
|
||||
|
||||
|
||||
class EBBackend(BaseBackend):
|
||||
def __init__(self, region):
|
||||
|
@ -91,7 +91,7 @@ EB_CREATE_APPLICATION = """
|
||||
</MaxCountRule>
|
||||
</VersionLifecycleConfig>
|
||||
</ResourceLifecycleConfig>
|
||||
<ApplicationArn>arn:aws:elasticbeanstalk:{{ region_name }}:111122223333:application/{{ application.application_name }}</ApplicationArn>
|
||||
<ApplicationArn>{{ application.arn }}</ApplicationArn>
|
||||
<ApplicationName>{{ application.application_name }}</ApplicationName>
|
||||
<DateUpdated>2019-09-03T13:08:29.049Z</DateUpdated>
|
||||
</Application>
|
||||
@ -125,7 +125,7 @@ EB_DESCRIBE_APPLICATIONS = """
|
||||
</MaxCountRule>
|
||||
</VersionLifecycleConfig>
|
||||
</ResourceLifecycleConfig>
|
||||
<ApplicationArn>arn:aws:elasticbeanstalk:{{ region_name }}:111122223333:application/{{ application.application_name }}</ApplicationArn>
|
||||
<ApplicationArn>{{ application.arn }}</ApplicationArn>
|
||||
<ApplicationName>{{ application.application_name }}</ApplicationName>
|
||||
<DateUpdated>2019-09-03T13:08:29.049Z</DateUpdated>
|
||||
</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",)
|
||||
env = conn.create_environment(ApplicationName="myapp", EnvironmentName="myenv",)
|
||||
env["EnvironmentName"].should.equal("myenv")
|
||||
env["EnvironmentArn"].should.contain("myapp/myenv")
|
||||
|
||||
|
||||
@mock_elasticbeanstalk
|
||||
@ -58,6 +59,7 @@ def test_describe_environments():
|
||||
len(envs).should.equal(1)
|
||||
envs[0]["ApplicationName"].should.equal("myapp")
|
||||
envs[0]["EnvironmentName"].should.equal("myenv")
|
||||
envs[0]["EnvironmentArn"].should.contain("myapp/myenv")
|
||||
|
||||
|
||||
def tags_dict_to_list(tag_dict):
|
||||
|
Loading…
Reference in New Issue
Block a user