gapic-common 0.20.0 → 0.21.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd54dc9471821e191b81b38efd0e03c24cfaaad13093b7b20d174a7235db9408
4
- data.tar.gz: dda7b540eedb2fb8f665548a6844b6c98c6b5e0b601d4627be16d229cdc1b65f
3
+ metadata.gz: b7c5286b152666f59249b7c1ba16867d494b934f2252bff17b68f1135ef47e97
4
+ data.tar.gz: 14bbbc1179570401141d6f62520bc2ff00b27f21f55431f0e3db2d3f4e7220e1
5
5
  SHA512:
6
- metadata.gz: cedbf49ae436a114a347723bda04637fee02481d7a56624f80f79ab1e2903ccc290a7667e1584d11c66bc0b60295333315f99ac15d01806c1713171ed3179dde
7
- data.tar.gz: a4f733db0e1bb0e158d982fe189dc510195e24299fa8880255917ae7a68b2a2d47ff740bf304fd187678c2ace7c9a75cdabf341347e0f0066fe16e40e7e8d0be
6
+ metadata.gz: f7e29a779c1fb17a88336b5c99c5635a9f196b275f9f381d56e25e8a5edc9ccf2e5ff9096500ab8bc33725489b793c2e1593bb38671da48b83529bba379562e0
7
+ data.tar.gz: ceb55e48e017ba629c0b583ebb9145d541a309998b29d5b47d40ef0819b0befde3659f39e37a4362691a248070042cd86a34f104100587b76ee742a6edec9565
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Release History
2
2
 
3
+ ### 0.21.1 (2023-12-14)
4
+
5
+ #### Bug Fixes
6
+
7
+ * add missing module import for universe_domain_concerns ([#1016](https://github.com/googleapis/gapic-generator-ruby/issues/1016))
8
+
9
+ ### 0.21.0 (2023-12-13)
10
+
11
+ #### Features
12
+
13
+ * Drop support for Ruby 2.6 ([#1009](https://github.com/googleapis/gapic-generator-ruby/issues/1009))
14
+ * Honor universe domain in stubs ([#1008](https://github.com/googleapis/gapic-generator-ruby/issues/1008))
15
+
3
16
  ### 0.20.0 (2023-08-31)
4
17
 
5
18
  #### Features
@@ -14,6 +14,6 @@
14
14
 
15
15
  module Gapic
16
16
  module Common
17
- VERSION = "0.20.0".freeze
17
+ VERSION = "0.21.1".freeze
18
18
  end
19
19
  end
data/lib/gapic/config.rb CHANGED
@@ -50,7 +50,7 @@ module Gapic
50
50
  #
51
51
  def config_attr name, default, *valid_values, &validator
52
52
  name = String(name).to_sym
53
- name_setter = "#{name}=".to_sym
53
+ name_setter = :"#{name}="
54
54
  raise NameError, "invalid config name #{name}" if name !~ /^[a-zA-Z]\w*$/ || name == :parent_config
55
55
  raise NameError, "method #{name} already exists" if method_defined? name
56
56
  raise NameError, "method #{name_setter} already exists" if method_defined? name_setter
@@ -58,7 +58,7 @@ module Gapic
58
58
  raise ArgumentError, "validation must be provided" if validator.nil? && valid_values.empty?
59
59
  validator ||= ->(value) { valid_values.any? { |v| v === value } }
60
60
 
61
- name_ivar = "@#{name}".to_sym
61
+ name_ivar = :"@#{name}"
62
62
 
63
63
  create_getter name_ivar, name, default
64
64
  create_setter name_ivar, name_setter, default, validator
@@ -91,8 +91,6 @@ module Gapic
91
91
  rpc_call = RpcCall.new @grpc_stub.method method_name
92
92
  response = rpc_call.call request, options: options, &block
93
93
  response
94
- rescue StandardError => e
95
- raise e
96
94
  ensure
97
95
  @mutex.synchronize { @concurrent_streams -= 1 }
98
96
  end
@@ -17,7 +17,7 @@ require "googleauth"
17
17
  require "gapic/grpc/service_stub/rpc_call"
18
18
  require "gapic/grpc/service_stub/channel"
19
19
  require "gapic/grpc/service_stub/channel_pool"
20
-
20
+ require "gapic/universe_domain_concerns"
21
21
 
22
22
  module Gapic
23
23
  ##
@@ -31,6 +31,8 @@ module Gapic
31
31
  # @return [Gapic::ServiceStub::ChannelPool] The instance of the ChannelPool class.
32
32
  #
33
33
  class ServiceStub
34
+ include UniverseDomainConcerns
35
+
34
36
  attr_reader :grpc_stub
35
37
  attr_reader :channel_pool
36
38
 
@@ -38,7 +40,12 @@ module Gapic
38
40
  # Creates a Gapic gRPC stub object.
39
41
  #
40
42
  # @param grpc_stub_class [Class] gRPC stub class to create a new instance of.
41
- # @param endpoint [String] The endpoint of the API.
43
+ # @param endpoint [String] The endpoint of the API. Overrides any endpoint_template.
44
+ # @param endpoint_template [String] The endpoint of the API, where the
45
+ # universe domain component of the hostname is marked by the string in
46
+ # the constant {UniverseDomainConcerns::ENDPOINT_SUBSTITUTION}.
47
+ # @param universe_domain [String] The universe domain in which calls should
48
+ # be made. Defaults to `googleapis.com`.
42
49
  # @param credentials [Google::Auth::Credentials, Signet::OAuth2::Client, String, Hash, Proc,
43
50
  # ::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] Provides the means for authenticating requests made by
44
51
  # the client. This parameter can be many types:
@@ -58,24 +65,32 @@ module Gapic
58
65
  # @param channel_pool_config [::Gapic::ServiceStub:ChannelPool::Configuration] The configuration for channel
59
66
  # pool. This argument will raise error when `credentials` is provided as a `::GRPC::Core::Channel`.
60
67
  #
61
- def initialize grpc_stub_class, endpoint:, credentials:, channel_args: nil,
62
- interceptors: nil, channel_pool_config: nil
68
+ def initialize grpc_stub_class,
69
+ credentials:,
70
+ endpoint: nil,
71
+ endpoint_template: nil,
72
+ universe_domain: nil,
73
+ channel_args: nil,
74
+ interceptors: nil,
75
+ channel_pool_config: nil
63
76
  raise ArgumentError, "grpc_stub_class is required" if grpc_stub_class.nil?
64
- raise ArgumentError, "endpoint is required" if endpoint.nil?
65
- raise ArgumentError, "credentials is required" if credentials.nil?
77
+
78
+ setup_universe_domain universe_domain: universe_domain,
79
+ endpoint: endpoint,
80
+ endpoint_template: endpoint_template,
81
+ credentials: credentials
66
82
 
67
83
  @channel_pool = nil
68
84
  @grpc_stub = nil
69
85
  channel_args = Hash channel_args
70
86
  interceptors = Array interceptors
71
87
 
72
-
73
88
  if channel_pool_config && channel_pool_config.channel_count > 1
74
- create_channel_pool grpc_stub_class, endpoint: endpoint, credentials: credentials,
89
+ create_channel_pool grpc_stub_class, endpoint: self.endpoint, credentials: self.credentials,
75
90
  channel_args: channel_args, interceptors: interceptors,
76
91
  channel_pool_config: channel_pool_config
77
92
  else
78
- create_grpc_stub grpc_stub_class, endpoint: endpoint, credentials: credentials,
93
+ create_grpc_stub grpc_stub_class, endpoint: self.endpoint, credentials: self.credentials,
79
94
  channel_args: channel_args, interceptors: interceptors
80
95
  end
81
96
  end
@@ -250,7 +250,7 @@ module Gapic
250
250
  # @return [Boolean]
251
251
  #
252
252
  def next_page_token?
253
- return if @response.nil?
253
+ return if @response.nil? # rubocop:disable Style/ReturnNilInPredicateMethodDefinition
254
254
 
255
255
  !@response.next_page_token.empty?
256
256
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  require "googleauth"
16
16
  require "gapic/rest/faraday_middleware"
17
+ require "gapic/universe_domain_concerns"
17
18
  require "faraday/retry"
18
19
 
19
20
  module Gapic
@@ -26,9 +27,16 @@ module Gapic
26
27
  # - store credentials and add auth information to the request
27
28
  #
28
29
  class ClientStub
30
+ include UniverseDomainConcerns
31
+
29
32
  ##
30
33
  # Initializes with an endpoint and credentials
31
- # @param endpoint [String] an endpoint for the service that this stub will send requests to
34
+ # @param endpoint [String] The endpoint of the API. Overrides any endpoint_template.
35
+ # @param endpoint_template [String] The endpoint of the API, where the
36
+ # universe domain component of the hostname is marked by the string in
37
+ # the constant {UniverseDomainConcerns::ENDPOINT_SUBSTITUTION}.
38
+ # @param universe_domain [String] The universe domain in which calls
39
+ # should be made. Defaults to `googleapis.com`.
32
40
  # @param credentials [Google::Auth::Credentials]
33
41
  # Credentials to send with calls in form of a googleauth credentials object.
34
42
  # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
@@ -42,19 +50,28 @@ module Gapic
42
50
  #
43
51
  # @yield [Faraday::Connection]
44
52
  #
45
- def initialize endpoint:, credentials:, numeric_enums: false, raise_faraday_errors: true
46
- @endpoint = endpoint
47
- @endpoint = "https://#{endpoint}" unless /^https?:/.match? endpoint
48
- @endpoint = @endpoint.sub %r{/$}, ""
53
+ def initialize credentials:,
54
+ endpoint: nil,
55
+ endpoint_template: nil,
56
+ universe_domain: nil,
57
+ numeric_enums: false,
58
+ raise_faraday_errors: true
59
+ setup_universe_domain universe_domain: universe_domain,
60
+ endpoint: endpoint,
61
+ endpoint_template: endpoint_template,
62
+ credentials: credentials
63
+
64
+ endpoint_url = self.endpoint
65
+ endpoint_url = "https://#{endpoint_url}" unless /^https?:/.match? endpoint_url
66
+ endpoint_url = endpoint_url.sub %r{/$}, ""
49
67
 
50
- @credentials = credentials
51
68
  @numeric_enums = numeric_enums
52
69
 
53
70
  @raise_faraday_errors = raise_faraday_errors
54
71
 
55
- @connection = Faraday.new url: @endpoint do |conn|
72
+ @connection = Faraday.new url: endpoint_url do |conn|
56
73
  conn.headers = { "Content-Type" => "application/json" }
57
- conn.request :google_authorization, @credentials unless @credentials.is_a? ::Symbol
74
+ conn.request :google_authorization, self.credentials unless self.credentials.is_a? ::Symbol
58
75
  conn.request :retry
59
76
  conn.response :raise_error
60
77
  conn.adapter :net_http
@@ -0,0 +1,84 @@
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
+ require "gapic/common/error"
16
+
17
+ module Gapic
18
+ ##
19
+ # A mixin module that provides methods for obtaining the effective universe
20
+ # domain, endpoint, and credentials for a stub. This is included in
21
+ # Grpc::ServiceStub and Rest::ClientStub.
22
+ #
23
+ module UniverseDomainConcerns
24
+ ##
25
+ # A substitution string for the universe domain in an endpoint template
26
+ # @return [String]
27
+ #
28
+ ENDPOINT_SUBSTITUTION = "$UNIVERSE_DOMAIN$".freeze
29
+
30
+ ##
31
+ # The effective endpoint
32
+ # @return [String]
33
+ #
34
+ attr_reader :endpoint
35
+
36
+ ##
37
+ # The effective universe domain
38
+ # @return [String]
39
+ #
40
+ attr_reader :universe_domain
41
+
42
+ ##
43
+ # The effective credentials
44
+ #
45
+ # @return [Google::Auth::Credentials, Signet::OAuth2::Client, Proc,
46
+ # ::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials]
47
+ #
48
+ attr_reader :credentials
49
+
50
+ protected
51
+
52
+ ##
53
+ # @private
54
+ # Called from the stub constructor to populate the data.
55
+ #
56
+ def setup_universe_domain universe_domain: nil,
57
+ endpoint: nil,
58
+ endpoint_template: nil,
59
+ credentials: nil
60
+ raise ArgumentError, "endpoint or endpoint_template is required" if endpoint.nil? && endpoint_template.nil?
61
+ raise ArgumentError, "credentials is required" if credentials.nil?
62
+
63
+ # TODO: The env logic should live in google-cloud-env
64
+ universe_domain ||= ENV["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] || "googleapis.com"
65
+ endpoint ||= endpoint_template.sub ENDPOINT_SUBSTITUTION, universe_domain
66
+
67
+ if credentials.respond_to?(:universe_domain) && credentials.universe_domain != universe_domain
68
+ raise UniverseDomainMismatch,
69
+ "Universe domain is #{universe_domain} but credentials are in #{credentials.universe_domain}"
70
+ end
71
+
72
+ @universe_domain = universe_domain
73
+ @endpoint = endpoint
74
+ @credentials = credentials
75
+ end
76
+ end
77
+
78
+ ##
79
+ # Raised when the configured universe domain does not match the universe
80
+ # domain of the credentials.
81
+ #
82
+ class UniverseDomainMismatch < ::Gapic::Common::Error
83
+ end
84
+ end
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.20.0
4
+ version: 0.21.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: 2023-09-05 00:00:00.000000000 Z
11
+ date: 2023-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.3.12
59
+ version: 1.4.0
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: 2.a
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 1.3.12
69
+ version: 1.4.0
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: 2.a
@@ -76,7 +76,7 @@ dependencies:
76
76
  requirements:
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 1.3.1
79
+ version: 1.11.0
80
80
  - - "<"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.a
@@ -86,7 +86,7 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 1.3.1
89
+ version: 1.11.0
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: 2.a
@@ -96,196 +96,42 @@ dependencies:
96
96
  requirements:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: '1.0'
99
+ version: '1.9'
100
100
  type: :runtime
101
101
  prerelease: false
102
102
  version_requirements: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - "~>"
105
105
  - !ruby/object:Gem::Version
106
- version: '1.0'
106
+ version: '1.9'
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: google-protobuf
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: '3.14'
113
+ version: '3.18'
114
114
  type: :runtime
115
115
  prerelease: false
116
116
  version_requirements: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - "~>"
119
119
  - !ruby/object:Gem::Version
120
- version: '3.14'
120
+ version: '3.18'
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: grpc
123
123
  requirement: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - "~>"
126
126
  - !ruby/object:Gem::Version
127
- version: '1.36'
127
+ version: '1.59'
128
128
  type: :runtime
129
129
  prerelease: false
130
130
  version_requirements: !ruby/object:Gem::Requirement
131
131
  requirements:
132
132
  - - "~>"
133
133
  - !ruby/object:Gem::Version
134
- version: '1.36'
135
- - !ruby/object:Gem::Dependency
136
- name: concurrent-ruby
137
- requirement: !ruby/object:Gem::Requirement
138
- requirements:
139
- - - "~>"
140
- - !ruby/object:Gem::Version
141
- version: 1.2.2
142
- type: :development
143
- prerelease: false
144
- version_requirements: !ruby/object:Gem::Requirement
145
- requirements:
146
- - - "~>"
147
- - !ruby/object:Gem::Version
148
- version: 1.2.2
149
- - !ruby/object:Gem::Dependency
150
- name: google-cloud-core
151
- requirement: !ruby/object:Gem::Requirement
152
- requirements:
153
- - - "~>"
154
- - !ruby/object:Gem::Version
155
- version: '1.5'
156
- type: :development
157
- prerelease: false
158
- version_requirements: !ruby/object:Gem::Requirement
159
- requirements:
160
- - - "~>"
161
- - !ruby/object:Gem::Version
162
- version: '1.5'
163
- - !ruby/object:Gem::Dependency
164
- name: google-style
165
- requirement: !ruby/object:Gem::Requirement
166
- requirements:
167
- - - "~>"
168
- - !ruby/object:Gem::Version
169
- version: 1.26.0
170
- type: :development
171
- prerelease: false
172
- version_requirements: !ruby/object:Gem::Requirement
173
- requirements:
174
- - - "~>"
175
- - !ruby/object:Gem::Version
176
- version: 1.26.0
177
- - !ruby/object:Gem::Dependency
178
- name: minitest
179
- requirement: !ruby/object:Gem::Requirement
180
- requirements:
181
- - - "~>"
182
- - !ruby/object:Gem::Version
183
- version: '5.16'
184
- type: :development
185
- prerelease: false
186
- version_requirements: !ruby/object:Gem::Requirement
187
- requirements:
188
- - - "~>"
189
- - !ruby/object:Gem::Version
190
- version: '5.16'
191
- - !ruby/object:Gem::Dependency
192
- name: minitest-autotest
193
- requirement: !ruby/object:Gem::Requirement
194
- requirements:
195
- - - "~>"
196
- - !ruby/object:Gem::Version
197
- version: '1.0'
198
- type: :development
199
- prerelease: false
200
- version_requirements: !ruby/object:Gem::Requirement
201
- requirements:
202
- - - "~>"
203
- - !ruby/object:Gem::Version
204
- version: '1.0'
205
- - !ruby/object:Gem::Dependency
206
- name: minitest-focus
207
- requirement: !ruby/object:Gem::Requirement
208
- requirements:
209
- - - "~>"
210
- - !ruby/object:Gem::Version
211
- version: '1.1'
212
- type: :development
213
- prerelease: false
214
- version_requirements: !ruby/object:Gem::Requirement
215
- requirements:
216
- - - "~>"
217
- - !ruby/object:Gem::Version
218
- version: '1.1'
219
- - !ruby/object:Gem::Dependency
220
- name: minitest-rg
221
- requirement: !ruby/object:Gem::Requirement
222
- requirements:
223
- - - "~>"
224
- - !ruby/object:Gem::Version
225
- version: '5.2'
226
- type: :development
227
- prerelease: false
228
- version_requirements: !ruby/object:Gem::Requirement
229
- requirements:
230
- - - "~>"
231
- - !ruby/object:Gem::Version
232
- version: '5.2'
233
- - !ruby/object:Gem::Dependency
234
- name: pry
235
- requirement: !ruby/object:Gem::Requirement
236
- requirements:
237
- - - ">="
238
- - !ruby/object:Gem::Version
239
- version: '0.14'
240
- type: :development
241
- prerelease: false
242
- version_requirements: !ruby/object:Gem::Requirement
243
- requirements:
244
- - - ">="
245
- - !ruby/object:Gem::Version
246
- version: '0.14'
247
- - !ruby/object:Gem::Dependency
248
- name: rake
249
- requirement: !ruby/object:Gem::Requirement
250
- requirements:
251
- - - ">="
252
- - !ruby/object:Gem::Version
253
- version: '12.0'
254
- type: :development
255
- prerelease: false
256
- version_requirements: !ruby/object:Gem::Requirement
257
- requirements:
258
- - - ">="
259
- - !ruby/object:Gem::Version
260
- version: '12.0'
261
- - !ruby/object:Gem::Dependency
262
- name: redcarpet
263
- requirement: !ruby/object:Gem::Requirement
264
- requirements:
265
- - - "~>"
266
- - !ruby/object:Gem::Version
267
- version: '3.0'
268
- type: :development
269
- prerelease: false
270
- version_requirements: !ruby/object:Gem::Requirement
271
- requirements:
272
- - - "~>"
273
- - !ruby/object:Gem::Version
274
- version: '3.0'
275
- - !ruby/object:Gem::Dependency
276
- name: yard
277
- requirement: !ruby/object:Gem::Requirement
278
- requirements:
279
- - - "~>"
280
- - !ruby/object:Gem::Version
281
- version: '0.9'
282
- type: :development
283
- prerelease: false
284
- version_requirements: !ruby/object:Gem::Requirement
285
- requirements:
286
- - - "~>"
287
- - !ruby/object:Gem::Version
288
- version: '0.9'
134
+ version: '1.59'
289
135
  description:
290
136
  email:
291
137
  - googleapis-packages@google.com
@@ -336,6 +182,7 @@ files:
336
182
  - lib/gapic/rest/threaded_enumerator.rb
337
183
  - lib/gapic/rest/transport_operation.rb
338
184
  - lib/gapic/stream_input.rb
185
+ - lib/gapic/universe_domain_concerns.rb
339
186
  homepage: https://github.com/googleapis/gapic-generator-ruby
340
187
  licenses:
341
188
  - Apache-2.0
@@ -348,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
348
195
  requirements:
349
196
  - - ">="
350
197
  - !ruby/object:Gem::Version
351
- version: '2.6'
198
+ version: '2.7'
352
199
  required_rubygems_version: !ruby/object:Gem::Requirement
353
200
  requirements:
354
201
  - - ">="