gapic-common 0.20.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd54dc9471821e191b81b38efd0e03c24cfaaad13093b7b20d174a7235db9408
4
- data.tar.gz: dda7b540eedb2fb8f665548a6844b6c98c6b5e0b601d4627be16d229cdc1b65f
3
+ metadata.gz: ac5c845df865497acbdcb4656a47667dd657083d85ef964f633fc0540ef80493
4
+ data.tar.gz: 851ab12cf7a9e8d5e5f93c991846f0a4701a5a96047fef0ebb17392a55061984
5
5
  SHA512:
6
- metadata.gz: cedbf49ae436a114a347723bda04637fee02481d7a56624f80f79ab1e2903ccc290a7667e1584d11c66bc0b60295333315f99ac15d01806c1713171ed3179dde
7
- data.tar.gz: a4f733db0e1bb0e158d982fe189dc510195e24299fa8880255917ae7a68b2a2d47ff740bf304fd187678c2ace7c9a75cdabf341347e0f0066fe16e40e7e8d0be
6
+ metadata.gz: 3225a82b3d2b7006fa0191c55e46e836724ec07d240d7fc5eb11188ccc5613572a714a012a5e904d85cc70d13bb816cd735faf0c3b458e54552e36f483f07f21
7
+ data.tar.gz: 7d4e26754019a71ae7bca52e2e195b71db46c755c6eca1cce34504990e31f2055d390119d9ae0bf81d1b217f7f1d3185200557da3c4d04b8aa251a3d87a13b54
data/CHANGELOG.md CHANGED
@@ -1,5 +1,82 @@
1
1
  # Release History
2
2
 
3
+ ### 1.2.0 (2025-09-04)
4
+
5
+ #### Features
6
+
7
+ * update google-protobuf dependency ([#41](https://github.com/googleapis/ruby-core-libraries/issues/41))
8
+
9
+ ### 1.1.0 (2025-08-11)
10
+
11
+ #### Features
12
+
13
+ * add http binding configuration ([#38](https://github.com/googleapis/ruby-core-libraries/issues/38))
14
+
15
+ ### 1.0.1 (2025-07-17)
16
+
17
+ #### Bug Fixes
18
+
19
+ * Removed log preprocessing of large payload data when logging is disabled ([#35](https://github.com/googleapis/ruby-core-libraries/issues/35))
20
+
21
+ ### 1.0.0 (2025-04-30)
22
+
23
+ #### Features
24
+
25
+ * Bump version to 1.0 ([#33](https://github.com/googleapis/ruby-core-libraries/issues/33))
26
+
27
+ ### 0.26.0 (2025-04-30)
28
+
29
+ #### Features
30
+
31
+ * Updated required Ruby version to 3.1 ([#29](https://github.com/googleapis/ruby-core-libraries/issues/29))
32
+
33
+ ### 0.25.0 (2025-01-22)
34
+
35
+ #### Features
36
+
37
+ * Implement a polling harness ([#20](https://github.com/googleapis/ruby-core-libraries/issues/20))
38
+
39
+ ### 0.24.0 (2024-12-05)
40
+
41
+ #### Features
42
+
43
+ * Log requests and responses ([#1112](https://github.com/googleapis/gapic-generator-ruby/issues/1112))
44
+ #### Bug Fixes
45
+
46
+ * Hardened deadline determination against Time.now hacking ([#942](https://github.com/googleapis/gapic-generator-ruby/issues/942))
47
+
48
+ ### 0.23.0 (2024-10-15)
49
+
50
+ #### Features
51
+
52
+ * Disable universe domain check if credentials include an explicit request to do so ([#1119](https://github.com/googleapis/gapic-generator-ruby/issues/1119))
53
+
54
+ ### 0.22.0 (2024-07-17)
55
+
56
+ #### Features
57
+
58
+ * Support for google-protobuf 4.x
59
+ * Requires at least Ruby 3.0
60
+
61
+ ### 0.21.2 (2024-07-02)
62
+
63
+ #### Bug Fixes
64
+
65
+ * Start requiring ostruct in generated test helper files ([#1065](https://github.com/googleapis/gapic-generator-ruby/issues/1065))
66
+
67
+ ### 0.21.1 (2023-12-14)
68
+
69
+ #### Bug Fixes
70
+
71
+ * add missing module import for universe_domain_concerns ([#1016](https://github.com/googleapis/gapic-generator-ruby/issues/1016))
72
+
73
+ ### 0.21.0 (2023-12-13)
74
+
75
+ #### Features
76
+
77
+ * Drop support for Ruby 2.6 ([#1009](https://github.com/googleapis/gapic-generator-ruby/issues/1009))
78
+ * Honor universe domain in stubs ([#1008](https://github.com/googleapis/gapic-generator-ruby/issues/1008))
79
+
3
80
  ### 0.20.0 (2023-08-31)
4
81
 
5
82
  #### Features
data/README.md CHANGED
@@ -15,14 +15,14 @@ convenient and idiomatic API surface to callers.
15
15
 
16
16
  ## Supported Ruby Versions
17
17
 
18
- This library is supported on Ruby 2.6+.
18
+ This library is supported on Ruby 3.0+.
19
19
 
20
20
  Google provides official support for Ruby versions that are actively supported
21
21
  by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
22
- security maintenance, and not end of life. Currently, this means Ruby 2.6 and
23
- later. Older versions of Ruby _may_ still work, but are unsupported and not
24
- recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
25
- about the Ruby support schedule.
22
+ security maintenance, and not end of life. Older versions of Ruby _may_ still
23
+ work, but are unsupported and not recommended. See
24
+ https://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby
25
+ support schedule.
26
26
 
27
27
  ## Contributing
28
28
 
@@ -12,63 +12,5 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
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
15
+ # File moved.
16
+ require "gapic/common/error_codes"
@@ -12,126 +12,27 @@
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"
15
+ require "gapic/common/retry_policy"
16
16
 
17
17
  module Gapic
18
18
  class CallOptions
19
19
  ##
20
- # The policy for retrying failed RPC calls using an incremental backoff. A new object instance should be used for
21
- # every RpcCall invocation.
20
+ # The policy for retrying failed RPC calls using an incremental backoff. A new object instance
21
+ # should be used for every RpcCall invocation.
22
22
  #
23
- # Only errors orginating from GRPC will be retried.
23
+ # Only errors originating from GRPC will be retried.
24
24
  #
25
- class RetryPolicy
25
+ class RetryPolicy < Gapic::Common::RetryPolicy
26
26
  ##
27
27
  # Create new API Call RetryPolicy.
28
28
  #
29
- # @param initial_delay [Numeric] client-side timeout
30
- # @param multiplier [Numeric] client-side timeout
31
- # @param max_delay [Numeric] client-side timeout
29
+ # @param retry_codes [Array<String|Numeric>] List of retry codes.
30
+ # @param initial_delay [Numeric] Initial delay in seconds.
31
+ # @param multiplier [Numeric] The delay scaling factor for each subsequent retry attempt.
32
+ # @param max_delay [Numeric] Maximum delay in seconds.
32
33
  #
33
34
  def initialize retry_codes: nil, initial_delay: nil, multiplier: nil, max_delay: nil
34
- @retry_codes = convert_codes retry_codes
35
- @initial_delay = initial_delay
36
- @multiplier = multiplier
37
- @max_delay = max_delay
38
- @delay = nil
39
- end
40
-
41
- def retry_codes
42
- @retry_codes || []
43
- end
44
-
45
- def initial_delay
46
- @initial_delay || 1
47
- end
48
-
49
- def multiplier
50
- @multiplier || 1.3
51
- end
52
-
53
- def max_delay
54
- @max_delay || 15
55
- end
56
-
57
- ##
58
- # The current delay value.
59
- def delay
60
- @delay || initial_delay
61
- end
62
-
63
- def call error
64
- return false unless retry? error
65
-
66
- delay!
67
- increment_delay!
68
-
69
- true
70
- end
71
-
72
- ##
73
- # @private
74
- # Apply default values to the policy object. This does not replace user-provided values, it only overrides empty
75
- # values.
76
- #
77
- # @param retry_policy [Hash] The policy for error retry. keys must match the arguments for
78
- # {RpcCall::RetryPolicy.new}.
79
- #
80
- def apply_defaults retry_policy
81
- return unless retry_policy.is_a? Hash
82
-
83
- @retry_codes ||= convert_codes retry_policy[:retry_codes]
84
- @initial_delay ||= retry_policy[:initial_delay]
85
- @multiplier ||= retry_policy[:multiplier]
86
- @max_delay ||= retry_policy[:max_delay]
87
-
88
- self
89
- end
90
-
91
- # @private Equality test
92
- def eql? other
93
- other.is_a?(RetryPolicy) &&
94
- other.retry_codes == retry_codes &&
95
- other.initial_delay == initial_delay &&
96
- other.multiplier == multiplier &&
97
- other.max_delay == max_delay
98
- end
99
- alias == eql?
100
-
101
- # @private Hash code
102
- def hash
103
- [retry_codes, initial_delay, multiplier, max_delay].hash
104
- end
105
-
106
- private
107
-
108
- def retry? error
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)))
112
- end
113
-
114
- def delay!
115
- # Call Kernel.sleep so we can stub it.
116
- Kernel.sleep delay
117
- end
118
-
119
- def convert_codes input_codes
120
- return nil if input_codes.nil?
121
- Array(input_codes).map do |obj|
122
- case obj
123
- when String
124
- ErrorCodes::ERROR_STRING_MAPPING[obj]
125
- when Integer
126
- obj
127
- end
128
- end.compact
129
- end
130
-
131
- ##
132
- # Calculate and set the next delay value.
133
- def increment_delay!
134
- @delay = [delay * multiplier, max_delay].min
35
+ super
135
36
  end
136
37
  end
137
38
  end
@@ -12,8 +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
  require "gapic/call_options/retry_policy"
16
+ require "gapic/common/error_codes"
17
17
 
18
18
  module Gapic
19
19
  ##
@@ -0,0 +1,74 @@
1
+ # Copyright 2025 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 Common
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
@@ -0,0 +1,82 @@
1
+ # Copyright 2025 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/retry_policy"
16
+
17
+ module Gapic
18
+ module Common
19
+ ##
20
+ # Provides a generic mechanism for periodic polling an operation.
21
+ #
22
+ # Polling intervals are calculated from the provided retry policy.
23
+ #
24
+ # Supports exponential backoff via `multiplier`, and automatically
25
+ # retries gRPC errors listed in `retry_codes`.
26
+ #
27
+ class PollingHarness
28
+ # @return [Gapic::Common::RetryPolicy] The retry policy associated with this instance.
29
+ attr_reader :retry_policy
30
+
31
+ ##
32
+ # Create new Gapic::Common::PollingHarness instance.
33
+ #
34
+ # @param retry_policy [Gapic::Common::RetryPolicy] The retry policy to
35
+ # use. If not provided, a new retry policy is constructed from the
36
+ # given kwargs.
37
+ # @param kwargs [keywords] Keyword arguments used to create a new retry
38
+ # policy. See {RetryPolicy#initialize}.
39
+ #
40
+ def initialize retry_policy: nil, **kwargs
41
+ @retry_policy = retry_policy ? retry_policy.dup : RetryPolicy.new(**kwargs)
42
+ end
43
+
44
+ ##
45
+ # Perform polling with exponential backoff. Repeatedly calls the given
46
+ # block until it returns a result other than the given sentinel value
47
+ # (normally `nil`), then returns that final result.
48
+ #
49
+ # Uses the retry policy regulate retries, including delays between tries,
50
+ # retriable errors, and final timeout. If an error code other than those
51
+ # listed in {RetryPolicy#retry_codes} is raised, it is propagated out. If
52
+ # the timeout expires, the given timeout result (normally `nil`) is
53
+ # returned.
54
+ #
55
+ # @param wait_sentinel [Object] The return value that should signal the
56
+ # polling harness to continue waiting. Any other value is treated as
57
+ # a real result and returned. Defaults to `nil`.
58
+ # @param timeout_result [Object] The result to return if timeout occurs.
59
+ # Defaults to `nil`.
60
+ #
61
+ # @yieldreturn [Object] The result of the polling logic, either a result
62
+ # to return, or the `wait_sentinel` value.
63
+ #
64
+ def wait wait_sentinel: nil, timeout_result: nil, mock_delay: false
65
+ unless block_given?
66
+ raise ArgumentError, "No callback provided to wait method."
67
+ end
68
+ retry_policy.start! mock_delay: mock_delay
69
+ loop do
70
+ begin
71
+ response = yield
72
+ return response unless response == wait_sentinel
73
+ rescue StandardError => e # Currently retry_error only accounts for ::GRPC::BadStatus.
74
+ raise unless retry_policy.retry_error? e
75
+ end
76
+ retry_policy.perform_delay!
77
+ return timeout_result unless retry_policy.retry_with_deadline?
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end