gapic-common 0.14.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/lib/gapic/call_options/error_codes.rb +74 -0
- data/lib/gapic/call_options/retry_policy.rb +6 -30
- data/lib/gapic/call_options.rb +1 -0
- data/lib/gapic/common/version.rb +1 -1
- data/lib/gapic/rest/client_stub.rb +94 -7
- data/lib/gapic/rest/error.rb +69 -1
- data/lib/gapic/rest/grpc_transcoder/http_binding.rb +54 -1
- data/lib/gapic/rest/grpc_transcoder.rb +5 -30
- data/lib/gapic/rest/server_stream.rb +1 -1
- data/lib/gapic/rest/transport_operation.rb +38 -0
- data/lib/gapic/rest.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 508b67fe556c18e32cab88da23a0097e425df549e288b72fec7d4a891b6c06f5
|
4
|
+
data.tar.gz: 29bbc436a310b93f2f043502344783835ba25ed91d5ac8523c190da0ecd019b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34e4be1fc16714c9afc6bd0d9ca832ae7409521d0ec9f10c41860e817c8ee28599d6853a0c84a780dc3e3fc19d33882068d613f2691d6ee99392b68f2c5dbe04
|
7
|
+
data.tar.gz: 6f130dd5c05535efc27e67f51a6b593082519a04601d69111db010d097e7c150501e9cee2845d4937c175fce79451f413b5e125e9f74d01f66634d74d6b9604a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 0.17.1 (2023-02-09)
|
4
|
+
|
5
|
+
#### Bug Fixes
|
6
|
+
|
7
|
+
* add new class to the rest imports ([#913](https://github.com/googleapis/gapic-generator-ruby/issues/913))
|
8
|
+
|
9
|
+
### 0.17.0 (2023-02-09)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* add a transport operation class in Rest ([#911](https://github.com/googleapis/gapic-generator-ruby/issues/911))
|
14
|
+
|
15
|
+
### 0.16.0 (2022-12-12)
|
16
|
+
|
17
|
+
#### Features
|
18
|
+
|
19
|
+
* custom regapic exception wrapping ([#866](https://github.com/googleapis/gapic-generator-ruby/issues/866))
|
20
|
+
|
21
|
+
### 0.15.1 (2022-11-18)
|
22
|
+
|
23
|
+
#### Bug Fixes
|
24
|
+
|
25
|
+
* Fixed uninitialized constant when checking retry policy for a REST call ([#857](https://github.com/googleapis/gapic-generator-ruby/issues/857))
|
26
|
+
|
27
|
+
### 0.15.0 (2022-11-17)
|
28
|
+
|
29
|
+
#### Features
|
30
|
+
|
31
|
+
* retry policy now works for REST calls
|
32
|
+
|
3
33
|
### 0.14.0 (2022-11-08)
|
4
34
|
|
5
35
|
#### Features
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Copyright 2019 Google LLC
|
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
|
+
# https://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
|
+
module Gapic
|
16
|
+
class CallOptions
|
17
|
+
##
|
18
|
+
# @private
|
19
|
+
# The gRPC error codes and their HTTP mapping
|
20
|
+
#
|
21
|
+
module ErrorCodes
|
22
|
+
# @private
|
23
|
+
# See https://grpc.github.io/grpc/core/md_doc_statuscodes.html for a
|
24
|
+
# list of error codes.
|
25
|
+
error_code_mapping = [
|
26
|
+
"OK",
|
27
|
+
"CANCELLED",
|
28
|
+
"UNKNOWN",
|
29
|
+
"INVALID_ARGUMENT",
|
30
|
+
"DEADLINE_EXCEEDED",
|
31
|
+
"NOT_FOUND",
|
32
|
+
"ALREADY_EXISTS",
|
33
|
+
"PERMISSION_DENIED",
|
34
|
+
"RESOURCE_EXHAUSTED",
|
35
|
+
"FAILED_PRECONDITION",
|
36
|
+
"ABORTED",
|
37
|
+
"OUT_OF_RANGE",
|
38
|
+
"UNIMPLEMENTED",
|
39
|
+
"INTERNAL",
|
40
|
+
"UNAVAILABLE",
|
41
|
+
"DATA_LOSS",
|
42
|
+
"UNAUTHENTICATED"
|
43
|
+
].freeze
|
44
|
+
|
45
|
+
# @private
|
46
|
+
ERROR_STRING_MAPPING = error_code_mapping.each_with_index.to_h.freeze
|
47
|
+
|
48
|
+
# @private
|
49
|
+
HTTP_GRPC_CODE_MAP = {
|
50
|
+
400 => 3, # InvalidArgumentError
|
51
|
+
401 => 16, # UnauthenticatedError
|
52
|
+
403 => 7, # PermissionDeniedError
|
53
|
+
404 => 5, # NotFoundError
|
54
|
+
409 => 6, # AlreadyExistsError
|
55
|
+
412 => 9, # FailedPreconditionError
|
56
|
+
429 => 8, # ResourceExhaustedError
|
57
|
+
499 => 1, # CanceledError
|
58
|
+
500 => 13, # InternalError
|
59
|
+
501 => 12, # UnimplementedError
|
60
|
+
503 => 14, # UnavailableError
|
61
|
+
504 => 4 # DeadlineExceededError
|
62
|
+
}.freeze
|
63
|
+
|
64
|
+
# @private
|
65
|
+
# Converts http error codes into corresponding gRPC ones
|
66
|
+
def self.grpc_error_for http_error_code
|
67
|
+
return 2 unless http_error_code
|
68
|
+
|
69
|
+
# The http status codes mapped to their error classes.
|
70
|
+
HTTP_GRPC_CODE_MAP[http_error_code] || 2 # UnknownError
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -12,6 +12,8 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require "gapic/call_options/error_codes"
|
16
|
+
|
15
17
|
module Gapic
|
16
18
|
class CallOptions
|
17
19
|
##
|
@@ -101,38 +103,12 @@ module Gapic
|
|
101
103
|
[retry_codes, initial_delay, multiplier, max_delay].hash
|
102
104
|
end
|
103
105
|
|
104
|
-
# @private
|
105
|
-
# See https://grpc.github.io/grpc/core/md_doc_statuscodes.html for a
|
106
|
-
# list of error codes.
|
107
|
-
ERROR_CODE_MAPPING = [
|
108
|
-
"OK",
|
109
|
-
"CANCELLED",
|
110
|
-
"UNKNOWN",
|
111
|
-
"INVALID_ARGUMENT",
|
112
|
-
"DEADLINE_EXCEEDED",
|
113
|
-
"NOT_FOUND",
|
114
|
-
"ALREADY_EXISTS",
|
115
|
-
"PERMISSION_DENIED",
|
116
|
-
"RESOURCE_EXHAUSTED",
|
117
|
-
"FAILED_PRECONDITION",
|
118
|
-
"ABORTED",
|
119
|
-
"OUT_OF_RANGE",
|
120
|
-
"UNIMPLEMENTED",
|
121
|
-
"INTERNAL",
|
122
|
-
"UNAVAILABLE",
|
123
|
-
"DATA_LOSS",
|
124
|
-
"UNAUTHENTICATED"
|
125
|
-
].freeze
|
126
|
-
|
127
|
-
# @private
|
128
|
-
ERROR_STRING_MAPPING = ERROR_CODE_MAPPING.each_with_index.each_with_object({}) do |(str, num), hash|
|
129
|
-
hash[str] = num
|
130
|
-
end.freeze
|
131
|
-
|
132
106
|
private
|
133
107
|
|
134
108
|
def retry? error
|
135
|
-
error.is_a?(::GRPC::BadStatus) && retry_codes.include?(error.code)
|
109
|
+
(defined?(::GRPC) && error.is_a?(::GRPC::BadStatus) && retry_codes.include?(error.code)) ||
|
110
|
+
(error.respond_to?(:response_status) &&
|
111
|
+
retry_codes.include?(ErrorCodes.grpc_error_for(error.response_status)))
|
136
112
|
end
|
137
113
|
|
138
114
|
def delay!
|
@@ -145,7 +121,7 @@ module Gapic
|
|
145
121
|
Array(input_codes).map do |obj|
|
146
122
|
case obj
|
147
123
|
when String
|
148
|
-
ERROR_STRING_MAPPING[obj]
|
124
|
+
ErrorCodes::ERROR_STRING_MAPPING[obj]
|
149
125
|
when Integer
|
150
126
|
obj
|
151
127
|
end
|
data/lib/gapic/call_options.rb
CHANGED
data/lib/gapic/common/version.rb
CHANGED
@@ -34,9 +34,15 @@ module Gapic
|
|
34
34
|
# (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
|
35
35
|
# @param numeric_enums [Boolean] Whether to signal the server to JSON-encode enums as ints
|
36
36
|
#
|
37
|
+
# @param raise_faraday_errors [Boolean]
|
38
|
+
# Whether to raise Faraday errors instead of wrapping them in `Gapic::Rest::Error`
|
39
|
+
# Added for backwards compatibility.
|
40
|
+
# Default is `true`. All REST clients (except for old versions of `google-cloud-compute-v1`)
|
41
|
+
# should explicitly set this parameter to `false`.
|
42
|
+
#
|
37
43
|
# @yield [Faraday::Connection]
|
38
44
|
#
|
39
|
-
def initialize endpoint:, credentials:, numeric_enums: false
|
45
|
+
def initialize endpoint:, credentials:, numeric_enums: false, raise_faraday_errors: true
|
40
46
|
@endpoint = endpoint
|
41
47
|
@endpoint = "https://#{endpoint}" unless /^https?:/.match? endpoint
|
42
48
|
@endpoint = @endpoint.sub %r{/$}, ""
|
@@ -44,6 +50,8 @@ module Gapic
|
|
44
50
|
@credentials = credentials
|
45
51
|
@numeric_enums = numeric_enums
|
46
52
|
|
53
|
+
@raise_faraday_errors = raise_faraday_errors
|
54
|
+
|
47
55
|
@connection = Faraday.new url: @endpoint do |conn|
|
48
56
|
conn.headers = { "Content-Type" => "application/json" }
|
49
57
|
conn.request :google_authorization, @credentials unless @credentials.is_a? ::Symbol
|
@@ -125,21 +133,62 @@ module Gapic
|
|
125
133
|
# @param uri [String] uri to send this request to
|
126
134
|
# @param body [String, nil] a body to send with the request, nil for requests without a body
|
127
135
|
# @param params [Hash] query string parameters for the request
|
128
|
-
# @param options [::Gapic::CallOptions,Hash] gapic options to be applied
|
129
|
-
# to the REST call. Currently only timeout and headers are supported.
|
136
|
+
# @param options [::Gapic::CallOptions,Hash] gapic options to be applied to the REST call.
|
130
137
|
# @param is_server_streaming [Boolean] flag if method is streaming
|
131
138
|
# @yieldparam chunk [String] The chunk of data received during server streaming.
|
132
139
|
# @return [Faraday::Response]
|
133
|
-
def make_http_request verb, uri:, body:, params:, options:, is_server_streaming: false
|
140
|
+
def make_http_request verb, uri:, body:, params:, options:, is_server_streaming: false, &block
|
141
|
+
# Converts hash and nil to an options object
|
142
|
+
options = ::Gapic::CallOptions.new(**options.to_h) unless options.is_a? ::Gapic::CallOptions
|
143
|
+
deadline = calculate_deadline options
|
144
|
+
retried_exception = nil
|
145
|
+
next_timeout = get_timeout deadline
|
146
|
+
|
147
|
+
begin
|
148
|
+
base_make_http_request(verb: verb, uri: uri, body: body,
|
149
|
+
params: params, metadata: options.metadata,
|
150
|
+
timeout: next_timeout,
|
151
|
+
is_server_streaming: is_server_streaming,
|
152
|
+
&block)
|
153
|
+
rescue ::Faraday::TimeoutError => e
|
154
|
+
raise if @raise_faraday_errors
|
155
|
+
raise Gapic::Rest::DeadlineExceededError.wrap_faraday_error e, root_cause: retried_exception
|
156
|
+
rescue ::Faraday::Error => e
|
157
|
+
next_timeout = get_timeout deadline
|
158
|
+
|
159
|
+
if check_retry?(next_timeout) && options.retry_policy.call(e)
|
160
|
+
retried_exception = e
|
161
|
+
retry
|
162
|
+
end
|
163
|
+
|
164
|
+
raise if @raise_faraday_errors
|
165
|
+
raise ::Gapic::Rest::Error.wrap_faraday_error e
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
##
|
170
|
+
# @private
|
171
|
+
# Sends a http request via Faraday
|
172
|
+
#
|
173
|
+
# @param verb [Symbol] http verb
|
174
|
+
# @param uri [String] uri to send this request to
|
175
|
+
# @param body [String, nil] a body to send with the request, nil for requests without a body
|
176
|
+
# @param params [Hash] query string parameters for the request
|
177
|
+
# @param metadata [Hash] additional headers for the request
|
178
|
+
# @param is_server_streaming [Boolean] flag if method is streaming
|
179
|
+
# @yieldparam chunk [String] The chunk of data received during server streaming.
|
180
|
+
# @return [Faraday::Response]
|
181
|
+
def base_make_http_request verb:, uri:, body:, params:, metadata:,
|
182
|
+
timeout:, is_server_streaming: false
|
134
183
|
if @numeric_enums && (!params.key?("$alt") || params["$alt"] == "json")
|
135
184
|
params = params.merge({ "$alt" => "json;enum-encoding=int" })
|
136
185
|
end
|
137
|
-
|
186
|
+
|
138
187
|
@connection.send verb, uri do |req|
|
139
188
|
req.params = params if params.any?
|
140
189
|
req.body = body unless body.nil?
|
141
|
-
req.headers = req.headers.merge
|
142
|
-
req.options.timeout =
|
190
|
+
req.headers = req.headers.merge metadata
|
191
|
+
req.options.timeout = timeout if timeout&.positive?
|
143
192
|
if is_server_streaming
|
144
193
|
req.options.on_data = proc do |chunk, _overall_received_bytes|
|
145
194
|
yield chunk
|
@@ -147,6 +196,44 @@ module Gapic
|
|
147
196
|
end
|
148
197
|
end
|
149
198
|
end
|
199
|
+
|
200
|
+
private
|
201
|
+
|
202
|
+
##
|
203
|
+
# Calculates deadline
|
204
|
+
#
|
205
|
+
# @param options [Gapic::CallOptions] call options for this call
|
206
|
+
#
|
207
|
+
# @return [Numeric, nil] Deadline against a POSIX clock_gettime()
|
208
|
+
def calculate_deadline options
|
209
|
+
return if options.timeout.nil?
|
210
|
+
return if options.timeout.negative?
|
211
|
+
|
212
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC) + options.timeout
|
213
|
+
end
|
214
|
+
|
215
|
+
##
|
216
|
+
# Calculates timeout (seconds) to use as a Faraday timeout
|
217
|
+
#
|
218
|
+
# @param deadline [Numeric, nil] deadline
|
219
|
+
#
|
220
|
+
# @return [Numeric, nil] Timeout (seconds)
|
221
|
+
def get_timeout deadline
|
222
|
+
return if deadline.nil?
|
223
|
+
deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
224
|
+
end
|
225
|
+
|
226
|
+
##
|
227
|
+
# Whether the timeout should be retried
|
228
|
+
#
|
229
|
+
# @param timeout [Numeric, nil]
|
230
|
+
#
|
231
|
+
# @return [Boolean] whether the timeout should be retried
|
232
|
+
def check_retry? timeout
|
233
|
+
return true if timeout.nil?
|
234
|
+
|
235
|
+
timeout.positive?
|
236
|
+
end
|
150
237
|
end
|
151
238
|
end
|
152
239
|
end
|
data/lib/gapic/rest/error.rb
CHANGED
@@ -55,6 +55,17 @@ module Gapic
|
|
55
55
|
#
|
56
56
|
# @return [ Gapic::Rest::Error]
|
57
57
|
def wrap_faraday_error err
|
58
|
+
message, status_code, status, details, headers = parse_faraday_error err
|
59
|
+
Gapic::Rest::Error.new message, status_code, status: status, details: details, headers: headers
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# @private
|
64
|
+
# Tries to get the error information from Faraday error
|
65
|
+
#
|
66
|
+
# @param err [Faraday::Error] the Faraday error to extract information from
|
67
|
+
# @return [Array(String, String, String, String, String)]
|
68
|
+
def parse_faraday_error err
|
58
69
|
message = err.message
|
59
70
|
status_code = err.response_status
|
60
71
|
status = nil
|
@@ -67,7 +78,7 @@ module Gapic
|
|
67
78
|
status_code = code unless code.nil?
|
68
79
|
end
|
69
80
|
|
70
|
-
|
81
|
+
[message, status_code, status, details, headers]
|
71
82
|
end
|
72
83
|
|
73
84
|
private
|
@@ -133,5 +144,62 @@ module Gapic
|
|
133
144
|
end
|
134
145
|
end
|
135
146
|
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# An error class that represents DeadlineExceeded error for Rest
|
150
|
+
# with an optional retry root cause.
|
151
|
+
#
|
152
|
+
# If the deadline for making a call was exceeded during the rest calls,
|
153
|
+
# this exception is thrown wrapping Faraday::TimeoutError.
|
154
|
+
#
|
155
|
+
# If there were other exceptions retried before that, the last one will be
|
156
|
+
# saved as a "root_cause".
|
157
|
+
#
|
158
|
+
# @!attribute [r] root_cause
|
159
|
+
# @return [Object, nil] The exception that was being retried
|
160
|
+
# when the Faraday::TimeoutError error occured.
|
161
|
+
#
|
162
|
+
class DeadlineExceededError < Error
|
163
|
+
attr_reader :root_cause
|
164
|
+
|
165
|
+
##
|
166
|
+
# @private
|
167
|
+
# @param message [String, nil] error message
|
168
|
+
# @param status_code [Integer, nil] HTTP status code of this error
|
169
|
+
# @param status [String, nil] The text representation of status as parsed from the response body
|
170
|
+
# @param details [Object, nil] Details data of this error
|
171
|
+
# @param headers [Object, nil] Http headers data of this error
|
172
|
+
# @param root_cause [Object, nil] The exception that was being retried
|
173
|
+
# when the Faraday::TimeoutError occured.
|
174
|
+
#
|
175
|
+
def initialize message, status_code, status: nil, details: nil, headers: nil, root_cause: nil
|
176
|
+
super message, status_code, status: status, details: details, headers: headers
|
177
|
+
@root_cause = root_cause
|
178
|
+
end
|
179
|
+
|
180
|
+
class << self
|
181
|
+
##
|
182
|
+
# @private
|
183
|
+
# This creates a new error message wrapping the Faraday's one. Additionally
|
184
|
+
# it tries to parse and set a detailed message and an error code from
|
185
|
+
# from the Google Cloud's response body
|
186
|
+
#
|
187
|
+
# @param err [Faraday::TimeoutError] the Faraday error to wrap
|
188
|
+
#
|
189
|
+
# @param root_cause [Object, nil] The exception that was being retried
|
190
|
+
# when the Faraday::TimeoutError occured.
|
191
|
+
#
|
192
|
+
# @return [ Gapic::Rest::DeadlineExceededError]
|
193
|
+
def wrap_faraday_error err, root_cause: nil
|
194
|
+
message, status_code, status, details, headers = parse_faraday_error err
|
195
|
+
Gapic::Rest::DeadlineExceededError.new message,
|
196
|
+
status_code,
|
197
|
+
status: status,
|
198
|
+
details: details,
|
199
|
+
headers: headers,
|
200
|
+
root_cause: root_cause
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
136
204
|
end
|
137
205
|
end
|
@@ -15,6 +15,7 @@
|
|
15
15
|
module Gapic
|
16
16
|
module Rest
|
17
17
|
class GrpcTranscoder
|
18
|
+
##
|
18
19
|
# @private
|
19
20
|
# A single binding for GRPC-REST transcoding of a request
|
20
21
|
# It includes a uri template with bound field parameters, a HTTP method type,
|
@@ -25,7 +26,8 @@ module Gapic
|
|
25
26
|
# @attribute [r] template
|
26
27
|
# @return [String] The URI template for the request.
|
27
28
|
# @attribute [r] field_bindings
|
28
|
-
# @return [Array<FieldBinding>]
|
29
|
+
# @return [Array<Gapic::Rest::GrpcTranscoder::HttpBinding::FieldBinding>]
|
30
|
+
# The field bindings for the URI template variables.
|
29
31
|
# @attribute [r] body
|
30
32
|
# @return [String] The body template for the request.
|
31
33
|
class HttpBinding
|
@@ -41,6 +43,57 @@ module Gapic
|
|
41
43
|
@body = body
|
42
44
|
end
|
43
45
|
|
46
|
+
##
|
47
|
+
# @private
|
48
|
+
# Creates a new HttpBinding.
|
49
|
+
#
|
50
|
+
# @param uri_method [Symbol] The rest verb for the binding.
|
51
|
+
# @param uri_template [String] The string with uri template for the binding.
|
52
|
+
# This string will be expanded with the parameters from variable bindings.
|
53
|
+
# @param matches [Array<Array>] Variable bindings in an array. Every element
|
54
|
+
# of the array is an [Array] triplet, where:
|
55
|
+
# - the first element is a [String] field path (e.g. `foo.bar`) in the request
|
56
|
+
# to bind to
|
57
|
+
# - the second element is a [Regexp] to match the field value
|
58
|
+
# - the third element is a [Boolean] whether the slashes in the field value
|
59
|
+
# should be preserved (as opposed to escaped) when expanding the uri template.
|
60
|
+
# @param body [String, Nil] The body template, e.g. `*` or a field path.
|
61
|
+
#
|
62
|
+
# @return [Gapic::Rest::GrpcTranscoder::HttpBinding] The new binding.
|
63
|
+
def self.create_with_validation uri_method:, uri_template:, matches: [], body: nil
|
64
|
+
template = uri_template
|
65
|
+
|
66
|
+
matches.each do |name, _regex, _preserve_slashes|
|
67
|
+
unless uri_template =~ /({#{Regexp.quote name}})/
|
68
|
+
err_msg = "Binding configuration is incorrect: missing parameter in the URI template.\n" \
|
69
|
+
"Parameter `#{name}` is specified for matching but there is no corresponding parameter " \
|
70
|
+
"`{#{name}}` in the URI template."
|
71
|
+
raise ::Gapic::Common::Error, err_msg
|
72
|
+
end
|
73
|
+
|
74
|
+
template = template.gsub "{#{name}}", ""
|
75
|
+
end
|
76
|
+
|
77
|
+
if template =~ /{([a-zA-Z_.]+)}/
|
78
|
+
err_name = Regexp.last_match[1]
|
79
|
+
err_msg = "Binding configuration is incorrect: missing match configuration.\n" \
|
80
|
+
"Parameter `{#{err_name}}` is specified in the URI template but there is no " \
|
81
|
+
"corresponding match configuration for `#{err_name}`."
|
82
|
+
raise ::Gapic::Common::Error, err_msg
|
83
|
+
end
|
84
|
+
|
85
|
+
if body&.include? "."
|
86
|
+
raise ::Gapic::Common::Error,
|
87
|
+
"Provided body template `#{body}` points to a field in a sub-message. This is not supported."
|
88
|
+
end
|
89
|
+
|
90
|
+
field_bindings = matches.map do |name, regex, preserve_slashes|
|
91
|
+
HttpBinding::FieldBinding.new name, regex, preserve_slashes
|
92
|
+
end
|
93
|
+
|
94
|
+
HttpBinding.new uri_method, uri_template, field_bindings, body
|
95
|
+
end
|
96
|
+
|
44
97
|
# A single binding for a field of a request message.
|
45
98
|
# @attribute [r] field_path
|
46
99
|
# @return [String] The path of the bound field, e.g. `foo.bar`.
|
@@ -44,36 +44,11 @@ module Gapic
|
|
44
44
|
#
|
45
45
|
# @return [Gapic::Rest::GrpcTranscoder] The updated transcoder.
|
46
46
|
def with_bindings uri_method:, uri_template:, matches: [], body: nil
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
"Parameter `#{name}` is specified for matching but there is no corresponding parameter " \
|
53
|
-
"`{#{name}}` in the URI template."
|
54
|
-
raise ::Gapic::Common::Error, err_msg
|
55
|
-
end
|
56
|
-
|
57
|
-
template = template.gsub "{#{name}}", ""
|
58
|
-
end
|
59
|
-
|
60
|
-
if template =~ /{([a-zA-Z_.]+)}/
|
61
|
-
err_name = Regexp.last_match[1]
|
62
|
-
err_msg = "Binding configuration is incorrect: missing match configuration.\n" \
|
63
|
-
"Parameter `{#{err_name}}` is specified in the URI template but there is no " \
|
64
|
-
"corresponding match configuration for `#{err_name}`."
|
65
|
-
raise ::Gapic::Common::Error, err_msg
|
66
|
-
end
|
67
|
-
|
68
|
-
if body&.include? "."
|
69
|
-
raise ::Gapic::Common::Error,
|
70
|
-
"Provided body template `#{body}` points to a field in a sub-message. This is not supported."
|
71
|
-
end
|
72
|
-
|
73
|
-
field_bindings = matches.map do |name, regex, preserve_slashes|
|
74
|
-
HttpBinding::FieldBinding.new name, regex, preserve_slashes
|
75
|
-
end
|
76
|
-
GrpcTranscoder.new @bindings + [HttpBinding.new(uri_method, uri_template, field_bindings, body)]
|
47
|
+
binding = HttpBinding.create_with_validation(uri_method: uri_method,
|
48
|
+
uri_template: uri_template,
|
49
|
+
matches: matches,
|
50
|
+
body: body)
|
51
|
+
GrpcTranscoder.new @bindings + [binding]
|
77
52
|
end
|
78
53
|
|
79
54
|
##
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright 2023 Google LLC
|
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
|
+
# https://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
|
+
module Gapic
|
16
|
+
module Rest
|
17
|
+
##
|
18
|
+
# Surfaces information about the active call
|
19
|
+
# from the underlying transport library.
|
20
|
+
#
|
21
|
+
class TransportOperation
|
22
|
+
##
|
23
|
+
# @private
|
24
|
+
# The underlying transport's library object that describes the active call, if any.
|
25
|
+
# It is not guaranteed to be any specific type, and its value is not guarateed to be stable.
|
26
|
+
# @return [::Object, nil, ::Faraday::Response]
|
27
|
+
attr_reader :underlying_op
|
28
|
+
|
29
|
+
##
|
30
|
+
# @private
|
31
|
+
# @param request [::Object, nil, ::Faraday::Response]
|
32
|
+
# The underlying transport's library object that describes the active call, if any.
|
33
|
+
def initialize underlying_op
|
34
|
+
@underlying_op = underlying_op
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/gapic/rest.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gapic-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Google API Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -288,6 +288,7 @@ files:
|
|
288
288
|
- RELEASING.md
|
289
289
|
- lib/gapic-common.rb
|
290
290
|
- lib/gapic/call_options.rb
|
291
|
+
- lib/gapic/call_options/error_codes.rb
|
291
292
|
- lib/gapic/call_options/retry_policy.rb
|
292
293
|
- lib/gapic/common.rb
|
293
294
|
- lib/gapic/common/error.rb
|
@@ -316,6 +317,7 @@ files:
|
|
316
317
|
- lib/gapic/rest/paged_enumerable.rb
|
317
318
|
- lib/gapic/rest/server_stream.rb
|
318
319
|
- lib/gapic/rest/threaded_enumerator.rb
|
320
|
+
- lib/gapic/rest/transport_operation.rb
|
319
321
|
- lib/gapic/stream_input.rb
|
320
322
|
homepage: https://github.com/googleapis/gapic-generator-ruby
|
321
323
|
licenses:
|
@@ -336,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
336
338
|
- !ruby/object:Gem::Version
|
337
339
|
version: '0'
|
338
340
|
requirements: []
|
339
|
-
rubygems_version: 3.
|
341
|
+
rubygems_version: 3.4.2
|
340
342
|
signing_key:
|
341
343
|
specification_version: 4
|
342
344
|
summary: Common code for GAPIC-generated API clients
|