def get_types(cls): if not cls._resource_types: cd = Config.get_directory() cls._resource_types = [ name for name, _ in cd.list_object_children(f'/{cls.object_type}/') ] return cls._resource_types
def _exists(cls, nodes: List[str]): operations = [] directory = Config.get_directory() try: for node in nodes: operations.append( directory.batch_get_object_info(cls(node).object_ref)) directory.batch_read(operations) except cd_client.exceptions.ResourceNotFoundException: raise FusilladeBadRequestException( f"One or more {cls.object_type} does not exist.")
def health_check(*args, **kwargs): health_checks = dict() health_checks.update(**Config.get_directory().health_checks(), **get_openip_health_status(), **authorize.health_checks()) if all([check == 'ok' for check in health_checks.values()]): body = dict(health_status='ok', services=health_checks) status = 200 headers = {"Content-Type": "application/json"} else: body = dict(health_status='unhealthy', services=health_checks) status = 500 headers = {"Content-Type": "application/json+problem"} return ConnexionResponse(status_code=status, headers=headers, body=body)
def __init__(self, name: str = None, object_ref: str = None): """ :param name: :param object_ref: """ self.cd: CloudDirectory = Config.get_directory() if name and object_ref: raise FusilladeException("object_reference XOR name") if name: self.from_name(name) else: self._name: str = None self._path_name: str = None self.object_ref: str = object_ref self.attached_policies: Dict[str, str] = dict()
def get_names(cls, obj_refs: List[str]) -> List[str]: cd = Config.get_directory() operations = [ cd.batch_get_attributes(obj_ref, cls._facet, ['name']) for obj_ref in obj_refs ] results = [] for r in cd.batch_read(operations)['Responses']: if r.get('SuccessfulResponse'): results.append( r.get('SuccessfulResponse')['GetObjectAttributes'] ['Attributes'][0]['Value']['StringValue']) else: logger.error({ "message": "Batch Request Failed", "response": r }) # log error request failed return results
def list_all(cls, next_token: str = None, per_page: int = None): cd = Config.get_directory() resp, next_token = cd.list_object_children_paged( f'/{cls.object_type}/', next_token, per_page) operations = [ cd.batch_get_attributes(f'${obj_ref}', cls._facet, ['name']) for obj_ref in resp.values() ] results = [] for r in cd.batch_read(operations)['Responses']: if r.get('SuccessfulResponse'): results.append( r.get('SuccessfulResponse')['GetObjectAttributes'] ['Attributes'][0]['Value']['StringValue']) else: logger.error({ "message": "Batch Request Failed", "response": r }) # log error request failed return {f"{cls.object_type}s": results}, next_token