grpc 1.42.0.pre1-x86_64-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 (128) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32.ruby +0 -0
  4. data/grpc_c.64.ruby +0 -0
  5. data/src/ruby/bin/math_client.rb +140 -0
  6. data/src/ruby/bin/math_pb.rb +34 -0
  7. data/src/ruby/bin/math_server.rb +191 -0
  8. data/src/ruby/bin/math_services_pb.rb +51 -0
  9. data/src/ruby/bin/noproto_client.rb +93 -0
  10. data/src/ruby/bin/noproto_server.rb +97 -0
  11. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  12. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  13. data/src/ruby/ext/grpc/extconf.rb +123 -0
  14. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  15. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  16. data/src/ruby/ext/grpc/rb_call.c +1051 -0
  17. data/src/ruby/ext/grpc/rb_call.h +57 -0
  18. data/src/ruby/ext/grpc/rb_call_credentials.c +341 -0
  19. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  20. data/src/ruby/ext/grpc/rb_channel.c +846 -0
  21. data/src/ruby/ext/grpc/rb_channel.h +34 -0
  22. data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
  23. data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
  24. data/src/ruby/ext/grpc/rb_channel_credentials.c +286 -0
  25. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  26. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  27. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  28. data/src/ruby/ext/grpc/rb_compression_options.c +471 -0
  29. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  30. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  31. data/src/ruby/ext/grpc/rb_event_thread.c +145 -0
  32. data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
  33. data/src/ruby/ext/grpc/rb_grpc.c +333 -0
  34. data/src/ruby/ext/grpc/rb_grpc.h +77 -0
  35. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +605 -0
  36. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +913 -0
  37. data/src/ruby/ext/grpc/rb_loader.c +57 -0
  38. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  39. data/src/ruby/ext/grpc/rb_server.c +385 -0
  40. data/src/ruby/ext/grpc/rb_server.h +32 -0
  41. data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
  42. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  43. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +218 -0
  44. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  45. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
  46. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  47. data/src/ruby/lib/grpc/2.4/grpc_c.bundle +0 -0
  48. data/src/ruby/lib/grpc/2.5/grpc_c.bundle +0 -0
  49. data/src/ruby/lib/grpc/2.6/grpc_c.bundle +0 -0
  50. data/src/ruby/lib/grpc/2.7/grpc_c.bundle +0 -0
  51. data/src/ruby/lib/grpc/3.0/grpc_c.bundle +0 -0
  52. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  53. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  54. data/src/ruby/lib/grpc/errors.rb +277 -0
  55. data/src/ruby/lib/grpc/generic/active_call.rb +669 -0
  56. data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
  57. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  58. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  59. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  60. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  61. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  62. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  63. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  64. data/src/ruby/lib/grpc/grpc.rb +24 -0
  65. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  66. data/src/ruby/lib/grpc/notifier.rb +45 -0
  67. data/src/ruby/lib/grpc/structs.rb +15 -0
  68. data/src/ruby/lib/grpc/version.rb +18 -0
  69. data/src/ruby/lib/grpc.rb +37 -0
  70. data/src/ruby/pb/README.md +42 -0
  71. data/src/ruby/pb/generate_proto_ruby.sh +51 -0
  72. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  73. data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
  74. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  75. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  76. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  77. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  78. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
  79. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +145 -0
  80. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
  81. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
  82. data/src/ruby/pb/test/client.rb +769 -0
  83. data/src/ruby/pb/test/server.rb +252 -0
  84. data/src/ruby/pb/test/xds_client.rb +415 -0
  85. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  86. data/src/ruby/spec/call_spec.rb +180 -0
  87. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  88. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  89. data/src/ruby/spec/channel_spec.rb +245 -0
  90. data/src/ruby/spec/client_auth_spec.rb +152 -0
  91. data/src/ruby/spec/client_server_spec.rb +664 -0
  92. data/src/ruby/spec/compression_options_spec.rb +149 -0
  93. data/src/ruby/spec/debug_message_spec.rb +134 -0
  94. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  95. data/src/ruby/spec/errors_spec.rb +142 -0
  96. data/src/ruby/spec/generic/active_call_spec.rb +683 -0
  97. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  98. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  99. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  100. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  101. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  102. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  103. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  104. data/src/ruby/spec/generic/service_spec.rb +263 -0
  105. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  106. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  107. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  108. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  109. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  110. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  112. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  113. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  114. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  115. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  116. data/src/ruby/spec/server_spec.rb +231 -0
  117. data/src/ruby/spec/spec_helper.rb +61 -0
  118. data/src/ruby/spec/support/helpers.rb +107 -0
  119. data/src/ruby/spec/support/services.rb +160 -0
  120. data/src/ruby/spec/testdata/README +1 -0
  121. data/src/ruby/spec/testdata/ca.pem +20 -0
  122. data/src/ruby/spec/testdata/client.key +28 -0
  123. data/src/ruby/spec/testdata/client.pem +20 -0
  124. data/src/ruby/spec/testdata/server1.key +28 -0
  125. data/src/ruby/spec/testdata/server1.pem +22 -0
  126. data/src/ruby/spec/time_consts_spec.rb +74 -0
  127. data/src/ruby/spec/user_agent_spec.rb +74 -0
  128. metadata +404 -0
@@ -0,0 +1,170 @@
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_server_credentials.h"
22
+
23
+ #include "rb_grpc.h"
24
+ #include "rb_grpc_imports.generated.h"
25
+ #include "rb_server_credentials.h"
26
+
27
+ #include <grpc/grpc.h>
28
+ #include <grpc/grpc_security.h>
29
+ #include <grpc/support/log.h>
30
+
31
+ /* grpc_rb_cXdsServerCredentials is the ruby class that proxies
32
+ grpc_server_credentials. */
33
+ static VALUE grpc_rb_cXdsServerCredentials = Qnil;
34
+
35
+ /* grpc_rb_xds_server_credentials wraps a grpc_server_credentials. It provides
36
+ a peer ruby object, 'mark' to hold references to objects involved in
37
+ constructing the server credentials. */
38
+ typedef struct grpc_rb_xds_server_credentials {
39
+ /* Holder of ruby objects involved in constructing the server credentials */
40
+ VALUE mark;
41
+ /* The actual server credentials */
42
+ grpc_server_credentials* wrapped;
43
+ } grpc_rb_xds_server_credentials;
44
+
45
+ /* Destroys the server credentials instances. */
46
+ static void grpc_rb_xds_server_credentials_free_internal(void* p) {
47
+ grpc_rb_xds_server_credentials* wrapper = NULL;
48
+ if (p == NULL) {
49
+ return;
50
+ };
51
+ wrapper = (grpc_rb_xds_server_credentials*)p;
52
+
53
+ /* Delete the wrapped object if the mark object is Qnil, which indicates that
54
+ no other object is the actual owner. */
55
+ if (wrapper->wrapped != NULL && wrapper->mark == Qnil) {
56
+ grpc_server_credentials_release(wrapper->wrapped);
57
+ wrapper->wrapped = NULL;
58
+ }
59
+
60
+ xfree(p);
61
+ }
62
+
63
+ /* Destroys the server credentials instances. */
64
+ static void grpc_rb_xds_server_credentials_free(void* p) {
65
+ grpc_rb_xds_server_credentials_free_internal(p);
66
+ grpc_ruby_shutdown();
67
+ }
68
+
69
+ /* Protects the mark object from GC */
70
+ static void grpc_rb_xds_server_credentials_mark(void* p) {
71
+ if (p == NULL) {
72
+ return;
73
+ }
74
+ grpc_rb_xds_server_credentials* wrapper = (grpc_rb_xds_server_credentials*)p;
75
+
76
+ /* If it's not already cleaned up, mark the mark object */
77
+ if (wrapper->mark != Qnil) {
78
+ rb_gc_mark(wrapper->mark);
79
+ }
80
+ }
81
+
82
+ static const rb_data_type_t grpc_rb_xds_server_credentials_data_type = {
83
+ "grpc_xds_server_credentials",
84
+ {grpc_rb_xds_server_credentials_mark, grpc_rb_xds_server_credentials_free,
85
+ GRPC_RB_MEMSIZE_UNAVAILABLE, NULL},
86
+ NULL,
87
+ NULL,
88
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
89
+ RUBY_TYPED_FREE_IMMEDIATELY
90
+ #endif
91
+ };
92
+
93
+ /* Allocates ServerCredential instances.
94
+ Provides safe initial defaults for the instance fields. */
95
+ static VALUE grpc_rb_xds_server_credentials_alloc(VALUE cls) {
96
+ grpc_ruby_init();
97
+ grpc_rb_xds_server_credentials* wrapper =
98
+ ALLOC(grpc_rb_xds_server_credentials);
99
+ wrapper->wrapped = NULL;
100
+ wrapper->mark = Qnil;
101
+ return TypedData_Wrap_Struct(cls, &grpc_rb_xds_server_credentials_data_type,
102
+ wrapper);
103
+ }
104
+
105
+ /* The attribute used on the mark object to preserve the fallback_creds. */
106
+ static ID id_fallback_creds;
107
+
108
+ /*
109
+ call-seq:
110
+ creds = ServerCredentials.new(fallback_creds)
111
+ fallback_creds: (ServerCredentials) fallback credentials to create
112
+ XDS credentials.
113
+ Initializes ServerCredential instances. */
114
+ static VALUE grpc_rb_xds_server_credentials_init(VALUE self,
115
+ VALUE fallback_creds) {
116
+ grpc_rb_xds_server_credentials* wrapper = NULL;
117
+ grpc_server_credentials* creds = NULL;
118
+
119
+ grpc_server_credentials* grpc_fallback_creds =
120
+ grpc_rb_get_wrapped_server_credentials(fallback_creds);
121
+ creds = grpc_xds_server_credentials_create(grpc_fallback_creds);
122
+
123
+ if (creds == NULL) {
124
+ rb_raise(rb_eRuntimeError,
125
+ "the call to grpc_xds_server_credentials_create() failed, could "
126
+ "not create a credentials, see "
127
+ "https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
128
+ "debugging tips");
129
+ return Qnil;
130
+ }
131
+ TypedData_Get_Struct(self, grpc_rb_xds_server_credentials,
132
+ &grpc_rb_xds_server_credentials_data_type, wrapper);
133
+ wrapper->wrapped = creds;
134
+
135
+ /* Add the input objects as hidden fields to preserve them. */
136
+ rb_ivar_set(self, id_fallback_creds, fallback_creds);
137
+
138
+ return self;
139
+ }
140
+
141
+ void Init_grpc_xds_server_credentials() {
142
+ grpc_rb_cXdsServerCredentials = rb_define_class_under(
143
+ grpc_rb_mGrpcCore, "XdsServerCredentials", rb_cObject);
144
+
145
+ /* Allocates an object managed by the ruby runtime */
146
+ rb_define_alloc_func(grpc_rb_cXdsServerCredentials,
147
+ grpc_rb_xds_server_credentials_alloc);
148
+
149
+ /* Provides a ruby constructor and support for dup/clone. */
150
+ rb_define_method(grpc_rb_cXdsServerCredentials, "initialize",
151
+ grpc_rb_xds_server_credentials_init, 1);
152
+ rb_define_method(grpc_rb_cXdsServerCredentials, "initialize_copy",
153
+ grpc_rb_cannot_init_copy, 1);
154
+
155
+ id_fallback_creds = rb_intern("__fallback_creds");
156
+ }
157
+
158
+ /* Gets the wrapped grpc_server_credentials from the ruby wrapper */
159
+ grpc_server_credentials* grpc_rb_get_wrapped_xds_server_credentials(VALUE v) {
160
+ grpc_rb_xds_server_credentials* wrapper = NULL;
161
+ Check_TypedStruct(v, &grpc_rb_xds_server_credentials_data_type);
162
+ TypedData_Get_Struct(v, grpc_rb_xds_server_credentials,
163
+ &grpc_rb_xds_server_credentials_data_type, wrapper);
164
+ return wrapper->wrapped;
165
+ }
166
+
167
+ /* Check if v is kind of ServerCredentials */
168
+ bool grpc_rb_is_xds_server_credentials(VALUE v) {
169
+ return rb_typeddata_is_kind_of(v, &grpc_rb_xds_server_credentials_data_type);
170
+ }
@@ -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_SERVER_CREDENTIALS_H_
20
+ #define GRPC_RB_XDS_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 XdsServerCredentials class. */
29
+ void Init_grpc_xds_server_credentials();
30
+
31
+ /* Gets the wrapped server_credentials from the ruby wrapper */
32
+ grpc_server_credentials* grpc_rb_get_wrapped_xds_server_credentials(VALUE v);
33
+
34
+ /* Check if v is kind of XdsServerCredentials */
35
+ bool grpc_rb_is_xds_server_credentials(VALUE v);
36
+
37
+ #endif /* GRPC_RB_XDS_SERVER_CREDENTIALS_H_ */
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,135 @@
1
+ # Copyright 2015 gRPC authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # GRPC contains the General RPC module.
16
+ module GRPC
17
+ module Core
18
+ # StatusCodes defines the canonical error codes used by gRPC for the RPC
19
+ # API.
20
+ module StatusCodes
21
+ # OK is returned on success.
22
+ OK = 0
23
+
24
+ # Canceled indicates the operation was canceled (typically by the caller).
25
+ CANCELLED = 1
26
+
27
+ # Unknown error. An example of where this error may be returned is if a
28
+ # Status value received from another address space belongs to an
29
+ # error-space that is not known in this address space. Also errors raised
30
+ # by APIs that do not return enough error information may be converted to
31
+ # this error.
32
+ UNKNOWN = 2
33
+
34
+ # InvalidArgument indicates client specified an invalid argument. Note
35
+ # that this differs from FailedPrecondition. It indicates arguments that
36
+ # are problematic regardless of the state of the system (e.g., a malformed
37
+ # file name).
38
+ INVALID_ARGUMENT = 3
39
+
40
+ # DeadlineExceeded means operation expired before completion. For
41
+ # operations that change the state of the system, this error may be
42
+ # returned even if the operation has completed successfully. For example,
43
+ # a successful response from a server could have been delayed long enough
44
+ # for the deadline to expire.
45
+ DEADLINE_EXCEEDED = 4
46
+
47
+ # NotFound means some requested entity (e.g., file or directory) was not
48
+ # found.
49
+ NOT_FOUND = 5
50
+
51
+ # AlreadyExists means an attempt to create an entity failed because one
52
+ # already exists.
53
+ ALREADY_EXISTS = 6
54
+
55
+ # PermissionDenied indicates the caller does not have permission to
56
+ # execute the specified operation. It must not be used for rejections
57
+ # caused by exhausting some resource (use ResourceExhausted instead for
58
+ # those errors). It must not be used if the caller cannot be identified
59
+ # (use Unauthenticated instead for those errors).
60
+ PERMISSION_DENIED = 7
61
+
62
+ # ResourceExhausted indicates some resource has been exhausted, perhaps a
63
+ # per-user quota, or perhaps the entire file system is out of space.
64
+ RESOURCE_EXHAUSTED = 8
65
+
66
+ # FailedPrecondition indicates operation was rejected because the system
67
+ # is not in a state required for the operation's execution. For example,
68
+ # directory to be deleted may be non-empty, an rmdir operation is applied
69
+ # to a non-directory, etc.
70
+ #
71
+ # A litmus test that may help a service implementor in deciding between
72
+ # FailedPrecondition, Aborted, and Unavailable:
73
+ # (a) Use Unavailable if the client can retry just the failing call.
74
+ # (b) Use Aborted if the client should retry at a higher-level (e.g.,
75
+ # restarting a read-modify-write sequence).
76
+ # (c) Use FailedPrecondition if the client should not retry until the
77
+ # system state has been explicitly fixed. E.g., if an "rmdir" fails
78
+ # because the directory is non-empty, FailedPrecondition should be
79
+ # returned since the client should not retry unless they have first
80
+ # fixed up the directory by deleting files from it.
81
+ # (d) Use FailedPrecondition if the client performs conditional REST
82
+ # Get/Update/Delete on a resource and the resource on the server does
83
+ # not match the condition. E.g., conflicting read-modify-write on the
84
+ # same resource.
85
+ FAILED_PRECONDITION = 9
86
+
87
+ # Aborted indicates the operation was aborted, typically due to a
88
+ # concurrency issue like sequencer check failures, transaction aborts,
89
+ # etc.
90
+ #
91
+ # See litmus test above for deciding between FailedPrecondition, Aborted,
92
+ # and Unavailable.
93
+ ABORTED = 10
94
+
95
+ # OutOfRange means operation was attempted past the valid range. E.g.,
96
+ # seeking or reading past end of file.
97
+ #
98
+ # Unlike InvalidArgument, this error indicates a problem that may be fixed
99
+ # if the system state changes. For example, a 32-bit file system will
100
+ # generate InvalidArgument if asked to read at an offset that is not in
101
+ # the range [0,2^32-1], but it will generate OutOfRange if asked to read
102
+ # from an offset past the current file size.
103
+ #
104
+ # There is a fair bit of overlap between FailedPrecondition and
105
+ # OutOfRange. We recommend using OutOfRange (the more specific error) when
106
+ # it applies so that callers who are iterating through a space can easily
107
+ # look for an OutOfRange error to detect when they are done.
108
+ OUT_OF_RANGE = 11
109
+
110
+ # Unimplemented indicates operation is not implemented or not
111
+ # supported/enabled in this service.
112
+ UNIMPLEMENTED = 12
113
+
114
+ # Internal errors. Means some invariants expected by underlying system has
115
+ # been broken. If you see one of these errors, something is very broken.
116
+ INTERNAL = 13
117
+
118
+ # Unavailable indicates the service is currently unavailable. This is a
119
+ # most likely a transient condition and may be corrected by retrying with
120
+ # a backoff. Note that it is not always safe to retry non-idempotent
121
+ # operations.
122
+ #
123
+ # See litmus test above for deciding between FailedPrecondition, Aborted,
124
+ # and Unavailable.
125
+ UNAVAILABLE = 14
126
+
127
+ # DataLoss indicates unrecoverable data loss or corruption.
128
+ DATA_LOSS = 15
129
+
130
+ # Unauthenticated indicates the request does not have valid authentication
131
+ # credentials for the operation.
132
+ UNAUTHENTICATED = 16
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright 2015 gRPC authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative '../grpc'
16
+
17
+ # GRPC contains the General RPC module.
18
+ module GRPC
19
+ module Core
20
+ # TimeConsts is a module from the C extension.
21
+ #
22
+ # Here it's re-opened to add a utility func.
23
+ module TimeConsts
24
+ # Converts a time delta to an absolute deadline.
25
+ #
26
+ # Assumes timeish is a relative time, and converts its to an absolute,
27
+ # with following exceptions:
28
+ #
29
+ # * if timish is one of the TimeConsts.TimeSpec constants the value is
30
+ # preserved.
31
+ # * timish < 0 => TimeConsts.INFINITE_FUTURE
32
+ # * timish == 0 => TimeConsts.ZERO
33
+ #
34
+ # @param timeish [Number|TimeSpec]
35
+ # @return [Number|TimeSpec]
36
+ def from_relative_time(timeish)
37
+ if timeish.is_a? TimeSpec
38
+ timeish
39
+ elsif timeish.nil?
40
+ TimeConsts::ZERO
41
+ elsif !timeish.is_a? Numeric
42
+ fail(TypeError,
43
+ "Cannot make an absolute deadline from #{timeish.inspect}")
44
+ elsif timeish < 0
45
+ TimeConsts::INFINITE_FUTURE
46
+ elsif timeish.zero?
47
+ TimeConsts::ZERO
48
+ else
49
+ Time.now + timeish
50
+ end
51
+ end
52
+
53
+ module_function :from_relative_time
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,277 @@
1
+ # Copyright 2015 gRPC authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative './structs'
16
+ require_relative './core/status_codes'
17
+ require_relative './google_rpc_status_utils'
18
+
19
+ # GRPC contains the General RPC module.
20
+ module GRPC
21
+ # BadStatus is an exception class that indicates that an error occurred at
22
+ # either end of a GRPC connection. When raised, it indicates that a status
23
+ # error should be returned to the other end of a GRPC connection; when
24
+ # caught it means that this end received a status error.
25
+ #
26
+ # There is also subclass of BadStatus in this module for each GRPC status.
27
+ # E.g., the GRPC::Cancelled class corresponds to status CANCELLED.
28
+ #
29
+ # See
30
+ # https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/status.h
31
+ # for detailed descriptions of each status code.
32
+ class BadStatus < StandardError
33
+ attr_reader :code, :details, :metadata, :debug_error_string
34
+
35
+ include GRPC::Core::StatusCodes
36
+
37
+ # @param code [Numeric] the status code
38
+ # @param details [String] the details of the exception
39
+ # @param metadata [Hash] the error's metadata
40
+ def initialize(code,
41
+ details = 'unknown cause',
42
+ metadata = {},
43
+ debug_error_string = nil)
44
+ exception_message = "#{code}:#{details}"
45
+ if debug_error_string
46
+ exception_message += ". debug_error_string:#{debug_error_string}"
47
+ end
48
+ super(exception_message)
49
+ @code = code
50
+ @details = details
51
+ @metadata = metadata
52
+ @debug_error_string = debug_error_string
53
+ end
54
+
55
+ # Converts the exception to a {Struct::Status} for use in the networking
56
+ # wrapper layer.
57
+ #
58
+ # @return [Struct::Status] with the same code and details
59
+ def to_status
60
+ Struct::Status.new(code, details, metadata, debug_error_string)
61
+ end
62
+
63
+ # Converts the exception to a deserialized {Google::Rpc::Status} object.
64
+ # Returns `nil` if the `grpc-status-details-bin` trailer could not be
65
+ # converted to a {Google::Rpc::Status} due to the server not providing
66
+ # the necessary trailers.
67
+ #
68
+ # @return [Google::Rpc::Status, nil]
69
+ def to_rpc_status
70
+ GoogleRpcStatusUtils.extract_google_rpc_status(to_status)
71
+ rescue Google::Protobuf::ParseError => parse_error
72
+ GRPC.logger.warn('parse error: to_rpc_status failed')
73
+ GRPC.logger.warn(parse_error)
74
+ nil
75
+ end
76
+
77
+ def self.new_status_exception(code,
78
+ details = 'unknown cause',
79
+ metadata = {},
80
+ debug_error_string = nil)
81
+ codes = {}
82
+ codes[OK] = Ok
83
+ codes[CANCELLED] = Cancelled
84
+ codes[UNKNOWN] = Unknown
85
+ codes[INVALID_ARGUMENT] = InvalidArgument
86
+ codes[DEADLINE_EXCEEDED] = DeadlineExceeded
87
+ codes[NOT_FOUND] = NotFound
88
+ codes[ALREADY_EXISTS] = AlreadyExists
89
+ codes[PERMISSION_DENIED] = PermissionDenied
90
+ codes[UNAUTHENTICATED] = Unauthenticated
91
+ codes[RESOURCE_EXHAUSTED] = ResourceExhausted
92
+ codes[FAILED_PRECONDITION] = FailedPrecondition
93
+ codes[ABORTED] = Aborted
94
+ codes[OUT_OF_RANGE] = OutOfRange
95
+ codes[UNIMPLEMENTED] = Unimplemented
96
+ codes[INTERNAL] = Internal
97
+ codes[UNAVAILABLE] = Unavailable
98
+ codes[DATA_LOSS] = DataLoss
99
+
100
+ if codes[code].nil?
101
+ BadStatus.new(code, details, metadata, debug_error_string)
102
+ else
103
+ codes[code].new(details, metadata, debug_error_string)
104
+ end
105
+ end
106
+ end
107
+
108
+ # GRPC status code corresponding to status OK
109
+ class Ok < BadStatus
110
+ def initialize(details = 'unknown cause',
111
+ metadata = {},
112
+ debug_error_string = nil)
113
+ super(Core::StatusCodes::OK,
114
+ details, metadata, debug_error_string)
115
+ end
116
+ end
117
+
118
+ # GRPC status code corresponding to status CANCELLED
119
+ class Cancelled < BadStatus
120
+ def initialize(details = 'unknown cause',
121
+ metadata = {},
122
+ debug_error_string = nil)
123
+ super(Core::StatusCodes::CANCELLED,
124
+ details, metadata, debug_error_string)
125
+ end
126
+ end
127
+
128
+ # GRPC status code corresponding to status UNKNOWN
129
+ class Unknown < BadStatus
130
+ def initialize(details = 'unknown cause',
131
+ metadata = {},
132
+ debug_error_string = nil)
133
+ super(Core::StatusCodes::UNKNOWN,
134
+ details, metadata, debug_error_string)
135
+ end
136
+ end
137
+
138
+ # GRPC status code corresponding to status INVALID_ARGUMENT
139
+ class InvalidArgument < BadStatus
140
+ def initialize(details = 'unknown cause',
141
+ metadata = {},
142
+ debug_error_string = nil)
143
+ super(Core::StatusCodes::INVALID_ARGUMENT,
144
+ details, metadata, debug_error_string)
145
+ end
146
+ end
147
+
148
+ # GRPC status code corresponding to status DEADLINE_EXCEEDED
149
+ class DeadlineExceeded < BadStatus
150
+ def initialize(details = 'unknown cause',
151
+ metadata = {},
152
+ debug_error_string = nil)
153
+ super(Core::StatusCodes::DEADLINE_EXCEEDED,
154
+ details, metadata, debug_error_string)
155
+ end
156
+ end
157
+
158
+ # GRPC status code corresponding to status NOT_FOUND
159
+ class NotFound < BadStatus
160
+ def initialize(details = 'unknown cause',
161
+ metadata = {},
162
+ debug_error_string = nil)
163
+ super(Core::StatusCodes::NOT_FOUND,
164
+ details, metadata, debug_error_string)
165
+ end
166
+ end
167
+
168
+ # GRPC status code corresponding to status ALREADY_EXISTS
169
+ class AlreadyExists < BadStatus
170
+ def initialize(details = 'unknown cause',
171
+ metadata = {},
172
+ debug_error_string = nil)
173
+ super(Core::StatusCodes::ALREADY_EXISTS,
174
+ details, metadata, debug_error_string)
175
+ end
176
+ end
177
+
178
+ # GRPC status code corresponding to status PERMISSION_DENIED
179
+ class PermissionDenied < BadStatus
180
+ def initialize(details = 'unknown cause',
181
+ metadata = {},
182
+ debug_error_string = nil)
183
+ super(Core::StatusCodes::PERMISSION_DENIED,
184
+ details, metadata, debug_error_string)
185
+ end
186
+ end
187
+
188
+ # GRPC status code corresponding to status UNAUTHENTICATED
189
+ class Unauthenticated < BadStatus
190
+ def initialize(details = 'unknown cause',
191
+ metadata = {},
192
+ debug_error_string = nil)
193
+ super(Core::StatusCodes::UNAUTHENTICATED,
194
+ details, metadata, debug_error_string)
195
+ end
196
+ end
197
+
198
+ # GRPC status code corresponding to status RESOURCE_EXHAUSTED
199
+ class ResourceExhausted < BadStatus
200
+ def initialize(details = 'unknown cause',
201
+ metadata = {},
202
+ debug_error_string = nil)
203
+ super(Core::StatusCodes::RESOURCE_EXHAUSTED,
204
+ details, metadata, debug_error_string)
205
+ end
206
+ end
207
+
208
+ # GRPC status code corresponding to status FAILED_PRECONDITION
209
+ class FailedPrecondition < BadStatus
210
+ def initialize(details = 'unknown cause',
211
+ metadata = {},
212
+ debug_error_string = nil)
213
+ super(Core::StatusCodes::FAILED_PRECONDITION,
214
+ details, metadata, debug_error_string)
215
+ end
216
+ end
217
+
218
+ # GRPC status code corresponding to status ABORTED
219
+ class Aborted < BadStatus
220
+ def initialize(details = 'unknown cause',
221
+ metadata = {},
222
+ debug_error_string = nil)
223
+ super(Core::StatusCodes::ABORTED,
224
+ details, metadata, debug_error_string)
225
+ end
226
+ end
227
+
228
+ # GRPC status code corresponding to status OUT_OF_RANGE
229
+ class OutOfRange < BadStatus
230
+ def initialize(details = 'unknown cause',
231
+ metadata = {},
232
+ debug_error_string = nil)
233
+ super(Core::StatusCodes::OUT_OF_RANGE,
234
+ details, metadata, debug_error_string)
235
+ end
236
+ end
237
+
238
+ # GRPC status code corresponding to status UNIMPLEMENTED
239
+ class Unimplemented < BadStatus
240
+ def initialize(details = 'unknown cause',
241
+ metadata = {},
242
+ debug_error_string = nil)
243
+ super(Core::StatusCodes::UNIMPLEMENTED,
244
+ details, metadata, debug_error_string)
245
+ end
246
+ end
247
+
248
+ # GRPC status code corresponding to status INTERNAL
249
+ class Internal < BadStatus
250
+ def initialize(details = 'unknown cause',
251
+ metadata = {},
252
+ debug_error_string = nil)
253
+ super(Core::StatusCodes::INTERNAL,
254
+ details, metadata, debug_error_string)
255
+ end
256
+ end
257
+
258
+ # GRPC status code corresponding to status UNAVAILABLE
259
+ class Unavailable < BadStatus
260
+ def initialize(details = 'unknown cause',
261
+ metadata = {},
262
+ debug_error_string = nil)
263
+ super(Core::StatusCodes::UNAVAILABLE,
264
+ details, metadata, debug_error_string)
265
+ end
266
+ end
267
+
268
+ # GRPC status code corresponding to status DATA_LOSS
269
+ class DataLoss < BadStatus
270
+ def initialize(details = 'unknown cause',
271
+ metadata = {},
272
+ debug_error_string = nil)
273
+ super(Core::StatusCodes::DATA_LOSS,
274
+ details, metadata, debug_error_string)
275
+ end
276
+ end
277
+ end