Use centralized ACCOUNT_ID (#4029)
This commit is contained in:
parent
6084d6cfe8
commit
5e4bccc22d
@ -151,8 +151,8 @@ class Database(CloudFormationModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def db_instance_arn(self):
|
def db_instance_arn(self):
|
||||||
return "arn:aws:rds:{0}:1234567890:db:{1}".format(
|
return "arn:aws:rds:{0}:{1}:db:{2}".format(
|
||||||
self.region, self.db_instance_identifier
|
self.region, ACCOUNT_ID, self.db_instance_identifier
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -551,8 +551,8 @@ class Snapshot(BaseModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def snapshot_arn(self):
|
def snapshot_arn(self):
|
||||||
return "arn:aws:rds:{0}:1234567890:snapshot:{1}".format(
|
return "arn:aws:rds:{0}:{1}:snapshot:{2}".format(
|
||||||
self.database.region, self.snapshot_id
|
self.database.region, ACCOUNT_ID, self.snapshot_id
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_xml(self):
|
def to_xml(self):
|
||||||
@ -614,7 +614,7 @@ class SecurityGroup(CloudFormationModel):
|
|||||||
self.ip_ranges = []
|
self.ip_ranges = []
|
||||||
self.ec2_security_groups = []
|
self.ec2_security_groups = []
|
||||||
self.tags = tags
|
self.tags = tags
|
||||||
self.owner_id = "1234567890"
|
self.owner_id = ACCOUNT_ID
|
||||||
self.vpc_id = None
|
self.vpc_id = None
|
||||||
|
|
||||||
def to_xml(self):
|
def to_xml(self):
|
||||||
|
@ -5,6 +5,8 @@ import string
|
|||||||
import six
|
import six
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from moto.core import ACCOUNT_ID
|
||||||
|
|
||||||
|
|
||||||
def random_password(
|
def random_password(
|
||||||
password_length,
|
password_length,
|
||||||
@ -68,8 +70,8 @@ def random_password(
|
|||||||
|
|
||||||
def secret_arn(region, secret_id):
|
def secret_arn(region, secret_id):
|
||||||
id_string = "".join(random.choice(string.ascii_letters) for _ in range(5))
|
id_string = "".join(random.choice(string.ascii_letters) for _ in range(5))
|
||||||
return "arn:aws:secretsmanager:{0}:1234567890:secret:{1}-{2}".format(
|
return "arn:aws:secretsmanager:{0}:{1}:secret:{2}-{3}".format(
|
||||||
region, secret_id, id_string
|
region, ACCOUNT_ID, secret_id, id_string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
ACCOUNT_ID = "1234567890"
|
from moto.core import ACCOUNT_ID
|
||||||
|
|
||||||
|
|
||||||
def parameter_arn(region, parameter_name):
|
def parameter_arn(region, parameter_name):
|
||||||
|
@ -31,7 +31,7 @@ def test_create_database():
|
|||||||
db_instance["MasterUsername"].should.equal("root")
|
db_instance["MasterUsername"].should.equal("root")
|
||||||
db_instance["DBSecurityGroups"][0]["DBSecurityGroupName"].should.equal("my_sg")
|
db_instance["DBSecurityGroups"][0]["DBSecurityGroupName"].should.equal("my_sg")
|
||||||
db_instance["DBInstanceArn"].should.equal(
|
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["DBInstanceStatus"].should.equal("available")
|
||||||
db_instance["DBName"].should.equal("staging-postgres")
|
db_instance["DBName"].should.equal("staging-postgres")
|
||||||
@ -312,7 +312,7 @@ def test_get_databases():
|
|||||||
list(instances["DBInstances"]).should.have.length_of(1)
|
list(instances["DBInstances"]).should.have.length_of(1)
|
||||||
instances["DBInstances"][0]["DBInstanceIdentifier"].should.equal("db-master-1")
|
instances["DBInstances"][0]["DBInstanceIdentifier"].should.equal("db-master-1")
|
||||||
instances["DBInstances"][0]["DBInstanceArn"].should.equal(
|
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)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
|||||||
import boto3
|
import boto3
|
||||||
|
|
||||||
from moto import mock_secretsmanager, mock_lambda, settings
|
from moto import mock_secretsmanager, mock_lambda, settings
|
||||||
|
from moto.core import ACCOUNT_ID
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
import string
|
import string
|
||||||
import pytz
|
import pytz
|
||||||
@ -30,11 +31,15 @@ def test_get_secret_value():
|
|||||||
def test_get_secret_value_by_arn():
|
def test_get_secret_value_by_arn():
|
||||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||||
|
|
||||||
|
name = "java-util-test-password"
|
||||||
secret_value = "test_get_secret_value_by_arn"
|
secret_value = "test_get_secret_value_by_arn"
|
||||||
result = conn.create_secret(
|
result = conn.create_secret(Name=name, SecretString=secret_value)
|
||||||
Name="java-util-test-password", 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
|
assert result["SecretString"] == secret_value
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ from botocore.exceptions import ClientError
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from moto import mock_ec2, mock_ssm
|
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 moto.ssm.models import PARAMETER_VERSION_LIMIT, PARAMETER_HISTORY_MAX_RESULTS
|
||||||
from tests import EXAMPLE_AMI_ID
|
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(
|
{p["ARN"] for p in response["Parameters"]}.should.equal(
|
||||||
set(
|
set(
|
||||||
[
|
[
|
||||||
"arn:aws:ssm:us-east-1:1234567890:parameter/foo",
|
"arn:aws:ssm:us-east-1:{}:parameter/foo".format(ACCOUNT_ID),
|
||||||
"arn:aws:ssm:us-east-1:1234567890:parameter/baz",
|
"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]["Version"].should.equal(1)
|
||||||
response["Parameters"][0]["LastModifiedDate"].should.be.a(datetime.datetime)
|
response["Parameters"][0]["LastModifiedDate"].should.be.a(datetime.datetime)
|
||||||
response["Parameters"][0]["ARN"].should.equal(
|
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"]
|
initial_modification_date = response["Parameters"][0]["LastModifiedDate"]
|
||||||
|
|
||||||
@ -274,7 +275,7 @@ def test_put_parameter(name):
|
|||||||
initial_modification_date
|
initial_modification_date
|
||||||
)
|
)
|
||||||
response["Parameters"][0]["ARN"].should.equal(
|
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(
|
response = client.put_parameter(
|
||||||
@ -295,7 +296,7 @@ def test_put_parameter(name):
|
|||||||
initial_modification_date
|
initial_modification_date
|
||||||
)
|
)
|
||||||
response["Parameters"][0]["ARN"].should.equal(
|
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"]["Type"].should.equal("String")
|
||||||
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
|
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
|
||||||
response["Parameter"]["ARN"].should.equal(
|
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"]["Type"].should.equal("String")
|
||||||
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
|
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
|
||||||
response["Parameter"]["ARN"].should.equal(
|
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)
|
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"]["Type"].should.equal("String")
|
||||||
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
|
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
|
||||||
response["Parameter"]["ARN"].should.equal(
|
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)
|
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"]["Type"].should.equal("String")
|
||||||
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
|
response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime)
|
||||||
response["Parameter"]["ARN"].should.equal(
|
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:
|
with pytest.raises(ClientError) as ex:
|
||||||
|
Loading…
Reference in New Issue
Block a user