Exemplo n.º 1
0
def get_governance_info_from_request(request_type='', json_params=None):
    # Default values for governance headers.
    actor_id = DEFAULT_ACTOR_ID
    expiry = DEFAULT_EXPIRY
    authtoken = ""
    if not json_params:
        if 'requester' in request.args:
            actor_id = str(request.args['requester'])
        if 'expiry' in request.args:
            expiry = str(request.args['expiry'])
        if 'authtoken' in request.args:
            authtoken = str(request.args['authtoken'])

    else:
        if 'requester' in json_params[request_type]:
            actor_id = json_params[request_type]['requester']
        if 'expiry' in json_params[request_type]:
            expiry = json_params[request_type]['expiry']
        if 'authtoken' in json_params[request_type]:
            authtoken = json_params[request_type]['authtoken']

    # R2 M185 - Enable temporary authentication tokens to resolve to actor ids
    if authtoken:
        idm_client = IdentityManagementServiceProcessClient(process=service_gateway_instance)
        try:
            token_info = idm_client.check_authentication_token(authtoken,
                                                               headers={"ion-actor-id": service_gateway_instance.name,
                                                                        'expiry': DEFAULT_EXPIRY})
            actor_id = token_info.get("actor_id", actor_id)
            expiry = token_info.get("expiry", expiry)
            log.info("Resolved token %s into actor id=%s expiry=%s", authtoken, actor_id, expiry)
        except NotFound:
            log.info("Provided authentication token not found: %s", authtoken)
        except Unauthorized:
            log.info("Authentication token expired or invalid: %s", authtoken)
        except Exception as ex:
            log.exception("Problem resolving authentication token")

    return actor_id, expiry