More plumbing work through creds framework

pull/1888/head
Craig Tiller 10 years ago
parent 6a29aa051b
commit ca22c972b0
  1. 7
      src/core/httpcli/httpcli.c
  2. 15
      src/core/security/credentials.c

@ -59,6 +59,7 @@ typedef struct {
int use_ssl;
grpc_httpcli_response_cb on_response;
void *user_data;
grpc_pollset_set *interested_parties;
} internal_request;
static grpc_httpcli_get_override g_get_override = NULL;
@ -206,7 +207,7 @@ static void next_address(internal_request *req) {
return;
}
addr = &req->addresses->addrs[req->next_address++];
grpc_tcp_client_connect(on_connected, req, (struct sockaddr *)&addr->addr,
grpc_tcp_client_connect(on_connected, req, req->interested_parties, (struct sockaddr *)&addr->addr,
addr->len, req->deadline);
}
@ -224,6 +225,7 @@ static void on_resolved(void *arg, grpc_resolved_addresses *addresses) {
void grpc_httpcli_get(const grpc_httpcli_request *request,
gpr_timespec deadline,
grpc_pollset_set *interested_parties,
grpc_httpcli_response_cb on_response, void *user_data) {
internal_request *req;
if (g_get_override &&
@ -238,6 +240,7 @@ void grpc_httpcli_get(const grpc_httpcli_request *request,
req->user_data = user_data;
req->deadline = deadline;
req->use_ssl = request->use_ssl;
req->interested_parties = interested_parties;
if (req->use_ssl) {
req->host = gpr_strdup(request->host);
}
@ -249,6 +252,7 @@ void grpc_httpcli_get(const grpc_httpcli_request *request,
void grpc_httpcli_post(const grpc_httpcli_request *request,
const char *body_bytes, size_t body_size,
gpr_timespec deadline,
grpc_pollset_set *interested_parties,
grpc_httpcli_response_cb on_response, void *user_data) {
internal_request *req;
if (g_post_override && g_post_override(request, body_bytes, body_size,
@ -264,6 +268,7 @@ void grpc_httpcli_post(const grpc_httpcli_request *request,
req->user_data = user_data;
req->deadline = deadline;
req->use_ssl = request->use_ssl;
req->interested_parties = interested_parties;
if (req->use_ssl) {
req->host = gpr_strdup(request->host);
}

@ -470,6 +470,7 @@ grpc_credentials *grpc_jwt_credentials_create(const char *json_key,
from an http service. */
typedef void (*grpc_fetch_oauth2_func)(grpc_credentials_metadata_request *req,
grpc_pollset_set *interested_parties,
grpc_httpcli_response_cb response_cb,
gpr_timespec deadline);
@ -479,6 +480,7 @@ typedef struct {
grpc_mdctx *md_ctx;
grpc_mdelem *access_token_md;
gpr_timespec token_expiration;
grpc_pollset_set pollset_set;
grpc_fetch_oauth2_func fetch_func;
} grpc_oauth2_token_fetcher_credentials;
@ -490,6 +492,7 @@ static void oauth2_token_fetcher_destroy(grpc_credentials *creds) {
}
gpr_mu_destroy(&c->mu);
grpc_mdctx_unref(c->md_ctx);
grpc_pollset_set_destroy(&c->pollset_set);
gpr_free(c);
}
@ -637,6 +640,7 @@ static void oauth2_token_fetcher_get_request_metadata(
} else {
c->fetch_func(
grpc_credentials_metadata_request_create(creds, cb, user_data),
&c->pollset_set,
on_oauth2_token_fetcher_http_response,
gpr_time_add(gpr_now(), refresh_threshold));
}
@ -651,6 +655,7 @@ static void init_oauth2_token_fetcher(grpc_oauth2_token_fetcher_credentials *c,
c->md_ctx = grpc_mdctx_create();
c->token_expiration = gpr_inf_past;
c->fetch_func = fetch_func;
grpc_pollset_set_init(&c->pollset_set);
}
static grpc_mdctx *oauth2_token_fetcher_get_metadata_context(
@ -670,6 +675,7 @@ static grpc_credentials_vtable compute_engine_vtable = {
static void compute_engine_fetch_oauth2(
grpc_credentials_metadata_request *metadata_req,
grpc_pollset_set *interested_parties,
grpc_httpcli_response_cb response_cb, gpr_timespec deadline) {
grpc_httpcli_header header = {"Metadata-Flavor", "Google"};
grpc_httpcli_request request;
@ -678,7 +684,7 @@ static void compute_engine_fetch_oauth2(
request.path = GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH;
request.hdr_count = 1;
request.hdrs = &header;
grpc_httpcli_get(&request, deadline, response_cb, metadata_req);
grpc_httpcli_get(&request, deadline, interested_parties, response_cb, metadata_req);
}
grpc_credentials *grpc_compute_engine_credentials_create(void) {
@ -714,7 +720,7 @@ static grpc_credentials_vtable service_account_vtable = {
static void service_account_fetch_oauth2(
grpc_credentials_metadata_request *metadata_req,
grpc_httpcli_response_cb response_cb, gpr_timespec deadline) {
grpc_pollset_set *interested_parties, grpc_httpcli_response_cb response_cb, gpr_timespec deadline) {
grpc_service_account_credentials *c =
(grpc_service_account_credentials *)metadata_req->creds;
grpc_httpcli_header header = {"Content-Type",
@ -739,7 +745,7 @@ static void service_account_fetch_oauth2(
request.hdr_count = 1;
request.hdrs = &header;
request.use_ssl = 1;
grpc_httpcli_post(&request, body, strlen(body), deadline, response_cb,
grpc_httpcli_post(&request, body, strlen(body), deadline, &c->base.pollset_set, response_cb,
metadata_req);
gpr_free(body);
gpr_free(jwt);
@ -788,6 +794,7 @@ static grpc_credentials_vtable refresh_token_vtable = {
static void refresh_token_fetch_oauth2(
grpc_credentials_metadata_request *metadata_req,
grpc_pollset_set *interested_parties,
grpc_httpcli_response_cb response_cb, gpr_timespec deadline) {
grpc_refresh_token_credentials *c =
(grpc_refresh_token_credentials *)metadata_req->creds;
@ -804,7 +811,7 @@ static void refresh_token_fetch_oauth2(
request.hdr_count = 1;
request.hdrs = &header;
request.use_ssl = 1;
grpc_httpcli_post(&request, body, strlen(body), deadline, response_cb,
grpc_httpcli_post(&request, body, strlen(body), deadline, interested_parties, response_cb,
metadata_req);
gpr_free(body);
}

Loading…
Cancel
Save