def add_principals(self, principals): for principal in principals: match = re.search( r"^arn:aws:organizations::\d{12}:organization/(o-\w+)$", principal ) if match: organization = self.organizations_backend.describe_organization() if principal == organization["Organization"]["Arn"]: continue else: raise UnknownResourceException( "Organization {} could not be found.".format(match.group(1)) ) match = re.search( r"^arn:aws:organizations::\d{12}:ou/(o-\w+)/(ou-[\w-]+)$", principal ) if match: roots = self.organizations_backend.list_roots() root_id = next( ( root["Id"] for root in roots["Roots"] if root["Name"] == "Root" and match.group(1) in root["Arn"] ), None, ) if root_id: ( ous, _, ) = self.organizations_backend.list_organizational_units_for_parent( parent_id=root_id ) if any(principal == ou["Arn"] for ou in ous): continue raise UnknownResourceException( "OrganizationalUnit {} in unknown organization could not be found.".format( match.group(2) ) ) if not re.match(r"^\d{12}$", principal): raise InvalidParameterException( "Principal ID {} is malformed. " "Verify the ID and try again.".format(principal) ) for principal in principals: self.principals.append(principal)
def delete_resource_share(self, arn): resource = next( (resource for resource in self.resource_shares if arn == resource.arn), None) if not resource: raise UnknownResourceException( "ResourceShare {} could not be found.".format(arn)) resource.delete() return dict(returnValue=True)
def update_resource_share(self, **kwargs): arn = kwargs["resourceShareArn"] resource = next( (resource for resource in self.resource_shares if arn == resource.arn), None) if not resource: raise UnknownResourceException( "ResourceShare {} could not be found.".format(arn)) resource.update(**kwargs) response = resource.describe() response.pop("featureSet") return dict(resourceShare=response)