grpc 1.59.5-aarch64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-msvcrt.ruby +0 -0
- data/grpc_c.64-ucrt.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +40 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +208 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1075 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +340 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +875 -0
- data/src/ruby/ext/grpc/rb_channel.h +35 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +172 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +161 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +496 -0
- data/src/ruby/ext/grpc/rb_grpc.h +83 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +603 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +910 -0
- data/src/ruby/ext/grpc/rb_loader.c +61 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +405 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +670 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +44 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +46 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +42 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +66 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
- data/src/ruby/pb/test/client.rb +785 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +415 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +180 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +124 -0
- data/src/ruby/spec/channel_spec.rb +207 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +676 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +692 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +104 -0
- data/src/ruby/spec/server_spec.rb +231 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +160 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- metadata +405 -0
@@ -0,0 +1,258 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 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 <ruby/ruby.h>
|
20
|
+
|
21
|
+
#include "rb_server_credentials.h"
|
22
|
+
|
23
|
+
#include "rb_grpc.h"
|
24
|
+
#include "rb_grpc_imports.generated.h"
|
25
|
+
|
26
|
+
#include <grpc/grpc.h>
|
27
|
+
#include <grpc/grpc_security.h>
|
28
|
+
#include <grpc/support/log.h>
|
29
|
+
|
30
|
+
/* grpc_rb_cServerCredentials is the ruby class that proxies
|
31
|
+
grpc_server_credentials. */
|
32
|
+
static VALUE grpc_rb_cServerCredentials = Qnil;
|
33
|
+
|
34
|
+
/* grpc_rb_server_credentials wraps a grpc_server_credentials. It provides a
|
35
|
+
peer ruby object, 'mark' to hold references to objects involved in
|
36
|
+
constructing the server credentials. */
|
37
|
+
typedef struct grpc_rb_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_server_credentials;
|
43
|
+
|
44
|
+
/* Destroys the server credentials instances. */
|
45
|
+
static void grpc_rb_server_credentials_free_internal(void* p) {
|
46
|
+
grpc_rb_server_credentials* wrapper = NULL;
|
47
|
+
if (p == NULL) {
|
48
|
+
return;
|
49
|
+
};
|
50
|
+
wrapper = (grpc_rb_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_server_credentials_free(void* p) {
|
64
|
+
grpc_rb_server_credentials_free_internal(p);
|
65
|
+
}
|
66
|
+
|
67
|
+
/* Protects the mark object from GC */
|
68
|
+
static void grpc_rb_server_credentials_mark(void* p) {
|
69
|
+
grpc_rb_server_credentials* wrapper = NULL;
|
70
|
+
if (p == NULL) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
wrapper = (grpc_rb_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_server_credentials_data_type = {
|
82
|
+
"grpc_server_credentials",
|
83
|
+
{grpc_rb_server_credentials_mark,
|
84
|
+
grpc_rb_server_credentials_free,
|
85
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE,
|
86
|
+
{NULL, NULL}},
|
87
|
+
NULL,
|
88
|
+
NULL,
|
89
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
90
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
91
|
+
#endif
|
92
|
+
};
|
93
|
+
|
94
|
+
/* Allocates ServerCredential instances.
|
95
|
+
Provides safe initial defaults for the instance fields. */
|
96
|
+
static VALUE grpc_rb_server_credentials_alloc(VALUE cls) {
|
97
|
+
grpc_ruby_init();
|
98
|
+
grpc_rb_server_credentials* wrapper = ALLOC(grpc_rb_server_credentials);
|
99
|
+
wrapper->wrapped = NULL;
|
100
|
+
wrapper->mark = Qnil;
|
101
|
+
return TypedData_Wrap_Struct(cls, &grpc_rb_server_credentials_data_type,
|
102
|
+
wrapper);
|
103
|
+
}
|
104
|
+
|
105
|
+
/* The attribute used on the mark object to preserve the pem_root_certs. */
|
106
|
+
static ID id_pem_root_certs;
|
107
|
+
|
108
|
+
/* The attribute used on the mark object to preserve the pem_key_certs */
|
109
|
+
static ID id_pem_key_certs;
|
110
|
+
|
111
|
+
/* The key used to access the pem cert in a key_cert pair hash */
|
112
|
+
static VALUE sym_cert_chain;
|
113
|
+
|
114
|
+
/* The key used to access the pem private key in a key_cert pair hash */
|
115
|
+
static VALUE sym_private_key;
|
116
|
+
|
117
|
+
/*
|
118
|
+
call-seq:
|
119
|
+
creds = ServerCredentials.new(nil,
|
120
|
+
[{private_key: <pem_private_key1>,
|
121
|
+
{cert_chain: <pem_cert_chain1>}],
|
122
|
+
force_client_auth)
|
123
|
+
creds = ServerCredentials.new(pem_root_certs,
|
124
|
+
[{private_key: <pem_private_key1>,
|
125
|
+
{cert_chain: <pem_cert_chain1>}],
|
126
|
+
force_client_auth)
|
127
|
+
|
128
|
+
pem_root_certs: (optional) PEM encoding of the server root certificate
|
129
|
+
pem_private_key: (required) PEM encoding of the server's private keys
|
130
|
+
force_client_auth: indicatees
|
131
|
+
|
132
|
+
Initializes ServerCredential instances. */
|
133
|
+
static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs,
|
134
|
+
VALUE pem_key_certs,
|
135
|
+
VALUE force_client_auth) {
|
136
|
+
grpc_rb_server_credentials* wrapper = NULL;
|
137
|
+
grpc_server_credentials* creds = NULL;
|
138
|
+
grpc_ssl_pem_key_cert_pair* key_cert_pairs = NULL;
|
139
|
+
VALUE cert = Qnil;
|
140
|
+
VALUE key = Qnil;
|
141
|
+
VALUE key_cert = Qnil;
|
142
|
+
int auth_client = 0;
|
143
|
+
long num_key_certs = 0;
|
144
|
+
int i;
|
145
|
+
|
146
|
+
if (NIL_P(force_client_auth) ||
|
147
|
+
!(force_client_auth == Qfalse || force_client_auth == Qtrue)) {
|
148
|
+
rb_raise(rb_eTypeError,
|
149
|
+
"bad force_client_auth: got:<%s> want: <True|False|nil>",
|
150
|
+
rb_obj_classname(force_client_auth));
|
151
|
+
return Qnil;
|
152
|
+
}
|
153
|
+
if (NIL_P(pem_key_certs) || TYPE(pem_key_certs) != T_ARRAY) {
|
154
|
+
rb_raise(rb_eTypeError, "bad pem_key_certs: got:<%s> want: <Array>",
|
155
|
+
rb_obj_classname(pem_key_certs));
|
156
|
+
return Qnil;
|
157
|
+
}
|
158
|
+
num_key_certs = RARRAY_LEN(pem_key_certs);
|
159
|
+
if (num_key_certs == 0) {
|
160
|
+
rb_raise(rb_eTypeError, "bad pem_key_certs: it had no elements");
|
161
|
+
return Qnil;
|
162
|
+
}
|
163
|
+
for (i = 0; i < num_key_certs; i++) {
|
164
|
+
key_cert = rb_ary_entry(pem_key_certs, i);
|
165
|
+
if (key_cert == Qnil) {
|
166
|
+
rb_raise(rb_eTypeError,
|
167
|
+
"could not create a server credential: nil key_cert");
|
168
|
+
return Qnil;
|
169
|
+
} else if (TYPE(key_cert) != T_HASH) {
|
170
|
+
rb_raise(rb_eTypeError,
|
171
|
+
"could not create a server credential: want <Hash>, got <%s>",
|
172
|
+
rb_obj_classname(key_cert));
|
173
|
+
return Qnil;
|
174
|
+
} else if (rb_hash_aref(key_cert, sym_private_key) == Qnil) {
|
175
|
+
rb_raise(rb_eTypeError,
|
176
|
+
"could not create a server credential: want nil private key");
|
177
|
+
return Qnil;
|
178
|
+
} else if (rb_hash_aref(key_cert, sym_cert_chain) == Qnil) {
|
179
|
+
rb_raise(rb_eTypeError,
|
180
|
+
"could not create a server credential: want nil cert chain");
|
181
|
+
return Qnil;
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
auth_client = TYPE(force_client_auth) == T_TRUE
|
186
|
+
? GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
|
187
|
+
: GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE;
|
188
|
+
key_cert_pairs = ALLOC_N(grpc_ssl_pem_key_cert_pair, num_key_certs);
|
189
|
+
for (i = 0; i < num_key_certs; i++) {
|
190
|
+
key_cert = rb_ary_entry(pem_key_certs, i);
|
191
|
+
key = rb_hash_aref(key_cert, sym_private_key);
|
192
|
+
cert = rb_hash_aref(key_cert, sym_cert_chain);
|
193
|
+
key_cert_pairs[i].private_key = RSTRING_PTR(key);
|
194
|
+
key_cert_pairs[i].cert_chain = RSTRING_PTR(cert);
|
195
|
+
}
|
196
|
+
|
197
|
+
TypedData_Get_Struct(self, grpc_rb_server_credentials,
|
198
|
+
&grpc_rb_server_credentials_data_type, wrapper);
|
199
|
+
|
200
|
+
if (pem_root_certs == Qnil) {
|
201
|
+
creds = grpc_ssl_server_credentials_create_ex(
|
202
|
+
NULL, key_cert_pairs, num_key_certs, auth_client, NULL);
|
203
|
+
} else {
|
204
|
+
creds = grpc_ssl_server_credentials_create_ex(RSTRING_PTR(pem_root_certs),
|
205
|
+
key_cert_pairs, num_key_certs,
|
206
|
+
auth_client, NULL);
|
207
|
+
}
|
208
|
+
xfree(key_cert_pairs);
|
209
|
+
if (creds == NULL) {
|
210
|
+
rb_raise(rb_eRuntimeError,
|
211
|
+
"the call to grpc_ssl_server_credentials_create_ex() failed, "
|
212
|
+
"could not create a credentials, see "
|
213
|
+
"https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
|
214
|
+
"debugging tips");
|
215
|
+
return Qnil;
|
216
|
+
}
|
217
|
+
wrapper->wrapped = creds;
|
218
|
+
|
219
|
+
/* Add the input objects as hidden fields to preserve them. */
|
220
|
+
rb_ivar_set(self, id_pem_key_certs, pem_key_certs);
|
221
|
+
rb_ivar_set(self, id_pem_root_certs, pem_root_certs);
|
222
|
+
|
223
|
+
return self;
|
224
|
+
}
|
225
|
+
|
226
|
+
void Init_grpc_server_credentials() {
|
227
|
+
grpc_rb_cServerCredentials =
|
228
|
+
rb_define_class_under(grpc_rb_mGrpcCore, "ServerCredentials", rb_cObject);
|
229
|
+
|
230
|
+
/* Allocates an object managed by the ruby runtime */
|
231
|
+
rb_define_alloc_func(grpc_rb_cServerCredentials,
|
232
|
+
grpc_rb_server_credentials_alloc);
|
233
|
+
|
234
|
+
/* Provides a ruby constructor and support for dup/clone. */
|
235
|
+
rb_define_method(grpc_rb_cServerCredentials, "initialize",
|
236
|
+
grpc_rb_server_credentials_init, 3);
|
237
|
+
rb_define_method(grpc_rb_cServerCredentials, "initialize_copy",
|
238
|
+
grpc_rb_cannot_init_copy, 1);
|
239
|
+
|
240
|
+
id_pem_key_certs = rb_intern("__pem_key_certs");
|
241
|
+
id_pem_root_certs = rb_intern("__pem_root_certs");
|
242
|
+
sym_private_key = ID2SYM(rb_intern("private_key"));
|
243
|
+
sym_cert_chain = ID2SYM(rb_intern("cert_chain"));
|
244
|
+
}
|
245
|
+
|
246
|
+
/* Gets the wrapped grpc_server_credentials from the ruby wrapper */
|
247
|
+
grpc_server_credentials* grpc_rb_get_wrapped_server_credentials(VALUE v) {
|
248
|
+
grpc_rb_server_credentials* wrapper = NULL;
|
249
|
+
Check_TypedStruct(v, &grpc_rb_server_credentials_data_type);
|
250
|
+
TypedData_Get_Struct(v, grpc_rb_server_credentials,
|
251
|
+
&grpc_rb_server_credentials_data_type, wrapper);
|
252
|
+
return wrapper->wrapped;
|
253
|
+
}
|
254
|
+
|
255
|
+
/* Check if v is kind of ServerCredentials */
|
256
|
+
bool grpc_rb_is_server_credentials(VALUE v) {
|
257
|
+
return rb_typeddata_is_kind_of(v, &grpc_rb_server_credentials_data_type);
|
258
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 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_SERVER_CREDENTIALS_H_
|
20
|
+
#define GRPC_RB_SERVER_CREDENTIALS_H_
|
21
|
+
|
22
|
+
#include <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <stdbool.h>
|
25
|
+
|
26
|
+
#include <grpc/grpc_security.h>
|
27
|
+
|
28
|
+
/* Initializes the ruby ServerCredentials class. */
|
29
|
+
void Init_grpc_server_credentials();
|
30
|
+
|
31
|
+
/* Gets the wrapped server_credentials from the ruby wrapper */
|
32
|
+
grpc_server_credentials* grpc_rb_get_wrapped_server_credentials(VALUE v);
|
33
|
+
|
34
|
+
/* Check if v is kind of ServerCredentials */
|
35
|
+
bool grpc_rb_is_server_credentials(VALUE v);
|
36
|
+
|
37
|
+
#endif /* GRPC_RB_SERVER_CREDENTIALS_H_ */
|
@@ -0,0 +1,217 @@
|
|
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 <ruby/ruby.h>
|
20
|
+
|
21
|
+
#include "rb_xds_channel_credentials.h"
|
22
|
+
|
23
|
+
#include <string.h>
|
24
|
+
|
25
|
+
#include "rb_call_credentials.h"
|
26
|
+
#include "rb_channel_credentials.h"
|
27
|
+
#include "rb_grpc.h"
|
28
|
+
#include "rb_grpc_imports.generated.h"
|
29
|
+
|
30
|
+
#include <grpc/grpc.h>
|
31
|
+
#include <grpc/grpc_security.h>
|
32
|
+
#include <grpc/support/alloc.h>
|
33
|
+
#include <grpc/support/log.h>
|
34
|
+
|
35
|
+
/* grpc_rb_cXdsChannelCredentials is the ruby class that proxies
|
36
|
+
grpc_channel_credentials. */
|
37
|
+
static VALUE grpc_rb_cXdsChannelCredentials = Qnil;
|
38
|
+
|
39
|
+
/* grpc_rb_xds_channel_credentials wraps a grpc_channel_credentials. It
|
40
|
+
* provides a mark object that is used to hold references to any objects used to
|
41
|
+
* create the credentials. */
|
42
|
+
typedef struct grpc_rb_xds_channel_credentials {
|
43
|
+
/* Holder of ruby objects involved in constructing the credentials */
|
44
|
+
VALUE mark;
|
45
|
+
|
46
|
+
/* The actual credentials */
|
47
|
+
grpc_channel_credentials* wrapped;
|
48
|
+
} grpc_rb_xds_channel_credentials;
|
49
|
+
|
50
|
+
static void grpc_rb_xds_channel_credentials_free_internal(void* p) {
|
51
|
+
grpc_rb_xds_channel_credentials* wrapper = NULL;
|
52
|
+
if (p == NULL) {
|
53
|
+
return;
|
54
|
+
};
|
55
|
+
wrapper = (grpc_rb_xds_channel_credentials*)p;
|
56
|
+
grpc_channel_credentials_release(wrapper->wrapped);
|
57
|
+
wrapper->wrapped = NULL;
|
58
|
+
|
59
|
+
xfree(p);
|
60
|
+
}
|
61
|
+
|
62
|
+
/* Destroys the credentials instances. */
|
63
|
+
static void grpc_rb_xds_channel_credentials_free(void* p) {
|
64
|
+
grpc_rb_xds_channel_credentials_free_internal(p);
|
65
|
+
}
|
66
|
+
|
67
|
+
/* Protects the mark object from GC */
|
68
|
+
static void grpc_rb_xds_channel_credentials_mark(void* p) {
|
69
|
+
grpc_rb_xds_channel_credentials* wrapper = NULL;
|
70
|
+
if (p == NULL) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
wrapper = (grpc_rb_xds_channel_credentials*)p;
|
74
|
+
|
75
|
+
if (wrapper->mark != Qnil) {
|
76
|
+
rb_gc_mark(wrapper->mark);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
static rb_data_type_t grpc_rb_xds_channel_credentials_data_type = {
|
81
|
+
"grpc_xds_channel_credentials",
|
82
|
+
{grpc_rb_xds_channel_credentials_mark, grpc_rb_xds_channel_credentials_free,
|
83
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE, NULL},
|
84
|
+
NULL,
|
85
|
+
NULL,
|
86
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
87
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
88
|
+
#endif
|
89
|
+
};
|
90
|
+
|
91
|
+
/* Allocates ChannelCredential instances.
|
92
|
+
Provides safe initial defaults for the instance fields. */
|
93
|
+
static VALUE grpc_rb_xds_channel_credentials_alloc(VALUE cls) {
|
94
|
+
grpc_ruby_init();
|
95
|
+
grpc_rb_xds_channel_credentials* wrapper =
|
96
|
+
ALLOC(grpc_rb_xds_channel_credentials);
|
97
|
+
wrapper->wrapped = NULL;
|
98
|
+
wrapper->mark = Qnil;
|
99
|
+
return TypedData_Wrap_Struct(cls, &grpc_rb_xds_channel_credentials_data_type,
|
100
|
+
wrapper);
|
101
|
+
}
|
102
|
+
|
103
|
+
/* Creates a wrapping object for a given channel credentials. This should only
|
104
|
+
* be called with grpc_channel_credentials objects that are not already
|
105
|
+
* associated with any Ruby object. */
|
106
|
+
VALUE grpc_rb_xds_wrap_channel_credentials(grpc_channel_credentials* c,
|
107
|
+
VALUE mark) {
|
108
|
+
grpc_rb_xds_channel_credentials* wrapper;
|
109
|
+
if (c == NULL) {
|
110
|
+
return Qnil;
|
111
|
+
}
|
112
|
+
VALUE rb_wrapper =
|
113
|
+
grpc_rb_xds_channel_credentials_alloc(grpc_rb_cXdsChannelCredentials);
|
114
|
+
TypedData_Get_Struct(rb_wrapper, grpc_rb_xds_channel_credentials,
|
115
|
+
&grpc_rb_xds_channel_credentials_data_type, wrapper);
|
116
|
+
wrapper->wrapped = c;
|
117
|
+
wrapper->mark = mark;
|
118
|
+
return rb_wrapper;
|
119
|
+
}
|
120
|
+
|
121
|
+
/* The attribute used on the mark object to hold the fallback creds. */
|
122
|
+
static ID id_fallback_creds;
|
123
|
+
|
124
|
+
/*
|
125
|
+
call-seq:
|
126
|
+
fallback_creds: (ChannelCredentials) fallback credentials to create
|
127
|
+
XDS credentials
|
128
|
+
Initializes Credential instances. */
|
129
|
+
static VALUE grpc_rb_xds_channel_credentials_init(VALUE self,
|
130
|
+
VALUE fallback_creds) {
|
131
|
+
grpc_rb_xds_channel_credentials* wrapper = NULL;
|
132
|
+
grpc_channel_credentials* grpc_fallback_creds =
|
133
|
+
grpc_rb_get_wrapped_channel_credentials(fallback_creds);
|
134
|
+
grpc_channel_credentials* creds =
|
135
|
+
grpc_xds_credentials_create(grpc_fallback_creds);
|
136
|
+
if (creds == NULL) {
|
137
|
+
rb_raise(rb_eRuntimeError,
|
138
|
+
"the call to grpc_xds_credentials_create() failed, could not "
|
139
|
+
"create a credentials, , see "
|
140
|
+
"https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
|
141
|
+
"debugging tips");
|
142
|
+
return Qnil;
|
143
|
+
}
|
144
|
+
|
145
|
+
TypedData_Get_Struct(self, grpc_rb_xds_channel_credentials,
|
146
|
+
&grpc_rb_xds_channel_credentials_data_type, wrapper);
|
147
|
+
wrapper->wrapped = creds;
|
148
|
+
|
149
|
+
/* Add the input objects as hidden fields to preserve them. */
|
150
|
+
rb_ivar_set(self, id_fallback_creds, fallback_creds);
|
151
|
+
|
152
|
+
return self;
|
153
|
+
}
|
154
|
+
|
155
|
+
// TODO: de-duplicate this code with the similar method in
|
156
|
+
// rb_channel_credentials.c, after putting ChannelCredentials and
|
157
|
+
// XdsChannelCredentials under a common parent class
|
158
|
+
static VALUE grpc_rb_xds_channel_credentials_compose(int argc, VALUE* argv,
|
159
|
+
VALUE self) {
|
160
|
+
grpc_channel_credentials* creds;
|
161
|
+
grpc_call_credentials* other;
|
162
|
+
grpc_channel_credentials* prev = NULL;
|
163
|
+
VALUE mark;
|
164
|
+
if (argc == 0) {
|
165
|
+
return self;
|
166
|
+
}
|
167
|
+
mark = rb_ary_new();
|
168
|
+
rb_ary_push(mark, self);
|
169
|
+
creds = grpc_rb_get_wrapped_xds_channel_credentials(self);
|
170
|
+
for (int i = 0; i < argc; i++) {
|
171
|
+
rb_ary_push(mark, argv[i]);
|
172
|
+
other = grpc_rb_get_wrapped_call_credentials(argv[i]);
|
173
|
+
creds = grpc_composite_channel_credentials_create(creds, other, NULL);
|
174
|
+
if (prev != NULL) {
|
175
|
+
grpc_channel_credentials_release(prev);
|
176
|
+
}
|
177
|
+
prev = creds;
|
178
|
+
|
179
|
+
if (creds == NULL) {
|
180
|
+
rb_raise(rb_eRuntimeError,
|
181
|
+
"Failed to compose channel and call credentials");
|
182
|
+
}
|
183
|
+
}
|
184
|
+
return grpc_rb_xds_wrap_channel_credentials(creds, mark);
|
185
|
+
}
|
186
|
+
|
187
|
+
void Init_grpc_xds_channel_credentials() {
|
188
|
+
grpc_rb_cXdsChannelCredentials = rb_define_class_under(
|
189
|
+
grpc_rb_mGrpcCore, "XdsChannelCredentials", rb_cObject);
|
190
|
+
|
191
|
+
/* Allocates an object managed by the ruby runtime */
|
192
|
+
rb_define_alloc_func(grpc_rb_cXdsChannelCredentials,
|
193
|
+
grpc_rb_xds_channel_credentials_alloc);
|
194
|
+
|
195
|
+
/* Provides a ruby constructor and support for dup/clone. */
|
196
|
+
rb_define_method(grpc_rb_cXdsChannelCredentials, "initialize",
|
197
|
+
grpc_rb_xds_channel_credentials_init, 1);
|
198
|
+
rb_define_method(grpc_rb_cXdsChannelCredentials, "initialize_copy",
|
199
|
+
grpc_rb_cannot_init_copy, 1);
|
200
|
+
rb_define_method(grpc_rb_cXdsChannelCredentials, "compose",
|
201
|
+
grpc_rb_xds_channel_credentials_compose, -1);
|
202
|
+
|
203
|
+
id_fallback_creds = rb_intern("__fallback_creds");
|
204
|
+
}
|
205
|
+
|
206
|
+
/* Gets the wrapped grpc_channel_credentials from the ruby wrapper */
|
207
|
+
grpc_channel_credentials* grpc_rb_get_wrapped_xds_channel_credentials(VALUE v) {
|
208
|
+
grpc_rb_xds_channel_credentials* wrapper = NULL;
|
209
|
+
Check_TypedStruct(v, &grpc_rb_xds_channel_credentials_data_type);
|
210
|
+
TypedData_Get_Struct(v, grpc_rb_xds_channel_credentials,
|
211
|
+
&grpc_rb_xds_channel_credentials_data_type, wrapper);
|
212
|
+
return wrapper->wrapped;
|
213
|
+
}
|
214
|
+
|
215
|
+
bool grpc_rb_is_xds_channel_credentials(VALUE v) {
|
216
|
+
return rb_typeddata_is_kind_of(v, &grpc_rb_xds_channel_credentials_data_type);
|
217
|
+
}
|
@@ -0,0 +1,37 @@
|
|
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 <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <stdbool.h>
|
25
|
+
|
26
|
+
#include <grpc/grpc_security.h>
|
27
|
+
|
28
|
+
/* Initializes the ruby ChannelCredentials class. */
|
29
|
+
void Init_grpc_xds_channel_credentials();
|
30
|
+
|
31
|
+
/* Gets the wrapped credentials from the ruby wrapper */
|
32
|
+
grpc_channel_credentials* grpc_rb_get_wrapped_xds_channel_credentials(VALUE v);
|
33
|
+
|
34
|
+
/* Check if v is kind of XdsChannelCredentials */
|
35
|
+
bool grpc_rb_is_xds_channel_credentials(VALUE v);
|
36
|
+
|
37
|
+
#endif /* GRPC_RB_XDS_CHANNEL_CREDENTIALS_H_ */
|