organizations: add 2 more endpoints
create_organizational_unit describe_organizational_unit
This commit is contained in:
parent
6c0c6148f1
commit
beebb9abc8
4 changed files with 104 additions and 29 deletions
|
|
@ -12,6 +12,7 @@ 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}'
|
||||
|
||||
class FakeOrganization(BaseModel):
|
||||
|
||||
|
|
@ -95,32 +96,6 @@ class FakeAccount(BaseModel):
|
|||
}
|
||||
|
||||
|
||||
class FakeOrganizationalUnit(BaseModel):
|
||||
|
||||
def __init__(self, organization, **kwargs):
|
||||
self.organization_id = organization.id
|
||||
self.master_account_id = organization.master_account_id
|
||||
self.id = utils.make_random_ou_id()
|
||||
self.name = kwargs['Name']
|
||||
|
||||
@property
|
||||
def arn(self):
|
||||
return OU_ARN_FORMAT.format(
|
||||
self.master_account_id,
|
||||
self.organization_id,
|
||||
self.id
|
||||
)
|
||||
|
||||
def describe(self):
|
||||
return {
|
||||
'OrganizationalUnit': {
|
||||
'Id': self.id,
|
||||
'Arn': self.arn,
|
||||
'Name': self.name,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class FakeRoot(BaseModel):
|
||||
|
||||
def __init__(self, organization, **kwargs):
|
||||
|
|
@ -150,12 +125,40 @@ class FakeRoot(BaseModel):
|
|||
}
|
||||
|
||||
|
||||
|
||||
class FakeOrganizationalUnit(BaseModel):
|
||||
|
||||
def __init__(self, organization, root_id, **kwargs):
|
||||
self.organization_id = organization.id
|
||||
self.master_account_id = organization.master_account_id
|
||||
self.id = utils.make_random_ou_id(root_id)
|
||||
self.name = kwargs['Name']
|
||||
self.parent_id = kwargs['ParentId']
|
||||
|
||||
@property
|
||||
def arn(self):
|
||||
return OU_ARN_FORMAT.format(
|
||||
self.master_account_id,
|
||||
self.organization_id,
|
||||
self.id
|
||||
)
|
||||
|
||||
def describe(self):
|
||||
return {
|
||||
'OrganizationalUnit': {
|
||||
'Id': self.id,
|
||||
'Arn': self.arn,
|
||||
'Name': self.name,
|
||||
}
|
||||
}
|
||||
|
||||
class OrganizationsBackend(BaseBackend):
|
||||
|
||||
def __init__(self):
|
||||
self.org = None
|
||||
self.accounts = []
|
||||
self.roots = []
|
||||
self.ou = []
|
||||
|
||||
def create_organization(self, **kwargs):
|
||||
self.org = FakeOrganization(kwargs['FeatureSet'])
|
||||
|
|
@ -170,14 +173,27 @@ class OrganizationsBackend(BaseBackend):
|
|||
Roots=[root.describe() for root in self.roots]
|
||||
)
|
||||
|
||||
def create_organizational_unit(self, **kwargs):
|
||||
new_ou = FakeOrganizationalUnit(self.org, self.roots[0].id, **kwargs)
|
||||
self.ou.append(new_ou)
|
||||
return new_ou.describe()
|
||||
|
||||
def describe_organizational_unit(self, **kwargs):
|
||||
ou = [
|
||||
ou for ou in self.ou if ou.id == kwargs['OrganizationalUnitId']
|
||||
].pop(0)
|
||||
return ou.describe()
|
||||
|
||||
def create_account(self, **kwargs):
|
||||
new_account = FakeAccount(self.org, **kwargs)
|
||||
self.accounts.append(new_account)
|
||||
return new_account.create_account_status
|
||||
|
||||
def describe_account(self, **kwargs):
|
||||
account = [account for account in self.accounts
|
||||
if account.account_id == kwargs['AccountId']][0]
|
||||
account = [
|
||||
account for account in self.accounts
|
||||
if account.account_id == kwargs['AccountId']
|
||||
].pop(0)
|
||||
return account.describe()
|
||||
|
||||
def list_accounts(self):
|
||||
|
|
|
|||
|
|
@ -36,6 +36,16 @@ class OrganizationsResponse(BaseResponse):
|
|||
self.organizations_backend.list_roots()
|
||||
)
|
||||
|
||||
def create_organizational_unit(self):
|
||||
return json.dumps(
|
||||
self.organizations_backend.create_organizational_unit(**self.request_params)
|
||||
)
|
||||
|
||||
def describe_organizational_unit(self):
|
||||
return json.dumps(
|
||||
self.organizations_backend.describe_organizational_unit(**self.request_params)
|
||||
)
|
||||
|
||||
def create_account(self):
|
||||
return json.dumps(
|
||||
self.organizations_backend.create_account(**self.request_params)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue