コード例 #1
0
def get_openip_health_status() -> dict:
    status = requests.get(
        furl(scheme="https",
             host=Config.get_openid_provider(),
             path="/testall").url).status_code
    status = 'ok' if status == 200 else 'unhealthy'
    return dict(openip_health_status=status)
コード例 #2
0
 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
コード例 #3
0
 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.")
コード例 #4
0
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)
コード例 #5
0
    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()
コード例 #6
0
def get_service_jwt(service_credentials, email=True, audience=None):
    iat = time.time()
    exp = iat + 3600
    payload = {'iss': service_credentials["client_email"],
               'sub': service_credentials["client_email"],
               'aud': audience or Config.get_audience(),
               'iat': iat,
               'exp': exp,
               'scope': ['email', 'openid', 'offline_access'],
               }
    if email:
        payload['https://auth.data.humancellatlas.org/email'] = service_credentials["client_email"]
    additional_headers = {'kid': service_credentials["private_key_id"]}
    signed_jwt = jwt.encode(payload, service_credentials["private_key"], headers=additional_headers,
                            algorithm='RS256').decode()
    return signed_jwt
コード例 #7
0
 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
コード例 #8
0
 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