Run black on moto & test directories.
This commit is contained in:
parent
c820395dbf
commit
96e5b1993d
507 changed files with 52541 additions and 47814 deletions
|
|
@ -11,17 +11,15 @@ from moto.organizations import utils
|
|||
|
||||
|
||||
class FakeOrganization(BaseModel):
|
||||
|
||||
def __init__(self, feature_set):
|
||||
self.id = utils.make_random_org_id()
|
||||
self.root_id = utils.make_random_root_id()
|
||||
self.feature_set = feature_set
|
||||
self.master_account_id = utils.MASTER_ACCOUNT_ID
|
||||
self.master_account_email = utils.MASTER_ACCOUNT_EMAIL
|
||||
self.available_policy_types = [{
|
||||
'Type': 'SERVICE_CONTROL_POLICY',
|
||||
'Status': 'ENABLED'
|
||||
}]
|
||||
self.available_policy_types = [
|
||||
{"Type": "SERVICE_CONTROL_POLICY", "Status": "ENABLED"}
|
||||
]
|
||||
|
||||
@property
|
||||
def arn(self):
|
||||
|
|
@ -33,129 +31,114 @@ class FakeOrganization(BaseModel):
|
|||
|
||||
def describe(self):
|
||||
return {
|
||||
'Organization': {
|
||||
'Id': self.id,
|
||||
'Arn': self.arn,
|
||||
'FeatureSet': self.feature_set,
|
||||
'MasterAccountArn': self.master_account_arn,
|
||||
'MasterAccountId': self.master_account_id,
|
||||
'MasterAccountEmail': self.master_account_email,
|
||||
'AvailablePolicyTypes': self.available_policy_types,
|
||||
"Organization": {
|
||||
"Id": self.id,
|
||||
"Arn": self.arn,
|
||||
"FeatureSet": self.feature_set,
|
||||
"MasterAccountArn": self.master_account_arn,
|
||||
"MasterAccountId": self.master_account_id,
|
||||
"MasterAccountEmail": self.master_account_email,
|
||||
"AvailablePolicyTypes": self.available_policy_types,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class FakeAccount(BaseModel):
|
||||
|
||||
def __init__(self, organization, **kwargs):
|
||||
self.type = 'ACCOUNT'
|
||||
self.type = "ACCOUNT"
|
||||
self.organization_id = organization.id
|
||||
self.master_account_id = organization.master_account_id
|
||||
self.create_account_status_id = utils.make_random_create_account_status_id()
|
||||
self.id = utils.make_random_account_id()
|
||||
self.name = kwargs['AccountName']
|
||||
self.email = kwargs['Email']
|
||||
self.name = kwargs["AccountName"]
|
||||
self.email = kwargs["Email"]
|
||||
self.create_time = datetime.datetime.utcnow()
|
||||
self.status = 'ACTIVE'
|
||||
self.joined_method = 'CREATED'
|
||||
self.status = "ACTIVE"
|
||||
self.joined_method = "CREATED"
|
||||
self.parent_id = organization.root_id
|
||||
self.attached_policies = []
|
||||
|
||||
@property
|
||||
def arn(self):
|
||||
return utils.ACCOUNT_ARN_FORMAT.format(
|
||||
self.master_account_id,
|
||||
self.organization_id,
|
||||
self.id
|
||||
self.master_account_id, self.organization_id, self.id
|
||||
)
|
||||
|
||||
@property
|
||||
def create_account_status(self):
|
||||
return {
|
||||
'CreateAccountStatus': {
|
||||
'Id': self.create_account_status_id,
|
||||
'AccountName': self.name,
|
||||
'State': 'SUCCEEDED',
|
||||
'RequestedTimestamp': unix_time(self.create_time),
|
||||
'CompletedTimestamp': unix_time(self.create_time),
|
||||
'AccountId': self.id,
|
||||
"CreateAccountStatus": {
|
||||
"Id": self.create_account_status_id,
|
||||
"AccountName": self.name,
|
||||
"State": "SUCCEEDED",
|
||||
"RequestedTimestamp": unix_time(self.create_time),
|
||||
"CompletedTimestamp": unix_time(self.create_time),
|
||||
"AccountId": self.id,
|
||||
}
|
||||
}
|
||||
|
||||
def describe(self):
|
||||
return {
|
||||
'Account': {
|
||||
'Id': self.id,
|
||||
'Arn': self.arn,
|
||||
'Email': self.email,
|
||||
'Name': self.name,
|
||||
'Status': self.status,
|
||||
'JoinedMethod': self.joined_method,
|
||||
'JoinedTimestamp': unix_time(self.create_time),
|
||||
"Account": {
|
||||
"Id": self.id,
|
||||
"Arn": self.arn,
|
||||
"Email": self.email,
|
||||
"Name": self.name,
|
||||
"Status": self.status,
|
||||
"JoinedMethod": self.joined_method,
|
||||
"JoinedTimestamp": unix_time(self.create_time),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class FakeOrganizationalUnit(BaseModel):
|
||||
|
||||
def __init__(self, organization, **kwargs):
|
||||
self.type = 'ORGANIZATIONAL_UNIT'
|
||||
self.type = "ORGANIZATIONAL_UNIT"
|
||||
self.organization_id = organization.id
|
||||
self.master_account_id = organization.master_account_id
|
||||
self.id = utils.make_random_ou_id(organization.root_id)
|
||||
self.name = kwargs.get('Name')
|
||||
self.parent_id = kwargs.get('ParentId')
|
||||
self.name = kwargs.get("Name")
|
||||
self.parent_id = kwargs.get("ParentId")
|
||||
self._arn_format = utils.OU_ARN_FORMAT
|
||||
self.attached_policies = []
|
||||
|
||||
@property
|
||||
def arn(self):
|
||||
return self._arn_format.format(
|
||||
self.master_account_id,
|
||||
self.organization_id,
|
||||
self.id
|
||||
self.master_account_id, self.organization_id, self.id
|
||||
)
|
||||
|
||||
def describe(self):
|
||||
return {
|
||||
'OrganizationalUnit': {
|
||||
'Id': self.id,
|
||||
'Arn': self.arn,
|
||||
'Name': self.name,
|
||||
}
|
||||
"OrganizationalUnit": {"Id": self.id, "Arn": self.arn, "Name": self.name}
|
||||
}
|
||||
|
||||
|
||||
class FakeRoot(FakeOrganizationalUnit):
|
||||
|
||||
def __init__(self, organization, **kwargs):
|
||||
super(FakeRoot, self).__init__(organization, **kwargs)
|
||||
self.type = 'ROOT'
|
||||
self.type = "ROOT"
|
||||
self.id = organization.root_id
|
||||
self.name = 'Root'
|
||||
self.policy_types = [{
|
||||
'Type': 'SERVICE_CONTROL_POLICY',
|
||||
'Status': 'ENABLED'
|
||||
}]
|
||||
self.name = "Root"
|
||||
self.policy_types = [{"Type": "SERVICE_CONTROL_POLICY", "Status": "ENABLED"}]
|
||||
self._arn_format = utils.ROOT_ARN_FORMAT
|
||||
self.attached_policies = []
|
||||
|
||||
def describe(self):
|
||||
return {
|
||||
'Id': self.id,
|
||||
'Arn': self.arn,
|
||||
'Name': self.name,
|
||||
'PolicyTypes': self.policy_types
|
||||
"Id": self.id,
|
||||
"Arn": self.arn,
|
||||
"Name": self.name,
|
||||
"PolicyTypes": self.policy_types,
|
||||
}
|
||||
|
||||
|
||||
class FakeServiceControlPolicy(BaseModel):
|
||||
|
||||
def __init__(self, organization, **kwargs):
|
||||
self.content = kwargs.get('Content')
|
||||
self.description = kwargs.get('Description')
|
||||
self.name = kwargs.get('Name')
|
||||
self.type = kwargs.get('Type')
|
||||
self.content = kwargs.get("Content")
|
||||
self.description = kwargs.get("Description")
|
||||
self.name = kwargs.get("Name")
|
||||
self.type = kwargs.get("Type")
|
||||
self.id = utils.make_random_service_control_policy_id()
|
||||
self.aws_managed = False
|
||||
self.organization_id = organization.id
|
||||
|
|
@ -166,29 +149,26 @@ class FakeServiceControlPolicy(BaseModel):
|
|||
@property
|
||||
def arn(self):
|
||||
return self._arn_format.format(
|
||||
self.master_account_id,
|
||||
self.organization_id,
|
||||
self.id
|
||||
self.master_account_id, self.organization_id, self.id
|
||||
)
|
||||
|
||||
def describe(self):
|
||||
return {
|
||||
'Policy': {
|
||||
'PolicySummary': {
|
||||
'Id': self.id,
|
||||
'Arn': self.arn,
|
||||
'Name': self.name,
|
||||
'Description': self.description,
|
||||
'Type': self.type,
|
||||
'AwsManaged': self.aws_managed,
|
||||
"Policy": {
|
||||
"PolicySummary": {
|
||||
"Id": self.id,
|
||||
"Arn": self.arn,
|
||||
"Name": self.name,
|
||||
"Description": self.description,
|
||||
"Type": self.type,
|
||||
"AwsManaged": self.aws_managed,
|
||||
},
|
||||
'Content': self.content
|
||||
"Content": self.content,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class OrganizationsBackend(BaseBackend):
|
||||
|
||||
def __init__(self):
|
||||
self.org = None
|
||||
self.accounts = []
|
||||
|
|
@ -196,33 +176,25 @@ class OrganizationsBackend(BaseBackend):
|
|||
self.policies = []
|
||||
|
||||
def create_organization(self, **kwargs):
|
||||
self.org = FakeOrganization(kwargs['FeatureSet'])
|
||||
self.org = FakeOrganization(kwargs["FeatureSet"])
|
||||
root_ou = FakeRoot(self.org)
|
||||
self.ou.append(root_ou)
|
||||
master_account = FakeAccount(
|
||||
self.org,
|
||||
AccountName='master',
|
||||
Email=self.org.master_account_email,
|
||||
self.org, AccountName="master", Email=self.org.master_account_email
|
||||
)
|
||||
master_account.id = self.org.master_account_id
|
||||
self.accounts.append(master_account)
|
||||
default_policy = FakeServiceControlPolicy(
|
||||
self.org,
|
||||
Name='FullAWSAccess',
|
||||
Description='Allows access to every operation',
|
||||
Type='SERVICE_CONTROL_POLICY',
|
||||
Name="FullAWSAccess",
|
||||
Description="Allows access to every operation",
|
||||
Type="SERVICE_CONTROL_POLICY",
|
||||
Content=json.dumps(
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": "*",
|
||||
"Resource": "*"
|
||||
}
|
||||
]
|
||||
"Statement": [{"Effect": "Allow", "Action": "*", "Resource": "*"}],
|
||||
}
|
||||
)
|
||||
),
|
||||
)
|
||||
default_policy.id = utils.DEFAULT_POLICY_ID
|
||||
default_policy.aws_managed = True
|
||||
|
|
@ -234,15 +206,13 @@ class OrganizationsBackend(BaseBackend):
|
|||
def describe_organization(self):
|
||||
if not self.org:
|
||||
raise RESTError(
|
||||
'AWSOrganizationsNotInUseException',
|
||||
"Your account is not a member of an organization."
|
||||
"AWSOrganizationsNotInUseException",
|
||||
"Your account is not a member of an organization.",
|
||||
)
|
||||
return self.org.describe()
|
||||
|
||||
def list_roots(self):
|
||||
return dict(
|
||||
Roots=[ou.describe() for ou in self.ou if isinstance(ou, FakeRoot)]
|
||||
)
|
||||
return dict(Roots=[ou.describe() for ou in self.ou if isinstance(ou, FakeRoot)])
|
||||
|
||||
def create_organizational_unit(self, **kwargs):
|
||||
new_ou = FakeOrganizationalUnit(self.org, **kwargs)
|
||||
|
|
@ -254,8 +224,8 @@ class OrganizationsBackend(BaseBackend):
|
|||
ou = next((ou for ou in self.ou if ou.id == ou_id), None)
|
||||
if ou is None:
|
||||
raise RESTError(
|
||||
'OrganizationalUnitNotFoundException',
|
||||
"You specified an organizational unit that doesn't exist."
|
||||
"OrganizationalUnitNotFoundException",
|
||||
"You specified an organizational unit that doesn't exist.",
|
||||
)
|
||||
return ou
|
||||
|
||||
|
|
@ -264,24 +234,19 @@ class OrganizationsBackend(BaseBackend):
|
|||
self.get_organizational_unit_by_id(parent_id)
|
||||
except RESTError:
|
||||
raise RESTError(
|
||||
'ParentNotFoundException',
|
||||
"You specified parent that doesn't exist."
|
||||
"ParentNotFoundException", "You specified parent that doesn't exist."
|
||||
)
|
||||
return parent_id
|
||||
|
||||
def describe_organizational_unit(self, **kwargs):
|
||||
ou = self.get_organizational_unit_by_id(kwargs['OrganizationalUnitId'])
|
||||
ou = self.get_organizational_unit_by_id(kwargs["OrganizationalUnitId"])
|
||||
return ou.describe()
|
||||
|
||||
def list_organizational_units_for_parent(self, **kwargs):
|
||||
parent_id = self.validate_parent_id(kwargs['ParentId'])
|
||||
parent_id = self.validate_parent_id(kwargs["ParentId"])
|
||||
return dict(
|
||||
OrganizationalUnits=[
|
||||
{
|
||||
'Id': ou.id,
|
||||
'Arn': ou.arn,
|
||||
'Name': ou.name,
|
||||
}
|
||||
{"Id": ou.id, "Arn": ou.arn, "Name": ou.name}
|
||||
for ou in self.ou
|
||||
if ou.parent_id == parent_id
|
||||
]
|
||||
|
|
@ -294,76 +259,66 @@ class OrganizationsBackend(BaseBackend):
|
|||
return new_account.create_account_status
|
||||
|
||||
def get_account_by_id(self, account_id):
|
||||
account = next((
|
||||
account for account in self.accounts
|
||||
if account.id == account_id
|
||||
), None)
|
||||
account = next(
|
||||
(account for account in self.accounts if account.id == account_id), None
|
||||
)
|
||||
if account is None:
|
||||
raise RESTError(
|
||||
'AccountNotFoundException',
|
||||
"You specified an account that doesn't exist."
|
||||
"AccountNotFoundException",
|
||||
"You specified an account that doesn't exist.",
|
||||
)
|
||||
return account
|
||||
|
||||
def describe_account(self, **kwargs):
|
||||
account = self.get_account_by_id(kwargs['AccountId'])
|
||||
account = self.get_account_by_id(kwargs["AccountId"])
|
||||
return account.describe()
|
||||
|
||||
def list_accounts(self):
|
||||
return dict(
|
||||
Accounts=[account.describe()['Account'] for account in self.accounts]
|
||||
Accounts=[account.describe()["Account"] for account in self.accounts]
|
||||
)
|
||||
|
||||
def list_accounts_for_parent(self, **kwargs):
|
||||
parent_id = self.validate_parent_id(kwargs['ParentId'])
|
||||
parent_id = self.validate_parent_id(kwargs["ParentId"])
|
||||
return dict(
|
||||
Accounts=[
|
||||
account.describe()['Account']
|
||||
account.describe()["Account"]
|
||||
for account in self.accounts
|
||||
if account.parent_id == parent_id
|
||||
]
|
||||
)
|
||||
|
||||
def move_account(self, **kwargs):
|
||||
new_parent_id = self.validate_parent_id(kwargs['DestinationParentId'])
|
||||
self.validate_parent_id(kwargs['SourceParentId'])
|
||||
account = self.get_account_by_id(kwargs['AccountId'])
|
||||
new_parent_id = self.validate_parent_id(kwargs["DestinationParentId"])
|
||||
self.validate_parent_id(kwargs["SourceParentId"])
|
||||
account = self.get_account_by_id(kwargs["AccountId"])
|
||||
index = self.accounts.index(account)
|
||||
self.accounts[index].parent_id = new_parent_id
|
||||
|
||||
def list_parents(self, **kwargs):
|
||||
if re.compile(r'[0-9]{12}').match(kwargs['ChildId']):
|
||||
child_object = self.get_account_by_id(kwargs['ChildId'])
|
||||
if re.compile(r"[0-9]{12}").match(kwargs["ChildId"]):
|
||||
child_object = self.get_account_by_id(kwargs["ChildId"])
|
||||
else:
|
||||
child_object = self.get_organizational_unit_by_id(kwargs['ChildId'])
|
||||
child_object = self.get_organizational_unit_by_id(kwargs["ChildId"])
|
||||
return dict(
|
||||
Parents=[
|
||||
{
|
||||
'Id': ou.id,
|
||||
'Type': ou.type,
|
||||
}
|
||||
{"Id": ou.id, "Type": ou.type}
|
||||
for ou in self.ou
|
||||
if ou.id == child_object.parent_id
|
||||
]
|
||||
)
|
||||
|
||||
def list_children(self, **kwargs):
|
||||
parent_id = self.validate_parent_id(kwargs['ParentId'])
|
||||
if kwargs['ChildType'] == 'ACCOUNT':
|
||||
parent_id = self.validate_parent_id(kwargs["ParentId"])
|
||||
if kwargs["ChildType"] == "ACCOUNT":
|
||||
obj_list = self.accounts
|
||||
elif kwargs['ChildType'] == 'ORGANIZATIONAL_UNIT':
|
||||
elif kwargs["ChildType"] == "ORGANIZATIONAL_UNIT":
|
||||
obj_list = self.ou
|
||||
else:
|
||||
raise RESTError(
|
||||
'InvalidInputException',
|
||||
'You specified an invalid value.'
|
||||
)
|
||||
raise RESTError("InvalidInputException", "You specified an invalid value.")
|
||||
return dict(
|
||||
Children=[
|
||||
{
|
||||
'Id': obj.id,
|
||||
'Type': kwargs['ChildType'],
|
||||
}
|
||||
{"Id": obj.id, "Type": kwargs["ChildType"]}
|
||||
for obj in obj_list
|
||||
if obj.parent_id == parent_id
|
||||
]
|
||||
|
|
@ -375,99 +330,93 @@ class OrganizationsBackend(BaseBackend):
|
|||
return new_policy.describe()
|
||||
|
||||
def describe_policy(self, **kwargs):
|
||||
if re.compile(utils.SCP_ID_REGEX).match(kwargs['PolicyId']):
|
||||
policy = next((p for p in self.policies if p.id == kwargs['PolicyId']), None)
|
||||
if re.compile(utils.SCP_ID_REGEX).match(kwargs["PolicyId"]):
|
||||
policy = next(
|
||||
(p for p in self.policies if p.id == kwargs["PolicyId"]), None
|
||||
)
|
||||
if policy is None:
|
||||
raise RESTError(
|
||||
'PolicyNotFoundException',
|
||||
"You specified a policy that doesn't exist."
|
||||
"PolicyNotFoundException",
|
||||
"You specified a policy that doesn't exist.",
|
||||
)
|
||||
else:
|
||||
raise RESTError(
|
||||
'InvalidInputException',
|
||||
'You specified an invalid value.'
|
||||
)
|
||||
raise RESTError("InvalidInputException", "You specified an invalid value.")
|
||||
return policy.describe()
|
||||
|
||||
def attach_policy(self, **kwargs):
|
||||
policy = next((p for p in self.policies if p.id == kwargs['PolicyId']), None)
|
||||
if (re.compile(utils.ROOT_ID_REGEX).match(kwargs['TargetId']) or re.compile(utils.OU_ID_REGEX).match(kwargs['TargetId'])):
|
||||
ou = next((ou for ou in self.ou if ou.id == kwargs['TargetId']), None)
|
||||
policy = next((p for p in self.policies if p.id == kwargs["PolicyId"]), None)
|
||||
if re.compile(utils.ROOT_ID_REGEX).match(kwargs["TargetId"]) or re.compile(
|
||||
utils.OU_ID_REGEX
|
||||
).match(kwargs["TargetId"]):
|
||||
ou = next((ou for ou in self.ou if ou.id == kwargs["TargetId"]), None)
|
||||
if ou is not None:
|
||||
if ou not in ou.attached_policies:
|
||||
ou.attached_policies.append(policy)
|
||||
policy.attachments.append(ou)
|
||||
else:
|
||||
raise RESTError(
|
||||
'OrganizationalUnitNotFoundException',
|
||||
"You specified an organizational unit that doesn't exist."
|
||||
"OrganizationalUnitNotFoundException",
|
||||
"You specified an organizational unit that doesn't exist.",
|
||||
)
|
||||
elif re.compile(utils.ACCOUNT_ID_REGEX).match(kwargs['TargetId']):
|
||||
account = next((a for a in self.accounts if a.id == kwargs['TargetId']), None)
|
||||
elif re.compile(utils.ACCOUNT_ID_REGEX).match(kwargs["TargetId"]):
|
||||
account = next(
|
||||
(a for a in self.accounts if a.id == kwargs["TargetId"]), None
|
||||
)
|
||||
if account is not None:
|
||||
if account not in account.attached_policies:
|
||||
account.attached_policies.append(policy)
|
||||
policy.attachments.append(account)
|
||||
else:
|
||||
raise RESTError(
|
||||
'AccountNotFoundException',
|
||||
"You specified an account that doesn't exist."
|
||||
"AccountNotFoundException",
|
||||
"You specified an account that doesn't exist.",
|
||||
)
|
||||
else:
|
||||
raise RESTError(
|
||||
'InvalidInputException',
|
||||
'You specified an invalid value.'
|
||||
)
|
||||
raise RESTError("InvalidInputException", "You specified an invalid value.")
|
||||
|
||||
def list_policies(self, **kwargs):
|
||||
return dict(Policies=[
|
||||
p.describe()['Policy']['PolicySummary'] for p in self.policies
|
||||
])
|
||||
return dict(
|
||||
Policies=[p.describe()["Policy"]["PolicySummary"] for p in self.policies]
|
||||
)
|
||||
|
||||
def list_policies_for_target(self, **kwargs):
|
||||
if re.compile(utils.OU_ID_REGEX).match(kwargs['TargetId']):
|
||||
obj = next((ou for ou in self.ou if ou.id == kwargs['TargetId']), None)
|
||||
if re.compile(utils.OU_ID_REGEX).match(kwargs["TargetId"]):
|
||||
obj = next((ou for ou in self.ou if ou.id == kwargs["TargetId"]), None)
|
||||
if obj is None:
|
||||
raise RESTError(
|
||||
'OrganizationalUnitNotFoundException',
|
||||
"You specified an organizational unit that doesn't exist."
|
||||
"OrganizationalUnitNotFoundException",
|
||||
"You specified an organizational unit that doesn't exist.",
|
||||
)
|
||||
elif re.compile(utils.ACCOUNT_ID_REGEX).match(kwargs['TargetId']):
|
||||
obj = next((a for a in self.accounts if a.id == kwargs['TargetId']), None)
|
||||
elif re.compile(utils.ACCOUNT_ID_REGEX).match(kwargs["TargetId"]):
|
||||
obj = next((a for a in self.accounts if a.id == kwargs["TargetId"]), None)
|
||||
if obj is None:
|
||||
raise RESTError(
|
||||
'AccountNotFoundException',
|
||||
"You specified an account that doesn't exist."
|
||||
"AccountNotFoundException",
|
||||
"You specified an account that doesn't exist.",
|
||||
)
|
||||
else:
|
||||
raise RESTError(
|
||||
'InvalidInputException',
|
||||
'You specified an invalid value.'
|
||||
)
|
||||
return dict(Policies=[
|
||||
p.describe()['Policy']['PolicySummary'] for p in obj.attached_policies
|
||||
])
|
||||
raise RESTError("InvalidInputException", "You specified an invalid value.")
|
||||
return dict(
|
||||
Policies=[
|
||||
p.describe()["Policy"]["PolicySummary"] for p in obj.attached_policies
|
||||
]
|
||||
)
|
||||
|
||||
def list_targets_for_policy(self, **kwargs):
|
||||
if re.compile(utils.SCP_ID_REGEX).match(kwargs['PolicyId']):
|
||||
policy = next((p for p in self.policies if p.id == kwargs['PolicyId']), None)
|
||||
if re.compile(utils.SCP_ID_REGEX).match(kwargs["PolicyId"]):
|
||||
policy = next(
|
||||
(p for p in self.policies if p.id == kwargs["PolicyId"]), None
|
||||
)
|
||||
if policy is None:
|
||||
raise RESTError(
|
||||
'PolicyNotFoundException',
|
||||
"You specified a policy that doesn't exist."
|
||||
"PolicyNotFoundException",
|
||||
"You specified a policy that doesn't exist.",
|
||||
)
|
||||
else:
|
||||
raise RESTError(
|
||||
'InvalidInputException',
|
||||
'You specified an invalid value.'
|
||||
)
|
||||
raise RESTError("InvalidInputException", "You specified an invalid value.")
|
||||
objects = [
|
||||
{
|
||||
'TargetId': obj.id,
|
||||
'Arn': obj.arn,
|
||||
'Name': obj.name,
|
||||
'Type': obj.type,
|
||||
} for obj in policy.attachments
|
||||
{"TargetId": obj.id, "Arn": obj.arn, "Name": obj.name, "Type": obj.type}
|
||||
for obj in policy.attachments
|
||||
]
|
||||
return dict(Targets=objects)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ from .models import organizations_backend
|
|||
|
||||
|
||||
class OrganizationsResponse(BaseResponse):
|
||||
|
||||
@property
|
||||
def organizations_backend(self):
|
||||
return organizations_backend
|
||||
|
|
@ -27,14 +26,10 @@ class OrganizationsResponse(BaseResponse):
|
|||
)
|
||||
|
||||
def describe_organization(self):
|
||||
return json.dumps(
|
||||
self.organizations_backend.describe_organization()
|
||||
)
|
||||
return json.dumps(self.organizations_backend.describe_organization())
|
||||
|
||||
def list_roots(self):
|
||||
return json.dumps(
|
||||
self.organizations_backend.list_roots()
|
||||
)
|
||||
return json.dumps(self.organizations_backend.list_roots())
|
||||
|
||||
def create_organizational_unit(self):
|
||||
return json.dumps(
|
||||
|
|
@ -43,12 +38,16 @@ class OrganizationsResponse(BaseResponse):
|
|||
|
||||
def describe_organizational_unit(self):
|
||||
return json.dumps(
|
||||
self.organizations_backend.describe_organizational_unit(**self.request_params)
|
||||
self.organizations_backend.describe_organizational_unit(
|
||||
**self.request_params
|
||||
)
|
||||
)
|
||||
|
||||
def list_organizational_units_for_parent(self):
|
||||
return json.dumps(
|
||||
self.organizations_backend.list_organizational_units_for_parent(**self.request_params)
|
||||
self.organizations_backend.list_organizational_units_for_parent(
|
||||
**self.request_params
|
||||
)
|
||||
)
|
||||
|
||||
def list_parents(self):
|
||||
|
|
@ -67,9 +66,7 @@ class OrganizationsResponse(BaseResponse):
|
|||
)
|
||||
|
||||
def list_accounts(self):
|
||||
return json.dumps(
|
||||
self.organizations_backend.list_accounts()
|
||||
)
|
||||
return json.dumps(self.organizations_backend.list_accounts())
|
||||
|
||||
def list_accounts_for_parent(self):
|
||||
return json.dumps(
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
from .responses import OrganizationsResponse
|
||||
|
||||
url_bases = [
|
||||
"https?://organizations.(.+).amazonaws.com",
|
||||
]
|
||||
url_bases = ["https?://organizations.(.+).amazonaws.com"]
|
||||
|
||||
url_paths = {
|
||||
'{0}/$': OrganizationsResponse.dispatch,
|
||||
}
|
||||
url_paths = {"{0}/$": OrganizationsResponse.dispatch}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@ from __future__ import unicode_literals
|
|||
import random
|
||||
import string
|
||||
|
||||
MASTER_ACCOUNT_ID = '123456789012'
|
||||
MASTER_ACCOUNT_EMAIL = 'master@example.com'
|
||||
DEFAULT_POLICY_ID = 'p-FullAWSAccess'
|
||||
ORGANIZATION_ARN_FORMAT = 'arn:aws:organizations::{0}:organization/{1}'
|
||||
MASTER_ACCOUNT_ARN_FORMAT = 'arn:aws:organizations::{0}:account/{1}/{0}'
|
||||
ACCOUNT_ARN_FORMAT = 'arn:aws:organizations::{0}:account/{1}/{2}'
|
||||
ROOT_ARN_FORMAT = 'arn:aws:organizations::{0}:root/{1}/{2}'
|
||||
OU_ARN_FORMAT = 'arn:aws:organizations::{0}:ou/{1}/{2}'
|
||||
SCP_ARN_FORMAT = 'arn:aws:organizations::{0}:policy/{1}/service_control_policy/{2}'
|
||||
MASTER_ACCOUNT_ID = "123456789012"
|
||||
MASTER_ACCOUNT_EMAIL = "master@example.com"
|
||||
DEFAULT_POLICY_ID = "p-FullAWSAccess"
|
||||
ORGANIZATION_ARN_FORMAT = "arn:aws:organizations::{0}:organization/{1}"
|
||||
MASTER_ACCOUNT_ARN_FORMAT = "arn:aws:organizations::{0}:account/{1}/{0}"
|
||||
ACCOUNT_ARN_FORMAT = "arn:aws:organizations::{0}:account/{1}/{2}"
|
||||
ROOT_ARN_FORMAT = "arn:aws:organizations::{0}:root/{1}/{2}"
|
||||
OU_ARN_FORMAT = "arn:aws:organizations::{0}:ou/{1}/{2}"
|
||||
SCP_ARN_FORMAT = "arn:aws:organizations::{0}:policy/{1}/service_control_policy/{2}"
|
||||
|
||||
CHARSET = string.ascii_lowercase + string.digits
|
||||
ORG_ID_SIZE = 10
|
||||
|
|
@ -22,26 +22,26 @@ CREATE_ACCOUNT_STATUS_ID_SIZE = 8
|
|||
SCP_ID_SIZE = 8
|
||||
|
||||
EMAIL_REGEX = "^.+@[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}|[0-9]{1,3}$"
|
||||
ORG_ID_REGEX = r'o-[a-z0-9]{%s}' % ORG_ID_SIZE
|
||||
ROOT_ID_REGEX = r'r-[a-z0-9]{%s}' % ROOT_ID_SIZE
|
||||
OU_ID_REGEX = r'ou-[a-z0-9]{%s}-[a-z0-9]{%s}' % (ROOT_ID_SIZE, OU_ID_SUFFIX_SIZE)
|
||||
ACCOUNT_ID_REGEX = r'[0-9]{%s}' % ACCOUNT_ID_SIZE
|
||||
CREATE_ACCOUNT_STATUS_ID_REGEX = r'car-[a-z0-9]{%s}' % CREATE_ACCOUNT_STATUS_ID_SIZE
|
||||
SCP_ID_REGEX = r'%s|p-[a-z0-9]{%s}' % (DEFAULT_POLICY_ID, SCP_ID_SIZE)
|
||||
ORG_ID_REGEX = r"o-[a-z0-9]{%s}" % ORG_ID_SIZE
|
||||
ROOT_ID_REGEX = r"r-[a-z0-9]{%s}" % ROOT_ID_SIZE
|
||||
OU_ID_REGEX = r"ou-[a-z0-9]{%s}-[a-z0-9]{%s}" % (ROOT_ID_SIZE, OU_ID_SUFFIX_SIZE)
|
||||
ACCOUNT_ID_REGEX = r"[0-9]{%s}" % ACCOUNT_ID_SIZE
|
||||
CREATE_ACCOUNT_STATUS_ID_REGEX = r"car-[a-z0-9]{%s}" % CREATE_ACCOUNT_STATUS_ID_SIZE
|
||||
SCP_ID_REGEX = r"%s|p-[a-z0-9]{%s}" % (DEFAULT_POLICY_ID, SCP_ID_SIZE)
|
||||
|
||||
|
||||
def make_random_org_id():
|
||||
# The regex pattern for an organization ID string requires "o-"
|
||||
# followed by from 10 to 32 lower-case letters or digits.
|
||||
# e.g. 'o-vipjnq5z86'
|
||||
return 'o-' + ''.join(random.choice(CHARSET) for x in range(ORG_ID_SIZE))
|
||||
return "o-" + "".join(random.choice(CHARSET) for x in range(ORG_ID_SIZE))
|
||||
|
||||
|
||||
def make_random_root_id():
|
||||
# The regex pattern for a root ID string requires "r-" followed by
|
||||
# from 4 to 32 lower-case letters or digits.
|
||||
# e.g. 'r-3zwx'
|
||||
return 'r-' + ''.join(random.choice(CHARSET) for x in range(ROOT_ID_SIZE))
|
||||
return "r-" + "".join(random.choice(CHARSET) for x in range(ROOT_ID_SIZE))
|
||||
|
||||
|
||||
def make_random_ou_id(root_id):
|
||||
|
|
@ -50,28 +50,32 @@ def make_random_ou_id(root_id):
|
|||
# that contains the OU) followed by a second "-" dash and from 8 to 32
|
||||
# additional lower-case letters or digits.
|
||||
# e.g. ou-g8sd-5oe3bjaw
|
||||
return '-'.join([
|
||||
'ou',
|
||||
root_id.partition('-')[2],
|
||||
''.join(random.choice(CHARSET) for x in range(OU_ID_SUFFIX_SIZE)),
|
||||
])
|
||||
return "-".join(
|
||||
[
|
||||
"ou",
|
||||
root_id.partition("-")[2],
|
||||
"".join(random.choice(CHARSET) for x in range(OU_ID_SUFFIX_SIZE)),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def make_random_account_id():
|
||||
# The regex pattern for an account ID string requires exactly 12 digits.
|
||||
# e.g. '488633172133'
|
||||
return ''.join([random.choice(string.digits) for n in range(ACCOUNT_ID_SIZE)])
|
||||
return "".join([random.choice(string.digits) for n in range(ACCOUNT_ID_SIZE)])
|
||||
|
||||
|
||||
def make_random_create_account_status_id():
|
||||
# The regex pattern for an create account request ID string requires
|
||||
# "car-" followed by from 8 to 32 lower-case letters or digits.
|
||||
# e.g. 'car-35gxzwrp'
|
||||
return 'car-' + ''.join(random.choice(CHARSET) for x in range(CREATE_ACCOUNT_STATUS_ID_SIZE))
|
||||
return "car-" + "".join(
|
||||
random.choice(CHARSET) for x in range(CREATE_ACCOUNT_STATUS_ID_SIZE)
|
||||
)
|
||||
|
||||
|
||||
def make_random_service_control_policy_id():
|
||||
# The regex pattern for a policy ID string requires "p-" followed by
|
||||
# from 8 to 128 lower-case letters or digits.
|
||||
# e.g. 'p-k2av4a8a'
|
||||
return 'p-' + ''.join(random.choice(CHARSET) for x in range(SCP_ID_SIZE))
|
||||
return "p-" + "".join(random.choice(CHARSET) for x in range(SCP_ID_SIZE))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue