Use centralized ACCOUNT_ID (#4029)

This commit is contained in:
Bert Blommers 2021-06-23 18:03:11 +01:00 committed by GitHub
parent 6084d6cfe8
commit 5e4bccc22d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 22 deletions

View File

@ -151,8 +151,8 @@ class Database(CloudFormationModel):
@property
def db_instance_arn(self):
return "arn:aws:rds:{0}:1234567890:db:{1}".format(
self.region, self.db_instance_identifier
return "arn:aws:rds:{0}:{1}:db:{2}".format(
self.region, ACCOUNT_ID, self.db_instance_identifier
)
@property
@ -551,8 +551,8 @@ class Snapshot(BaseModel):
@property
def snapshot_arn(self):
return "arn:aws:rds:{0}:1234567890:snapshot:{1}".format(
self.database.region, self.snapshot_id
return "arn:aws:rds:{0}:{1}:snapshot:{2}".format(
self.database.region, ACCOUNT_ID, self.snapshot_id
)
def to_xml(self):
@ -614,7 +614,7 @@ class SecurityGroup(CloudFormationModel):
self.ip_ranges = []
self.ec2_security_groups = []
self.tags = tags
self.owner_id = "1234567890"
self.owner_id = ACCOUNT_ID
self.vpc_id = None
def to_xml(self):

View File

@ -5,6 +5,8 @@ import string
import six
import re
from moto.core import ACCOUNT_ID
def random_password(
password_length,
@ -68,8 +70,8 @@ def random_password(
def secret_arn(region, secret_id):
id_string = "".join(random.choice(string.ascii_letters) for _ in range(5))
return "arn:aws:secretsmanager:{0}:1234567890:secret:{1}-{2}".format(
region, secret_id, id_string
return "arn:aws:secretsmanager:{0}:{1}:secret:{2}-{3}".format(
region, ACCOUNT_ID, secret_id, id_string
)

View File

@ -1,4 +1,4 @@
ACCOUNT_ID = "1234567890"
from moto.core import ACCOUNT_ID
def parameter_arn(region, parameter_name):

View File

@ -31,7 +31,7 @@ def test_create_database():
db_instance["MasterUsername"].should.equal("root")
db_instance["DBSecurityGroups"][0]["DBSecurityGroupName"].should.equal("my_sg")
db_instance["DBInstanceArn"].should.equal(
"arn:aws:rds:us-west-2:1234567890:db:db-master-1"
"arn:aws:rds:us-west-2:{}:db:db-master-1".format(ACCOUNT_ID)
)
db_instance["DBInstanceStatus"].should.equal("available")
db_instance["DBName"].should.equal("staging-postgres")
@ -312,7 +312,7 @@ def test_get_databases():
list(instances["DBInstances"]).should.have.length_of(1)
instances["DBInstances"][0]["DBInstanceIdentifier"].should.equal("db-master-1")
instances["DBInstances"][0]["DBInstanceArn"].should.equal(
"arn:aws:rds:us-west-2:1234567890:db:db-master-1"
"arn:aws:rds:us-west-2:{}:db:db-master-1".format(ACCOUNT_ID)
)

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals
import boto3
from moto import mock_secretsmanager, mock_lambda, settings
from moto.core import ACCOUNT_ID
from botocore.exceptions import ClientError
import string
import pytz
@ -30,11 +31,15 @@ def test_get_secret_value():
def test_get_secret_value_by_arn():
conn = boto3.client("secretsmanager", region_name="us-west-2")
name = "java-util-test-password"
secret_value = "test_get_secret_value_by_arn"
result = conn.create_secret(
Name="java-util-test-password", SecretString=secret_value
result = conn.create_secret(Name=name, SecretString=secret_value)
arn = result["ARN"]
arn.should.match(
"^arn:aws:secretsmanager:us-west-2:{}:secret:{}".format(ACCOUNT_ID, name)
)
result = conn.get_secret_value(SecretId=result["ARN"])
result = conn.get_secret_value(SecretId=arn)
assert result["SecretString"] == secret_value

View File

@ -12,6 +12,7 @@ from botocore.exceptions import ClientError
import pytest
from moto import mock_ec2, mock_ssm
from moto.core import ACCOUNT_ID
from moto.ssm.models import PARAMETER_VERSION_LIMIT, PARAMETER_HISTORY_MAX_RESULTS
from tests import EXAMPLE_AMI_ID
@ -120,8 +121,8 @@ def test_get_parameters_by_path():
{p["ARN"] for p in response["Parameters"]}.should.equal(
set(
[
"arn:aws:ssm:us-east-1:1234567890:parameter/foo",
"arn:aws:ssm:us-east-1:1234567890:parameter/baz",
"arn:aws:ssm:us-east-1:{}:parameter/foo".format(ACCOUNT_ID),
"arn:aws:ssm:us-east-1:{}:parameter/baz".format(ACCOUNT_ID),
]
)
)
@ -247,7 +248,7 @@ def test_put_parameter(name):
response["Parameters"][0]["Version"].should.equal(1)
response["Parameters"][0]["LastModifiedDate"].should.be.a(datetime.datetime)
response["Parameters"][0]["ARN"].should.equal(
"arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name)
"arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name)
)
initial_modification_date = response["Parameters"][0]["LastModifiedDate"]
@ -274,7 +275,7 @@ def test_put_parameter(name):
initial_modification_date
)
response["Parameters"][0]["ARN"].should.equal(
"arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name)
"arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name)
)
response = client.put_parameter(
@ -295,7 +296,7 @@ def test_put_parameter(name):
initial_modification_date
)
response["Parameters"][0]["ARN"].should.equal(
"arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name)
"arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name)
)
@ -408,7 +409,7 @@ def test_get_parameter():
response["Parameter"]["Type"].should.equal("String")
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
response["Parameter"]["ARN"].should.equal(
"arn:aws:ssm:us-east-1:1234567890:parameter/test"
"arn:aws:ssm:us-east-1:{}:parameter/test".format(ACCOUNT_ID)
)
@ -434,7 +435,7 @@ def test_get_parameter_with_version_and_labels():
response["Parameter"]["Type"].should.equal("String")
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
response["Parameter"]["ARN"].should.equal(
"arn:aws:ssm:us-east-1:1234567890:parameter/test-1"
"arn:aws:ssm:us-east-1:{}:parameter/test-1".format(ACCOUNT_ID)
)
response = client.get_parameter(Name="test-2:1", WithDecryption=False)
@ -443,7 +444,7 @@ def test_get_parameter_with_version_and_labels():
response["Parameter"]["Type"].should.equal("String")
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
response["Parameter"]["ARN"].should.equal(
"arn:aws:ssm:us-east-1:1234567890:parameter/test-2"
"arn:aws:ssm:us-east-1:{}:parameter/test-2".format(ACCOUNT_ID)
)
response = client.get_parameter(Name="test-2:test-label", WithDecryption=False)
@ -452,7 +453,7 @@ def test_get_parameter_with_version_and_labels():
response["Parameter"]["Type"].should.equal("String")
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
response["Parameter"]["ARN"].should.equal(
"arn:aws:ssm:us-east-1:1234567890:parameter/test-2"
"arn:aws:ssm:us-east-1:{}:parameter/test-2".format(ACCOUNT_ID)
)
with pytest.raises(ClientError) as ex: