Fixed bug with composing credentials

pull/4289/head
murgatroid99 9 years ago
parent ca72d6cd3d
commit e389b04336
  1. 31
      src/ruby/ext/grpc/rb_call_credentials.c
  2. 32
      src/ruby/ext/grpc/rb_channel_credentials.c

@ -179,17 +179,6 @@ static rb_data_type_t grpc_rb_call_credentials_data_type = {
#endif
};
/* Creates a wrapping object for a given call credentials. This should only be
* called with grpc_call_credentials objects that are not already associated
* with any Ruby object */
VALUE grpc_rb_wrap_call_credentials(grpc_call_credentials *c) {
if (c == NULL) {
return Qnil;
}
return TypedData_Wrap_Struct(grpc_rb_cCallCredentials,
&grpc_rb_call_credentials_data_type, c);
}
/* Allocates CallCredentials instances.
Provides safe initial defaults for the instance fields. */
static VALUE grpc_rb_call_credentials_alloc(VALUE cls) {
@ -199,6 +188,22 @@ static VALUE grpc_rb_call_credentials_alloc(VALUE cls) {
return TypedData_Wrap_Struct(cls, &grpc_rb_call_credentials_data_type, wrapper);
}
/* Creates a wrapping object for a given call credentials. This should only be
* called with grpc_call_credentials objects that are not already associated
* with any Ruby object */
VALUE grpc_rb_wrap_call_credentials(grpc_call_credentials *c) {
VALUE rb_wrapper;
grpc_rb_call_credentials *wrapper;
if (c == NULL) {
return Qnil;
}
rb_wrapper = grpc_rb_call_credentials_alloc(grpc_rb_cCallCredentials);
TypedData_Get_Struct(rb_wrapper, grpc_rb_call_credentials,
&grpc_rb_call_credentials_data_type, wrapper);
wrapper->wrapped = c;
return rb_wrapper;
}
/* Clones CallCredentials instances.
Gives CallCredentials a consistent implementation of Ruby's object copy/dup
protocol. */
@ -246,6 +251,10 @@ static VALUE grpc_rb_call_credentials_init(VALUE self, VALUE proc) {
plugin.get_metadata = grpc_rb_call_credentials_plugin_get_metadata;
plugin.destroy = grpc_rb_call_credentials_plugin_destroy;
if (!rb_obj_is_proc(proc)) {
rb_raise(rb_eTypeError, "Argument to CallCredentials#new must be a proc");
return Qnil;
}
plugin.state = (void*)proc;
plugin.type = "";

@ -37,6 +37,7 @@
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include "rb_call_credentials.h"
#include "rb_grpc.h"
@ -99,17 +100,6 @@ static rb_data_type_t grpc_rb_channel_credentials_data_type = {
#endif
};
/* Creates a wrapping object for a given channel credentials. This should only
* be called with grpc_channel_credentials objects that are not already
* associated with any Ruby object. */
VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c) {
if (c == NULL) {
return Qnil;
}
return TypedData_Wrap_Struct(grpc_rb_cChannelCredentials,
&grpc_rb_channel_credentials_data_type, c);
}
/* Allocates ChannelCredential instances.
Provides safe initial defaults for the instance fields. */
static VALUE grpc_rb_channel_credentials_alloc(VALUE cls) {
@ -119,6 +109,22 @@ static VALUE grpc_rb_channel_credentials_alloc(VALUE cls) {
return TypedData_Wrap_Struct(cls, &grpc_rb_channel_credentials_data_type, wrapper);
}
/* Creates a wrapping object for a given channel credentials. This should only
* be called with grpc_channel_credentials objects that are not already
* associated with any Ruby object. */
VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c) {
VALUE rb_wrapper;
grpc_rb_channel_credentials *wrapper;
if (c == NULL) {
return Qnil;
}
rb_wrapper = grpc_rb_channel_credentials_alloc(grpc_rb_cChannelCredentials);
TypedData_Get_Struct(rb_wrapper, grpc_rb_channel_credentials,
&grpc_rb_channel_credentials_data_type, wrapper);
wrapper->wrapped = c;
return rb_wrapper;
}
/* Clones ChannelCredentials instances.
Gives ChannelCredentials a consistent implementation of Ruby's object copy/dup
protocol. */
@ -222,6 +228,10 @@ static VALUE grpc_rb_channel_credentials_compose(int argc, VALUE *argv,
for (int i = 0; i < argc; i++) {
other = grpc_rb_get_wrapped_call_credentials(argv[i]);
creds = grpc_composite_channel_credentials_create(creds, other, NULL);
if (creds == NULL) {
rb_raise(rb_eRuntimeError,
"Failed to compose channel and call credentials");
}
}
return grpc_rb_wrap_channel_credentials(creds);
}

Loading…
Cancel
Save