in modular_sdk/services/parent_service.py [0:0]
def build(self, application_id: str, customer_id: str,
parent_type: ParentType, created_by: str,
is_deleted: bool = False, description: Optional[str] = None,
meta: Optional[dict] = None,
scope: Optional[ParentScope] = None,
tenant_name: Optional[str] = None,
cloud: Optional[str] = None) -> Parent:
"""
Make sure to provide valid scope, tenant_name and cloud. Or
use specific methods: create_all_scope, create_tenant_scope
:param application_id:
:param customer_id:
:param parent_type:
:param is_deleted:
:param description:
:param meta:
:param scope:
:param tenant_name:
:param cloud:
:param created_by:
:return:
"""
# TODO either move validation from here to outside or make the
# validation decent (what if application by id does not exist,
# what if meta for this parent_type is not valid?, ...)
if parent_type not in ALL_PARENT_TYPES:
_LOG.warning(f'Invalid parent type specified \'{parent_type}\'. '
f'Available options: {ALL_PARENT_TYPES}')
raise ModularException(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'Invalid parent type specified \'{parent_type}\'. '
f'Available options are: {ALL_PARENT_TYPES}'
)
customer = self.customer_service.get(name=customer_id)
if not customer:
_LOG.error(f'Customer with name \'{customer_id}\' does not exist')
raise ModularException(
code=RESPONSE_RESOURCE_NOT_FOUND_CODE,
content=f'Customer with name \'{customer_id}\' does not exist'
)
return self._create(
customer_id=customer_id,
application_id=application_id,
type_=parent_type,
description=description,
meta=meta,
is_deleted=is_deleted,
scope=scope,
tenant_name=tenant_name,
cloud=cloud,
created_by=created_by
)