grpc 1.33.0.pre1-universal-darwin → 1.37.0.pre1-universal-darwin
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/etc/roots.pem +257 -573
- data/src/ruby/ext/grpc/extconf.rb +10 -2
- data/src/ruby/ext/grpc/rb_channel.c +10 -1
- data/src/ruby/ext/grpc/rb_channel_credentials.c +11 -1
- data/src/ruby/ext/grpc/rb_channel_credentials.h +4 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +1 -1
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +1 -1
- data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc.c +4 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -14
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +70 -37
- data/src/ruby/ext/grpc/rb_server.c +13 -1
- data/src/ruby/ext/grpc/rb_server_credentials.c +19 -3
- data/src/ruby/ext/grpc/rb_server_credentials.h +4 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +215 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +35 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +35 -0
- data/src/ruby/lib/grpc/2.4/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/2.5/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/2.6/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +4 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +35 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +18 -0
- data/src/ruby/pb/test/xds_client.rb +166 -25
- data/src/ruby/spec/call_spec.rb +1 -1
- data/src/ruby/spec/channel_credentials_spec.rb +32 -0
- data/src/ruby/spec/channel_spec.rb +17 -6
- data/src/ruby/spec/client_auth_spec.rb +27 -1
- data/src/ruby/spec/errors_spec.rb +1 -1
- data/src/ruby/spec/generic/active_call_spec.rb +2 -2
- data/src/ruby/spec/generic/client_stub_spec.rb +4 -4
- data/src/ruby/spec/generic/rpc_server_spec.rb +1 -1
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +2 -6
- data/src/ruby/spec/server_credentials_spec.rb +25 -0
- data/src/ruby/spec/server_spec.rb +22 -0
- metadata +14 -11
- data/src/ruby/lib/grpc/2.3/grpc_c.bundle +0 -0
@@ -31,6 +31,7 @@
|
|
31
31
|
#include "rb_completion_queue.h"
|
32
32
|
#include "rb_grpc.h"
|
33
33
|
#include "rb_server_credentials.h"
|
34
|
+
#include "rb_xds_server_credentials.h"
|
34
35
|
|
35
36
|
/* grpc_rb_cServer is the ruby class that proxies grpc_server. */
|
36
37
|
static VALUE grpc_rb_cServer = Qnil;
|
@@ -326,7 +327,18 @@ static VALUE grpc_rb_server_add_http2_port(VALUE self, VALUE port,
|
|
326
327
|
StringValueCStr(port));
|
327
328
|
}
|
328
329
|
} else {
|
329
|
-
|
330
|
+
// TODO: create a common parent class for all server-side credentials,
|
331
|
+
// then we can have a single method to retrieve the underlying
|
332
|
+
// grpc_server_credentials object, and avoid the need for this reflection
|
333
|
+
if (grpc_rb_is_server_credentials(rb_creds)) {
|
334
|
+
creds = grpc_rb_get_wrapped_server_credentials(rb_creds);
|
335
|
+
} else if (grpc_rb_is_xds_server_credentials(rb_creds)) {
|
336
|
+
creds = grpc_rb_get_wrapped_xds_server_credentials(rb_creds);
|
337
|
+
} else {
|
338
|
+
rb_raise(rb_eTypeError,
|
339
|
+
"failed to create server because credentials parameter has an "
|
340
|
+
"invalid type, want ServerCredentials or XdsServerCredentials");
|
341
|
+
}
|
330
342
|
recvd_port = grpc_server_add_secure_http2_port(
|
331
343
|
s->wrapped, StringValueCStr(port), creds);
|
332
344
|
if (recvd_port == 0) {
|
@@ -42,7 +42,7 @@ typedef struct grpc_rb_server_credentials {
|
|
42
42
|
} grpc_rb_server_credentials;
|
43
43
|
|
44
44
|
/* Destroys the server credentials instances. */
|
45
|
-
static void
|
45
|
+
static void grpc_rb_server_credentials_free_internal(void* p) {
|
46
46
|
grpc_rb_server_credentials* wrapper = NULL;
|
47
47
|
if (p == NULL) {
|
48
48
|
return;
|
@@ -59,6 +59,12 @@ static void grpc_rb_server_credentials_free(void* p) {
|
|
59
59
|
xfree(p);
|
60
60
|
}
|
61
61
|
|
62
|
+
/* Destroys the server credentials instances. */
|
63
|
+
static void grpc_rb_server_credentials_free(void* p) {
|
64
|
+
grpc_rb_server_credentials_free_internal(p);
|
65
|
+
grpc_ruby_shutdown();
|
66
|
+
}
|
67
|
+
|
62
68
|
/* Protects the mark object from GC */
|
63
69
|
static void grpc_rb_server_credentials_mark(void* p) {
|
64
70
|
grpc_rb_server_credentials* wrapper = NULL;
|
@@ -87,9 +93,9 @@ static const rb_data_type_t grpc_rb_server_credentials_data_type = {
|
|
87
93
|
};
|
88
94
|
|
89
95
|
/* Allocates ServerCredential instances.
|
90
|
-
|
91
96
|
Provides safe initial defaults for the instance fields. */
|
92
97
|
static VALUE grpc_rb_server_credentials_alloc(VALUE cls) {
|
98
|
+
grpc_ruby_init();
|
93
99
|
grpc_rb_server_credentials* wrapper = ALLOC(grpc_rb_server_credentials);
|
94
100
|
wrapper->wrapped = NULL;
|
95
101
|
wrapper->mark = Qnil;
|
@@ -202,7 +208,11 @@ static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs,
|
|
202
208
|
}
|
203
209
|
xfree(key_cert_pairs);
|
204
210
|
if (creds == NULL) {
|
205
|
-
rb_raise(rb_eRuntimeError,
|
211
|
+
rb_raise(rb_eRuntimeError,
|
212
|
+
"the call to grpc_ssl_server_credentials_create_ex() failed, "
|
213
|
+
"could not create a credentials, see "
|
214
|
+
"https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
|
215
|
+
"debugging tips");
|
206
216
|
return Qnil;
|
207
217
|
}
|
208
218
|
wrapper->wrapped = creds;
|
@@ -237,7 +247,13 @@ void Init_grpc_server_credentials() {
|
|
237
247
|
/* Gets the wrapped grpc_server_credentials from the ruby wrapper */
|
238
248
|
grpc_server_credentials* grpc_rb_get_wrapped_server_credentials(VALUE v) {
|
239
249
|
grpc_rb_server_credentials* wrapper = NULL;
|
250
|
+
Check_TypedStruct(v, &grpc_rb_server_credentials_data_type);
|
240
251
|
TypedData_Get_Struct(v, grpc_rb_server_credentials,
|
241
252
|
&grpc_rb_server_credentials_data_type, wrapper);
|
242
253
|
return wrapper->wrapped;
|
243
254
|
}
|
255
|
+
|
256
|
+
/* Check if v is kind of ServerCredentials */
|
257
|
+
bool grpc_rb_is_server_credentials(VALUE v) {
|
258
|
+
return rb_typeddata_is_kind_of(v, &grpc_rb_server_credentials_data_type);
|
259
|
+
}
|
@@ -20,6 +20,7 @@
|
|
20
20
|
#define GRPC_RB_SERVER_CREDENTIALS_H_
|
21
21
|
|
22
22
|
#include <ruby/ruby.h>
|
23
|
+
#include <stdbool.h>
|
23
24
|
|
24
25
|
#include <grpc/grpc_security.h>
|
25
26
|
|
@@ -29,4 +30,7 @@ void Init_grpc_server_credentials();
|
|
29
30
|
/* Gets the wrapped server_credentials from the ruby wrapper */
|
30
31
|
grpc_server_credentials* grpc_rb_get_wrapped_server_credentials(VALUE v);
|
31
32
|
|
33
|
+
/* Check if v is kind of ServerCredentials */
|
34
|
+
bool grpc_rb_is_server_credentials(VALUE v);
|
35
|
+
|
32
36
|
#endif /* GRPC_RB_SERVER_CREDENTIALS_H_ */
|
@@ -0,0 +1,215 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2021 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <grpc/grpc.h>
|
20
|
+
#include <grpc/grpc_security.h>
|
21
|
+
#include <grpc/support/alloc.h>
|
22
|
+
#include <grpc/support/log.h>
|
23
|
+
#include <ruby/ruby.h>
|
24
|
+
#include <string.h>
|
25
|
+
|
26
|
+
#include "rb_call_credentials.h"
|
27
|
+
#include "rb_channel_credentials.h"
|
28
|
+
#include "rb_grpc.h"
|
29
|
+
#include "rb_grpc_imports.generated.h"
|
30
|
+
#include "rb_xds_channel_credentials.h"
|
31
|
+
|
32
|
+
/* grpc_rb_cXdsChannelCredentials is the ruby class that proxies
|
33
|
+
grpc_channel_credentials. */
|
34
|
+
static VALUE grpc_rb_cXdsChannelCredentials = Qnil;
|
35
|
+
|
36
|
+
/* grpc_rb_xds_channel_credentials wraps a grpc_channel_credentials. It
|
37
|
+
* provides a mark object that is used to hold references to any objects used to
|
38
|
+
* create the credentials. */
|
39
|
+
typedef struct grpc_rb_xds_channel_credentials {
|
40
|
+
/* Holder of ruby objects involved in constructing the credentials */
|
41
|
+
VALUE mark;
|
42
|
+
|
43
|
+
/* The actual credentials */
|
44
|
+
grpc_channel_credentials* wrapped;
|
45
|
+
} grpc_rb_xds_channel_credentials;
|
46
|
+
|
47
|
+
static void grpc_rb_xds_channel_credentials_free_internal(void* p) {
|
48
|
+
grpc_rb_xds_channel_credentials* wrapper = NULL;
|
49
|
+
if (p == NULL) {
|
50
|
+
return;
|
51
|
+
};
|
52
|
+
wrapper = (grpc_rb_xds_channel_credentials*)p;
|
53
|
+
grpc_channel_credentials_release(wrapper->wrapped);
|
54
|
+
wrapper->wrapped = NULL;
|
55
|
+
|
56
|
+
xfree(p);
|
57
|
+
}
|
58
|
+
|
59
|
+
/* Destroys the credentials instances. */
|
60
|
+
static void grpc_rb_xds_channel_credentials_free(void* p) {
|
61
|
+
grpc_rb_xds_channel_credentials_free_internal(p);
|
62
|
+
grpc_ruby_shutdown();
|
63
|
+
}
|
64
|
+
|
65
|
+
/* Protects the mark object from GC */
|
66
|
+
static void grpc_rb_xds_channel_credentials_mark(void* p) {
|
67
|
+
grpc_rb_xds_channel_credentials* wrapper = NULL;
|
68
|
+
if (p == NULL) {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
wrapper = (grpc_rb_xds_channel_credentials*)p;
|
72
|
+
|
73
|
+
if (wrapper->mark != Qnil) {
|
74
|
+
rb_gc_mark(wrapper->mark);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
static rb_data_type_t grpc_rb_xds_channel_credentials_data_type = {
|
79
|
+
"grpc_xds_channel_credentials",
|
80
|
+
{grpc_rb_xds_channel_credentials_mark, grpc_rb_xds_channel_credentials_free,
|
81
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE, NULL},
|
82
|
+
NULL,
|
83
|
+
NULL,
|
84
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
85
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
86
|
+
#endif
|
87
|
+
};
|
88
|
+
|
89
|
+
/* Allocates ChannelCredential instances.
|
90
|
+
Provides safe initial defaults for the instance fields. */
|
91
|
+
static VALUE grpc_rb_xds_channel_credentials_alloc(VALUE cls) {
|
92
|
+
grpc_ruby_init();
|
93
|
+
grpc_rb_xds_channel_credentials* wrapper =
|
94
|
+
ALLOC(grpc_rb_xds_channel_credentials);
|
95
|
+
wrapper->wrapped = NULL;
|
96
|
+
wrapper->mark = Qnil;
|
97
|
+
return TypedData_Wrap_Struct(cls, &grpc_rb_xds_channel_credentials_data_type,
|
98
|
+
wrapper);
|
99
|
+
}
|
100
|
+
|
101
|
+
/* Creates a wrapping object for a given channel credentials. This should only
|
102
|
+
* be called with grpc_channel_credentials objects that are not already
|
103
|
+
* associated with any Ruby object. */
|
104
|
+
VALUE grpc_rb_xds_wrap_channel_credentials(grpc_channel_credentials* c,
|
105
|
+
VALUE mark) {
|
106
|
+
grpc_rb_xds_channel_credentials* wrapper;
|
107
|
+
if (c == NULL) {
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
VALUE rb_wrapper =
|
111
|
+
grpc_rb_xds_channel_credentials_alloc(grpc_rb_cXdsChannelCredentials);
|
112
|
+
TypedData_Get_Struct(rb_wrapper, grpc_rb_xds_channel_credentials,
|
113
|
+
&grpc_rb_xds_channel_credentials_data_type, wrapper);
|
114
|
+
wrapper->wrapped = c;
|
115
|
+
wrapper->mark = mark;
|
116
|
+
return rb_wrapper;
|
117
|
+
}
|
118
|
+
|
119
|
+
/* The attribute used on the mark object to hold the fallback creds. */
|
120
|
+
static ID id_fallback_creds;
|
121
|
+
|
122
|
+
/*
|
123
|
+
call-seq:
|
124
|
+
fallback_creds: (ChannelCredentials) fallback credentials to create
|
125
|
+
XDS credentials
|
126
|
+
Initializes Credential instances. */
|
127
|
+
static VALUE grpc_rb_xds_channel_credentials_init(VALUE self,
|
128
|
+
VALUE fallback_creds) {
|
129
|
+
grpc_rb_xds_channel_credentials* wrapper = NULL;
|
130
|
+
grpc_channel_credentials* grpc_fallback_creds =
|
131
|
+
grpc_rb_get_wrapped_channel_credentials(fallback_creds);
|
132
|
+
grpc_channel_credentials* creds =
|
133
|
+
grpc_xds_credentials_create(grpc_fallback_creds);
|
134
|
+
if (creds == NULL) {
|
135
|
+
rb_raise(rb_eRuntimeError,
|
136
|
+
"the call to grpc_xds_credentials_create() failed, could not "
|
137
|
+
"create a credentials, , see "
|
138
|
+
"https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
|
139
|
+
"debugging tips");
|
140
|
+
return Qnil;
|
141
|
+
}
|
142
|
+
|
143
|
+
TypedData_Get_Struct(self, grpc_rb_xds_channel_credentials,
|
144
|
+
&grpc_rb_xds_channel_credentials_data_type, wrapper);
|
145
|
+
wrapper->wrapped = creds;
|
146
|
+
|
147
|
+
/* Add the input objects as hidden fields to preserve them. */
|
148
|
+
rb_ivar_set(self, id_fallback_creds, fallback_creds);
|
149
|
+
|
150
|
+
return self;
|
151
|
+
}
|
152
|
+
|
153
|
+
// TODO: de-duplicate this code with the similar method in
|
154
|
+
// rb_channel_credentials.c, after putting ChannelCredentials and
|
155
|
+
// XdsChannelCredentials under a common parent class
|
156
|
+
static VALUE grpc_rb_xds_channel_credentials_compose(int argc, VALUE* argv,
|
157
|
+
VALUE self) {
|
158
|
+
grpc_channel_credentials* creds;
|
159
|
+
grpc_call_credentials* other;
|
160
|
+
grpc_channel_credentials* prev = NULL;
|
161
|
+
VALUE mark;
|
162
|
+
if (argc == 0) {
|
163
|
+
return self;
|
164
|
+
}
|
165
|
+
mark = rb_ary_new();
|
166
|
+
rb_ary_push(mark, self);
|
167
|
+
creds = grpc_rb_get_wrapped_xds_channel_credentials(self);
|
168
|
+
for (int i = 0; i < argc; i++) {
|
169
|
+
rb_ary_push(mark, argv[i]);
|
170
|
+
other = grpc_rb_get_wrapped_call_credentials(argv[i]);
|
171
|
+
creds = grpc_composite_channel_credentials_create(creds, other, NULL);
|
172
|
+
if (prev != NULL) {
|
173
|
+
grpc_channel_credentials_release(prev);
|
174
|
+
}
|
175
|
+
prev = creds;
|
176
|
+
|
177
|
+
if (creds == NULL) {
|
178
|
+
rb_raise(rb_eRuntimeError,
|
179
|
+
"Failed to compose channel and call credentials");
|
180
|
+
}
|
181
|
+
}
|
182
|
+
return grpc_rb_xds_wrap_channel_credentials(creds, mark);
|
183
|
+
}
|
184
|
+
|
185
|
+
void Init_grpc_xds_channel_credentials() {
|
186
|
+
grpc_rb_cXdsChannelCredentials = rb_define_class_under(
|
187
|
+
grpc_rb_mGrpcCore, "XdsChannelCredentials", rb_cObject);
|
188
|
+
|
189
|
+
/* Allocates an object managed by the ruby runtime */
|
190
|
+
rb_define_alloc_func(grpc_rb_cXdsChannelCredentials,
|
191
|
+
grpc_rb_xds_channel_credentials_alloc);
|
192
|
+
|
193
|
+
/* Provides a ruby constructor and support for dup/clone. */
|
194
|
+
rb_define_method(grpc_rb_cXdsChannelCredentials, "initialize",
|
195
|
+
grpc_rb_xds_channel_credentials_init, 1);
|
196
|
+
rb_define_method(grpc_rb_cXdsChannelCredentials, "initialize_copy",
|
197
|
+
grpc_rb_cannot_init_copy, 1);
|
198
|
+
rb_define_method(grpc_rb_cXdsChannelCredentials, "compose",
|
199
|
+
grpc_rb_xds_channel_credentials_compose, -1);
|
200
|
+
|
201
|
+
id_fallback_creds = rb_intern("__fallback_creds");
|
202
|
+
}
|
203
|
+
|
204
|
+
/* Gets the wrapped grpc_channel_credentials from the ruby wrapper */
|
205
|
+
grpc_channel_credentials* grpc_rb_get_wrapped_xds_channel_credentials(VALUE v) {
|
206
|
+
grpc_rb_xds_channel_credentials* wrapper = NULL;
|
207
|
+
Check_TypedStruct(v, &grpc_rb_xds_channel_credentials_data_type);
|
208
|
+
TypedData_Get_Struct(v, grpc_rb_xds_channel_credentials,
|
209
|
+
&grpc_rb_xds_channel_credentials_data_type, wrapper);
|
210
|
+
return wrapper->wrapped;
|
211
|
+
}
|
212
|
+
|
213
|
+
bool grpc_rb_is_xds_channel_credentials(VALUE v) {
|
214
|
+
return rb_typeddata_is_kind_of(v, &grpc_rb_xds_channel_credentials_data_type);
|
215
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2021 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef GRPC_RB_XDS_CHANNEL_CREDENTIALS_H_
|
20
|
+
#define GRPC_RB_XDS_CHANNEL_CREDENTIALS_H_
|
21
|
+
|
22
|
+
#include <grpc/grpc_security.h>
|
23
|
+
#include <ruby/ruby.h>
|
24
|
+
#include <stdbool.h>
|
25
|
+
|
26
|
+
/* Initializes the ruby ChannelCredentials class. */
|
27
|
+
void Init_grpc_xds_channel_credentials();
|
28
|
+
|
29
|
+
/* Gets the wrapped credentials from the ruby wrapper */
|
30
|
+
grpc_channel_credentials* grpc_rb_get_wrapped_xds_channel_credentials(VALUE v);
|
31
|
+
|
32
|
+
/* Check if v is kind of XdsChannelCredentials */
|
33
|
+
bool grpc_rb_is_xds_channel_credentials(VALUE v);
|
34
|
+
|
35
|
+
#endif /* GRPC_RB_XDS_CHANNEL_CREDENTIALS_H_ */
|
@@ -0,0 +1,169 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2021 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "rb_xds_server_credentials.h"
|
20
|
+
|
21
|
+
#include <grpc/grpc.h>
|
22
|
+
#include <grpc/grpc_security.h>
|
23
|
+
#include <grpc/support/log.h>
|
24
|
+
#include <ruby/ruby.h>
|
25
|
+
|
26
|
+
#include "rb_grpc.h"
|
27
|
+
#include "rb_grpc_imports.generated.h"
|
28
|
+
#include "rb_server_credentials.h"
|
29
|
+
|
30
|
+
/* grpc_rb_cXdsServerCredentials is the ruby class that proxies
|
31
|
+
grpc_server_credentials. */
|
32
|
+
static VALUE grpc_rb_cXdsServerCredentials = Qnil;
|
33
|
+
|
34
|
+
/* grpc_rb_xds_server_credentials wraps a grpc_server_credentials. It provides
|
35
|
+
a peer ruby object, 'mark' to hold references to objects involved in
|
36
|
+
constructing the server credentials. */
|
37
|
+
typedef struct grpc_rb_xds_server_credentials {
|
38
|
+
/* Holder of ruby objects involved in constructing the server credentials */
|
39
|
+
VALUE mark;
|
40
|
+
/* The actual server credentials */
|
41
|
+
grpc_server_credentials* wrapped;
|
42
|
+
} grpc_rb_xds_server_credentials;
|
43
|
+
|
44
|
+
/* Destroys the server credentials instances. */
|
45
|
+
static void grpc_rb_xds_server_credentials_free_internal(void* p) {
|
46
|
+
grpc_rb_xds_server_credentials* wrapper = NULL;
|
47
|
+
if (p == NULL) {
|
48
|
+
return;
|
49
|
+
};
|
50
|
+
wrapper = (grpc_rb_xds_server_credentials*)p;
|
51
|
+
|
52
|
+
/* Delete the wrapped object if the mark object is Qnil, which indicates that
|
53
|
+
no other object is the actual owner. */
|
54
|
+
if (wrapper->wrapped != NULL && wrapper->mark == Qnil) {
|
55
|
+
grpc_server_credentials_release(wrapper->wrapped);
|
56
|
+
wrapper->wrapped = NULL;
|
57
|
+
}
|
58
|
+
|
59
|
+
xfree(p);
|
60
|
+
}
|
61
|
+
|
62
|
+
/* Destroys the server credentials instances. */
|
63
|
+
static void grpc_rb_xds_server_credentials_free(void* p) {
|
64
|
+
grpc_rb_xds_server_credentials_free_internal(p);
|
65
|
+
grpc_ruby_shutdown();
|
66
|
+
}
|
67
|
+
|
68
|
+
/* Protects the mark object from GC */
|
69
|
+
static void grpc_rb_xds_server_credentials_mark(void* p) {
|
70
|
+
if (p == NULL) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
grpc_rb_xds_server_credentials* wrapper = (grpc_rb_xds_server_credentials*)p;
|
74
|
+
|
75
|
+
/* If it's not already cleaned up, mark the mark object */
|
76
|
+
if (wrapper->mark != Qnil) {
|
77
|
+
rb_gc_mark(wrapper->mark);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
static const rb_data_type_t grpc_rb_xds_server_credentials_data_type = {
|
82
|
+
"grpc_xds_server_credentials",
|
83
|
+
{grpc_rb_xds_server_credentials_mark, grpc_rb_xds_server_credentials_free,
|
84
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE, NULL},
|
85
|
+
NULL,
|
86
|
+
NULL,
|
87
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
88
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
89
|
+
#endif
|
90
|
+
};
|
91
|
+
|
92
|
+
/* Allocates ServerCredential instances.
|
93
|
+
Provides safe initial defaults for the instance fields. */
|
94
|
+
static VALUE grpc_rb_xds_server_credentials_alloc(VALUE cls) {
|
95
|
+
grpc_ruby_init();
|
96
|
+
grpc_rb_xds_server_credentials* wrapper =
|
97
|
+
ALLOC(grpc_rb_xds_server_credentials);
|
98
|
+
wrapper->wrapped = NULL;
|
99
|
+
wrapper->mark = Qnil;
|
100
|
+
return TypedData_Wrap_Struct(cls, &grpc_rb_xds_server_credentials_data_type,
|
101
|
+
wrapper);
|
102
|
+
}
|
103
|
+
|
104
|
+
/* The attribute used on the mark object to preserve the fallback_creds. */
|
105
|
+
static ID id_fallback_creds;
|
106
|
+
|
107
|
+
/*
|
108
|
+
call-seq:
|
109
|
+
creds = ServerCredentials.new(fallback_creds)
|
110
|
+
fallback_creds: (ServerCredentials) fallback credentials to create
|
111
|
+
XDS credentials.
|
112
|
+
Initializes ServerCredential instances. */
|
113
|
+
static VALUE grpc_rb_xds_server_credentials_init(VALUE self,
|
114
|
+
VALUE fallback_creds) {
|
115
|
+
grpc_rb_xds_server_credentials* wrapper = NULL;
|
116
|
+
grpc_server_credentials* creds = NULL;
|
117
|
+
|
118
|
+
grpc_server_credentials* grpc_fallback_creds =
|
119
|
+
grpc_rb_get_wrapped_server_credentials(fallback_creds);
|
120
|
+
creds = grpc_xds_server_credentials_create(grpc_fallback_creds);
|
121
|
+
|
122
|
+
if (creds == NULL) {
|
123
|
+
rb_raise(rb_eRuntimeError,
|
124
|
+
"the call to grpc_xds_server_credentials_create() failed, could "
|
125
|
+
"not create a credentials, see "
|
126
|
+
"https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
|
127
|
+
"debugging tips");
|
128
|
+
return Qnil;
|
129
|
+
}
|
130
|
+
TypedData_Get_Struct(self, grpc_rb_xds_server_credentials,
|
131
|
+
&grpc_rb_xds_server_credentials_data_type, wrapper);
|
132
|
+
wrapper->wrapped = creds;
|
133
|
+
|
134
|
+
/* Add the input objects as hidden fields to preserve them. */
|
135
|
+
rb_ivar_set(self, id_fallback_creds, fallback_creds);
|
136
|
+
|
137
|
+
return self;
|
138
|
+
}
|
139
|
+
|
140
|
+
void Init_grpc_xds_server_credentials() {
|
141
|
+
grpc_rb_cXdsServerCredentials = rb_define_class_under(
|
142
|
+
grpc_rb_mGrpcCore, "XdsServerCredentials", rb_cObject);
|
143
|
+
|
144
|
+
/* Allocates an object managed by the ruby runtime */
|
145
|
+
rb_define_alloc_func(grpc_rb_cXdsServerCredentials,
|
146
|
+
grpc_rb_xds_server_credentials_alloc);
|
147
|
+
|
148
|
+
/* Provides a ruby constructor and support for dup/clone. */
|
149
|
+
rb_define_method(grpc_rb_cXdsServerCredentials, "initialize",
|
150
|
+
grpc_rb_xds_server_credentials_init, 1);
|
151
|
+
rb_define_method(grpc_rb_cXdsServerCredentials, "initialize_copy",
|
152
|
+
grpc_rb_cannot_init_copy, 1);
|
153
|
+
|
154
|
+
id_fallback_creds = rb_intern("__fallback_creds");
|
155
|
+
}
|
156
|
+
|
157
|
+
/* Gets the wrapped grpc_server_credentials from the ruby wrapper */
|
158
|
+
grpc_server_credentials* grpc_rb_get_wrapped_xds_server_credentials(VALUE v) {
|
159
|
+
grpc_rb_xds_server_credentials* wrapper = NULL;
|
160
|
+
Check_TypedStruct(v, &grpc_rb_xds_server_credentials_data_type);
|
161
|
+
TypedData_Get_Struct(v, grpc_rb_xds_server_credentials,
|
162
|
+
&grpc_rb_xds_server_credentials_data_type, wrapper);
|
163
|
+
return wrapper->wrapped;
|
164
|
+
}
|
165
|
+
|
166
|
+
/* Check if v is kind of ServerCredentials */
|
167
|
+
bool grpc_rb_is_xds_server_credentials(VALUE v) {
|
168
|
+
return rb_typeddata_is_kind_of(v, &grpc_rb_xds_server_credentials_data_type);
|
169
|
+
}
|