Пример #1
0
def proxy_api(role, _job_id, request_config):
    job_id = request_config.get('header').get('job_id', _job_id)
    method = request_config.get('header').get('method', 'POST')
    endpoint = request_config.get('header').get('endpoint')
    src_party_id = request_config.get('header').get('src_party_id')
    dest_party_id = request_config.get('header').get('dest_party_id')
    json_body = request_config.get('body')
    _packet = forward_grpc_packet(
        json_body,
        method,
        endpoint,
        src_party_id,
        dest_party_id,
        job_id=job_id,
        role=role,
        overall_timeout=DEFAULT_REMOTE_REQUEST_TIMEOUT)
    _routing_metadata = gen_routing_metadata(src_party_id=src_party_id,
                                             dest_party_id=dest_party_id)
    host, port, protocol = get_federated_proxy_address(src_party_id,
                                                       dest_party_id)
    channel, stub = get_command_federation_channel(host, port)
    _return, _call = stub.unaryCall.with_call(_packet,
                                              metadata=_routing_metadata)
    channel.close()
    json_body = json_loads(_return.body.value)
    return json_body
Пример #2
0
def forward_api(job_id,
                method,
                endpoint,
                src_party_id,
                dest_party_id,
                json_body,
                role,
                overall_timeout=DEFAULT_GRPC_OVERALL_TIMEOUT):
    _packet = forward_grpc_packet(json_body,
                                  method,
                                  endpoint,
                                  src_party_id,
                                  dest_party_id,
                                  job_id=job_id,
                                  role=role,
                                  overall_timeout=overall_timeout)

    channel, stub = get_proxy_data_channel()
    _return = stub.unaryCall(_packet)
    channel.close()
    json_body = json.loads(_return.body.value)
    return json_body