diff options
author | yangg <yangg@google.com> | 2015-01-09 14:19:44 -0800 |
---|---|---|
committer | Nicolas Noble <nnoble@google.com> | 2015-01-12 11:22:01 -0800 |
commit | 4105e2b86c91ecc3687def3abcbb602bee894b0a (patch) | |
tree | dbeed01da6a51b69f0a7651cac16541b99c293c5 /src/core | |
parent | 5d61ac074c26a1631cfdbd34d590c730139a9de6 (diff) |
Add ServiceAccount Credentials wrapping and handle credentials creation
failure.
Change on 2015/01/09 by yangg <yangg@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=83634736
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/security/security_context.c | 12 | ||||
-rw-r--r-- | src/core/surface/lame_client.c | 29 |
2 files changed, 35 insertions, 6 deletions
diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c index 13b9a847ee..917a22f453 100644 --- a/src/core/security/security_context.c +++ b/src/core/security/security_context.c @@ -451,7 +451,7 @@ static grpc_channel *grpc_ssl_channel_create(grpc_credentials *creds, grpc_security_status status = GRPC_SECURITY_OK; size_t i = 0; const char *secure_peer_name = target; - for (i = 0; i < args->num_args; i++) { + for (i = 0; args && i < args->num_args; i++) { grpc_arg *arg = &args->args[i]; if (!strcmp(arg->key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) && arg->type == GRPC_ARG_STRING) { @@ -492,12 +492,17 @@ static grpc_channel *grpc_channel_create_from_composite_creds( return grpc_ssl_channel_create( composite_creds, grpc_ssl_credentials_get_config(creds), target, args); } - return NULL; /* TODO(ctiller): return lame channel. */ + gpr_log(GPR_ERROR, "Credentials is insufficient to create a secure channel."); + return grpc_lame_client_channel_create(); } grpc_channel *grpc_secure_channel_create(grpc_credentials *creds, const char *target, const grpc_channel_args *args) { + if (creds == NULL) { + gpr_log(GPR_ERROR, "No credentials to create a secure channel."); + return grpc_lame_client_channel_create(); + } if (grpc_credentials_has_request_metadata_only(creds)) { gpr_log(GPR_ERROR, "Credentials is insufficient to create a secure channel."); @@ -518,7 +523,8 @@ grpc_channel *grpc_secure_channel_create(grpc_credentials *creds, return grpc_channel_create_from_composite_creds(creds, target, args); } else { gpr_log(GPR_ERROR, - "Unknown credentials type %s for creating a secure channel."); + "Unknown credentials type %s for creating a secure channel.", + creds->type); return grpc_lame_client_channel_create(); } } diff --git a/src/core/surface/lame_client.c b/src/core/surface/lame_client.c index 6a832436ca..5fa3e42362 100644 --- a/src/core/surface/lame_client.c +++ b/src/core/surface/lame_client.c @@ -33,6 +33,8 @@ #include "src/core/surface/lame_client.h" +#include <string.h> + #include "src/core/channel/channel_stack.h" #include "src/core/surface/channel.h" #include "src/core/surface/call.h" @@ -42,16 +44,28 @@ typedef struct { void *unused; } call_data; -typedef struct { void *unused; } channel_data; +typedef struct { grpc_mdelem *message; } channel_data; + +static void do_nothing(void *data, grpc_op_error error) {} static void call_op(grpc_call_element *elem, grpc_call_element *from_elem, grpc_call_op *op) { + channel_data *channeld = elem->channel_data; GRPC_CALL_LOG_OP(GPR_INFO, elem, op); switch (op->type) { - case GRPC_SEND_START: + case GRPC_SEND_START: { + grpc_call_op set_status_op; + grpc_mdelem_ref(channeld->message); + memset(&set_status_op, 0, sizeof(grpc_call_op)); + set_status_op.dir = GRPC_CALL_UP; + set_status_op.type = GRPC_RECV_METADATA; + set_status_op.done_cb = do_nothing; + set_status_op.data.metadata = channeld->message; + grpc_call_recv_metadata(elem, &set_status_op); grpc_call_recv_finish(elem, 1); break; + } case GRPC_SEND_METADATA: grpc_mdelem_unref(op->data.metadata); break; @@ -81,11 +95,20 @@ static void destroy_call_elem(grpc_call_element *elem) {} static void init_channel_elem(grpc_channel_element *elem, const grpc_channel_args *args, grpc_mdctx *mdctx, int is_first, int is_last) { + channel_data *channeld = elem->channel_data; + GPR_ASSERT(is_first); GPR_ASSERT(is_last); + + channeld->message = grpc_mdelem_from_strings(mdctx, "grpc-message", + "Rpc sent on a lame channel."); } -static void destroy_channel_elem(grpc_channel_element *elem) {} +static void destroy_channel_elem(grpc_channel_element *elem) { + channel_data *channeld = elem->channel_data; + + grpc_mdelem_unref(channeld->message); +} static const grpc_channel_filter lame_filter = { call_op, channel_op, |