grpc 1.35.0-universal-darwin → 1.38.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.

Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/src/ruby/bin/math_services_pb.rb +1 -1
  3. data/src/ruby/ext/grpc/extconf.rb +9 -1
  4. data/src/ruby/ext/grpc/rb_channel.c +10 -1
  5. data/src/ruby/ext/grpc/rb_channel_credentials.c +11 -1
  6. data/src/ruby/ext/grpc/rb_channel_credentials.h +4 -0
  7. data/src/ruby/ext/grpc/rb_compression_options.c +1 -1
  8. data/src/ruby/ext/grpc/rb_enable_cpp.cc +1 -1
  9. data/src/ruby/ext/grpc/rb_grpc.c +4 -0
  10. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  11. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  12. data/src/ruby/ext/grpc/rb_server.c +13 -1
  13. data/src/ruby/ext/grpc/rb_server_credentials.c +19 -3
  14. data/src/ruby/ext/grpc/rb_server_credentials.h +4 -0
  15. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +215 -0
  16. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +35 -0
  17. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
  18. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +35 -0
  19. data/src/ruby/lib/grpc/2.4/grpc_c.bundle +0 -0
  20. data/src/ruby/lib/grpc/2.5/grpc_c.bundle +0 -0
  21. data/src/ruby/lib/grpc/2.6/grpc_c.bundle +0 -0
  22. data/src/ruby/lib/grpc/2.7/grpc_c.bundle +0 -0
  23. data/src/ruby/lib/grpc/3.0/grpc_c.bundle +0 -0
  24. data/src/ruby/lib/grpc/generic/client_stub.rb +4 -2
  25. data/src/ruby/lib/grpc/version.rb +1 -1
  26. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +1 -1
  27. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +7 -0
  28. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +6 -6
  29. data/src/ruby/pb/test/xds_client.rb +41 -27
  30. data/src/ruby/spec/call_spec.rb +1 -1
  31. data/src/ruby/spec/channel_credentials_spec.rb +32 -0
  32. data/src/ruby/spec/channel_spec.rb +17 -6
  33. data/src/ruby/spec/client_auth_spec.rb +27 -1
  34. data/src/ruby/spec/errors_spec.rb +1 -1
  35. data/src/ruby/spec/generic/active_call_spec.rb +2 -2
  36. data/src/ruby/spec/generic/client_stub_spec.rb +4 -4
  37. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -1
  38. data/src/ruby/spec/server_credentials_spec.rb +25 -0
  39. data/src/ruby/spec/server_spec.rb +22 -0
  40. metadata +13 -9
  41. data/src/ruby/lib/grpc/2.3/grpc_c.bundle +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e3ce6d44e19d84008be35c73d03e5fd1f44f6641eef6dba79c7292513c9cb11
4
- data.tar.gz: ce42cb68eb77fe75c54f6df71b744aa030a9e7ee43d48be242284e87c1b97491
3
+ metadata.gz: e3d0e7e9221d4ebf0170e83dbdb9aa6f66ad38c8fd53bd9f609aea97449904a9
4
+ data.tar.gz: 90ae8be1aaac07d858e972996d5718f156e56e5e601c7da171d886e62716398d
5
5
  SHA512:
6
- metadata.gz: 9d10bedcb3cd16ba4b05c66891c61f2d90f032063bf147d50b16d528061b4a28875e80a3f4bbcdd930d905fac9f439675ad534aed744483cba9a42dd1b7a4f21
7
- data.tar.gz: b7c714042bd36c51d67dc78090460df065b2c05598a27d702c022a076abd98cbbde9cb57b38b7c8ae7916fbffab89d35c917389fac12f0cea49ccc5352c68b0d
6
+ metadata.gz: 0e027bc53cb64a8821b1b8858c0978f8c838a2f7475f41d55aaa47424b6509bd870b15b0b40425c6506cfe25c5d052b27d8380a3d2f67963750cbc5bb49221ba
7
+ data.tar.gz: e5978ae12bd2d50c98ff7d235fc40e23293c0dbe126015bdf27fc94fea866645dcd6bc9a9280ea91def5e6ac8a8c5df45cc6563c79f4ade259ea2092fb04bb22
@@ -23,7 +23,7 @@ module Math
23
23
  module Math
24
24
  class Service
25
25
 
26
- include GRPC::GenericService
26
+ include ::GRPC::GenericService
27
27
 
28
28
  self.marshal_class_method = :encode
29
29
  self.unmarshal_class_method = :decode
@@ -45,8 +45,16 @@ if RUBY_PLATFORM =~ /darwin/
45
45
  ENV['EMBED_OPENSSL'] = 'true'
46
46
  ENV['EMBED_ZLIB'] = 'true'
47
47
  ENV['EMBED_CARES'] = 'true'
48
+
48
49
  ENV['ARCH_FLAGS'] = RbConfig::CONFIG['ARCH_FLAG']
49
- ENV['ARCH_FLAGS'] = '-arch i386 -arch x86_64' if RUBY_PLATFORM =~ /darwin/
50
+ if RUBY_PLATFORM =~ /darwin/
51
+ if RUBY_PLATFORM =~ /arm64/
52
+ ENV['ARCH_FLAGS'] = '-arch arm64'
53
+ else
54
+ ENV['ARCH_FLAGS'] = '-arch i386 -arch x86_64'
55
+ end
56
+ end
57
+
50
58
  ENV['CPPFLAGS'] = '-DGPR_BACKWARDS_COMPATIBILITY_MODE'
51
59
 
52
60
  output_dir = File.expand_path(RbConfig::CONFIG['topdir'])
@@ -34,6 +34,7 @@
34
34
  #include "rb_completion_queue.h"
35
35
  #include "rb_grpc.h"
36
36
  #include "rb_server.h"
37
+ #include "rb_xds_channel_credentials.h"
37
38
 
38
39
  /* id_channel is the name of the hidden ivar that preserves a reference to the
39
40
  * channel on a call, so that calls are not GCed before their channel. */
@@ -242,7 +243,15 @@ static VALUE grpc_rb_channel_init(int argc, VALUE* argv, VALUE self) {
242
243
  ch = grpc_insecure_channel_create(target_chars, &args, NULL);
243
244
  } else {
244
245
  wrapper->credentials = credentials;
245
- creds = grpc_rb_get_wrapped_channel_credentials(credentials);
246
+ if (grpc_rb_is_channel_credentials(credentials)) {
247
+ creds = grpc_rb_get_wrapped_channel_credentials(credentials);
248
+ } else if (grpc_rb_is_xds_channel_credentials(credentials)) {
249
+ creds = grpc_rb_get_wrapped_xds_channel_credentials(credentials);
250
+ } else {
251
+ rb_raise(rb_eTypeError,
252
+ "bad creds, want ChannelCredentials or XdsChannelCredentials");
253
+ return Qnil;
254
+ }
246
255
  ch = grpc_secure_channel_create(creds, target_chars, &args, NULL);
247
256
  }
248
257
 
@@ -180,7 +180,11 @@ static VALUE grpc_rb_channel_credentials_init(int argc, VALUE* argv,
180
180
  NULL, NULL);
181
181
  }
182
182
  if (creds == NULL) {
183
- rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why");
183
+ rb_raise(rb_eRuntimeError,
184
+ "the call to grpc_ssl_credentials_create() failed, could not "
185
+ "create a credentials, see "
186
+ "https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
187
+ "debugging tips");
184
188
  return Qnil;
185
189
  }
186
190
  wrapper->wrapped = creds;
@@ -270,7 +274,13 @@ void Init_grpc_channel_credentials() {
270
274
  /* Gets the wrapped grpc_channel_credentials from the ruby wrapper */
271
275
  grpc_channel_credentials* grpc_rb_get_wrapped_channel_credentials(VALUE v) {
272
276
  grpc_rb_channel_credentials* wrapper = NULL;
277
+ Check_TypedStruct(v, &grpc_rb_channel_credentials_data_type);
273
278
  TypedData_Get_Struct(v, grpc_rb_channel_credentials,
274
279
  &grpc_rb_channel_credentials_data_type, wrapper);
275
280
  return wrapper->wrapped;
276
281
  }
282
+
283
+ /* Check if v is kind of ChannelCredentials */
284
+ bool grpc_rb_is_channel_credentials(VALUE v) {
285
+ return rb_typeddata_is_kind_of(v, &grpc_rb_channel_credentials_data_type);
286
+ }
@@ -20,6 +20,7 @@
20
20
  #define GRPC_RB_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_channel_credentials();
29
30
  /* Gets the wrapped credentials from the ruby wrapper */
30
31
  grpc_channel_credentials* grpc_rb_get_wrapped_channel_credentials(VALUE v);
31
32
 
33
+ /* Check if v is kind of ChannelCredentials */
34
+ bool grpc_rb_is_channel_credentials(VALUE v);
35
+
32
36
  #endif /* GRPC_RB_CREDENTIALS_H_ */
@@ -142,7 +142,7 @@ grpc_compression_level grpc_rb_compression_options_level_name_to_value_internal(
142
142
  "Unrecognized compression level name."
143
143
  "Valid compression level names are none, low, medium, and high.");
144
144
 
145
- /* Dummy return statement. */
145
+ /* Phony return statement. */
146
146
  return GRPC_COMPRESS_LEVEL_NONE;
147
147
  }
148
148
 
@@ -18,5 +18,5 @@
18
18
 
19
19
  #include <ruby/ruby.h>
20
20
 
21
- // This is a dummy C++ source file to trigger ruby extension builder to
21
+ // This is a phony C++ source file to trigger ruby extension builder to
22
22
  // pick C++ rather than C linker to link with c++ library properly.
@@ -40,6 +40,8 @@
40
40
  #include "rb_loader.h"
41
41
  #include "rb_server.h"
42
42
  #include "rb_server_credentials.h"
43
+ #include "rb_xds_channel_credentials.h"
44
+ #include "rb_xds_server_credentials.h"
43
45
 
44
46
  static VALUE grpc_rb_cTimeVal = Qnil;
45
47
 
@@ -321,8 +323,10 @@ void Init_grpc_c() {
321
323
  Init_grpc_call();
322
324
  Init_grpc_call_credentials();
323
325
  Init_grpc_channel_credentials();
326
+ Init_grpc_xds_channel_credentials();
324
327
  Init_grpc_server();
325
328
  Init_grpc_server_credentials();
329
+ Init_grpc_xds_server_credentials();
326
330
  Init_grpc_time_consts();
327
331
  Init_grpc_compression_options();
328
332
  }
@@ -98,6 +98,7 @@ grpc_resource_quota_ref_type grpc_resource_quota_ref_import;
98
98
  grpc_resource_quota_unref_type grpc_resource_quota_unref_import;
99
99
  grpc_resource_quota_resize_type grpc_resource_quota_resize_import;
100
100
  grpc_resource_quota_set_max_threads_type grpc_resource_quota_set_max_threads_import;
101
+ grpc_dump_xds_configs_type grpc_dump_xds_configs_import;
101
102
  grpc_resource_quota_arg_vtable_type grpc_resource_quota_arg_vtable_import;
102
103
  grpc_channelz_get_top_channels_type grpc_channelz_get_top_channels_import;
103
104
  grpc_channelz_get_servers_type grpc_channelz_get_servers_import;
@@ -382,6 +383,7 @@ void grpc_rb_load_imports(HMODULE library) {
382
383
  grpc_resource_quota_unref_import = (grpc_resource_quota_unref_type) GetProcAddress(library, "grpc_resource_quota_unref");
383
384
  grpc_resource_quota_resize_import = (grpc_resource_quota_resize_type) GetProcAddress(library, "grpc_resource_quota_resize");
384
385
  grpc_resource_quota_set_max_threads_import = (grpc_resource_quota_set_max_threads_type) GetProcAddress(library, "grpc_resource_quota_set_max_threads");
386
+ grpc_dump_xds_configs_import = (grpc_dump_xds_configs_type) GetProcAddress(library, "grpc_dump_xds_configs");
385
387
  grpc_resource_quota_arg_vtable_import = (grpc_resource_quota_arg_vtable_type) GetProcAddress(library, "grpc_resource_quota_arg_vtable");
386
388
  grpc_channelz_get_top_channels_import = (grpc_channelz_get_top_channels_type) GetProcAddress(library, "grpc_channelz_get_top_channels");
387
389
  grpc_channelz_get_servers_import = (grpc_channelz_get_servers_type) GetProcAddress(library, "grpc_channelz_get_servers");
@@ -215,7 +215,7 @@ extern grpc_server_create_type grpc_server_create_import;
215
215
  typedef void(*grpc_server_register_completion_queue_type)(grpc_server* server, grpc_completion_queue* cq, void* reserved);
216
216
  extern grpc_server_register_completion_queue_type grpc_server_register_completion_queue_import;
217
217
  #define grpc_server_register_completion_queue grpc_server_register_completion_queue_import
218
- typedef grpc_server_config_fetcher*(*grpc_server_config_fetcher_xds_create_type)();
218
+ typedef grpc_server_config_fetcher*(*grpc_server_config_fetcher_xds_create_type)(grpc_server_xds_status_notifier notifier, const grpc_channel_args* args);
219
219
  extern grpc_server_config_fetcher_xds_create_type grpc_server_config_fetcher_xds_create_import;
220
220
  #define grpc_server_config_fetcher_xds_create grpc_server_config_fetcher_xds_create_import
221
221
  typedef void(*grpc_server_config_fetcher_destroy_type)(grpc_server_config_fetcher* config_fetcher);
@@ -269,6 +269,9 @@ extern grpc_resource_quota_resize_type grpc_resource_quota_resize_import;
269
269
  typedef void(*grpc_resource_quota_set_max_threads_type)(grpc_resource_quota* resource_quota, int new_max_threads);
270
270
  extern grpc_resource_quota_set_max_threads_type grpc_resource_quota_set_max_threads_import;
271
271
  #define grpc_resource_quota_set_max_threads grpc_resource_quota_set_max_threads_import
272
+ typedef grpc_slice(*grpc_dump_xds_configs_type)();
273
+ extern grpc_dump_xds_configs_type grpc_dump_xds_configs_import;
274
+ #define grpc_dump_xds_configs grpc_dump_xds_configs_import
272
275
  typedef const grpc_arg_pointer_vtable*(*grpc_resource_quota_arg_vtable_type)(void);
273
276
  extern grpc_resource_quota_arg_vtable_type grpc_resource_quota_arg_vtable_import;
274
277
  #define grpc_resource_quota_arg_vtable grpc_resource_quota_arg_vtable_import
@@ -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
- creds = grpc_rb_get_wrapped_server_credentials(rb_creds);
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 grpc_rb_server_credentials_free(void* p) {
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, "could not create a credentials, not sure why");
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
+ }