grpc 1.60.0.pre1-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32-msvcrt.ruby +0 -0
  4. data/grpc_c.64-msvcrt.ruby +0 -0
  5. data/grpc_c.64-ucrt.ruby +0 -0
  6. data/src/ruby/bin/math_client.rb +140 -0
  7. data/src/ruby/bin/math_pb.rb +40 -0
  8. data/src/ruby/bin/math_server.rb +191 -0
  9. data/src/ruby/bin/math_services_pb.rb +51 -0
  10. data/src/ruby/bin/noproto_client.rb +93 -0
  11. data/src/ruby/bin/noproto_server.rb +97 -0
  12. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
  13. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
  14. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
  15. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
  16. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  17. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  18. data/src/ruby/ext/grpc/extconf.rb +270 -0
  19. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  20. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  21. data/src/ruby/ext/grpc/rb_call.c +1075 -0
  22. data/src/ruby/ext/grpc/rb_call.h +57 -0
  23. data/src/ruby/ext/grpc/rb_call_credentials.c +340 -0
  24. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  25. data/src/ruby/ext/grpc/rb_channel.c +875 -0
  26. data/src/ruby/ext/grpc/rb_channel.h +35 -0
  27. data/src/ruby/ext/grpc/rb_channel_args.c +172 -0
  28. data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
  29. data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
  30. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  31. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  32. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  33. data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
  34. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  35. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  36. data/src/ruby/ext/grpc/rb_event_thread.c +161 -0
  37. data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
  38. data/src/ruby/ext/grpc/rb_grpc.c +496 -0
  39. data/src/ruby/ext/grpc/rb_grpc.h +83 -0
  40. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +603 -0
  41. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +910 -0
  42. data/src/ruby/ext/grpc/rb_loader.c +61 -0
  43. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  44. data/src/ruby/ext/grpc/rb_server.c +405 -0
  45. data/src/ruby/ext/grpc/rb_server.h +32 -0
  46. data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
  47. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  48. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
  49. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  50. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
  51. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  52. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  53. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  54. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  55. data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
  56. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  57. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  58. data/src/ruby/lib/grpc/errors.rb +277 -0
  59. data/src/ruby/lib/grpc/generic/active_call.rb +670 -0
  60. data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
  61. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  62. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  63. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  64. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  65. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  66. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  67. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  68. data/src/ruby/lib/grpc/grpc.rb +24 -0
  69. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  70. data/src/ruby/lib/grpc/notifier.rb +45 -0
  71. data/src/ruby/lib/grpc/structs.rb +15 -0
  72. data/src/ruby/lib/grpc/version.rb +18 -0
  73. data/src/ruby/lib/grpc.rb +37 -0
  74. data/src/ruby/pb/README.md +42 -0
  75. data/src/ruby/pb/generate_proto_ruby.sh +46 -0
  76. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  77. data/src/ruby/pb/grpc/health/v1/health_pb.rb +42 -0
  78. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  79. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  80. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  81. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  82. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
  83. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +71 -0
  84. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -0
  85. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +174 -0
  86. data/src/ruby/pb/test/client.rb +785 -0
  87. data/src/ruby/pb/test/server.rb +252 -0
  88. data/src/ruby/pb/test/xds_client.rb +415 -0
  89. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  90. data/src/ruby/spec/call_spec.rb +180 -0
  91. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  92. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  93. data/src/ruby/spec/channel_spec.rb +207 -0
  94. data/src/ruby/spec/client_auth_spec.rb +152 -0
  95. data/src/ruby/spec/client_server_spec.rb +676 -0
  96. data/src/ruby/spec/compression_options_spec.rb +149 -0
  97. data/src/ruby/spec/debug_message_spec.rb +134 -0
  98. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  99. data/src/ruby/spec/errors_spec.rb +142 -0
  100. data/src/ruby/spec/generic/active_call_spec.rb +692 -0
  101. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  102. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  103. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  104. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  105. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  106. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  107. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  108. data/src/ruby/spec/generic/service_spec.rb +263 -0
  109. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  110. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  112. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  113. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  114. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  115. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  116. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  117. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  118. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  119. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  120. data/src/ruby/spec/server_spec.rb +231 -0
  121. data/src/ruby/spec/spec_helper.rb +61 -0
  122. data/src/ruby/spec/support/helpers.rb +107 -0
  123. data/src/ruby/spec/support/services.rb +160 -0
  124. data/src/ruby/spec/testdata/README +1 -0
  125. data/src/ruby/spec/testdata/ca.pem +20 -0
  126. data/src/ruby/spec/testdata/client.key +28 -0
  127. data/src/ruby/spec/testdata/client.pem +20 -0
  128. data/src/ruby/spec/testdata/server1.key +28 -0
  129. data/src/ruby/spec/testdata/server1.pem +22 -0
  130. data/src/ruby/spec/time_consts_spec.rb +74 -0
  131. data/src/ruby/spec/user_agent_spec.rb +74 -0
  132. metadata +405 -0
@@ -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 <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
+ }
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
+ }
@@ -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
@@ -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