gapic-generator 0.6.2 → 0.6.7

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: 78e591a0a5e9a24086ccfcf3227d7fe20dd2c0732f6ff7e4230b81ee48d0bcb6
4
- data.tar.gz: 48b3b285796cd0bc3452ebf15797a8a1c54941aa79e4781588abc7f90b3aee8a
3
+ metadata.gz: 5aa9d03bd1f1b684465822ee5d675fd68d59bc540fff223872296f654c070003
4
+ data.tar.gz: 776dc70b99781fb0bb302fd17dd4cf346635a0a6893c486e345806d89356e4a6
5
5
  SHA512:
6
- metadata.gz: 2095d8bd87701b4b229a4f7c3c4ec2623a76b9c11c076068c5653d084881c68c44f23e96c9310f329bd2f64d3a91dd929a10656a1b19677e125d6555e70105cf
7
- data.tar.gz: faeb9756320e9863dcede6634bd03c6024798871e3c8ebf083c65eb3bc917933806365d292303b436088b3371c43e86c5992e2cd1fdfed7465cd3f22e7562468
6
+ metadata.gz: deb619583674bdbf4b93ec0c01d2372032cc009d94e264a208590357bba2952c69d6bb15ab82bddd40a90c6e64b19d312515d1b221731771c9656b61954fd00d
7
+ data.tar.gz: 67e2be16533a5ed217c81a9b0d20f85d438792edcc0ff8bccbc9626b21e794e8b130957a4fd1bea4823efb8d4de9c4a10ccab4fae40fdd2122402f6b3989988b
@@ -1,5 +1,30 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.6.7 / 2020-08-07
4
+
5
+ * Generated credentials config allows symbols.
6
+
7
+ ### 0.6.6 / 2020-08-05
8
+
9
+ * Use numeric error codes rather than strings in generated retry configs.
10
+
11
+ ### 0.6.5 / 2020-07-16
12
+
13
+ * Examples in auth, rakefile, and readme should pick a non-common service.
14
+ * Emit a warning if common_services config references a nonexistent service.
15
+
16
+ ### 0.6.4 / 2020-07-13
17
+
18
+ * Fix rubocop warning on a generated multi-path helper if it could take no arguments.
19
+ * Run the rubocop file formatting step without caching.
20
+ * Fix an issue where generating a service with no options would fail.
21
+
22
+ ### 0.6.3 / 2020-06-27
23
+
24
+ * Fixes for generated tests for some cases involving proto maps.
25
+ * Fix a Ruby 2.7 keyword arguments warning in generated tests.
26
+ * Clean up bundler references in gemspecs and Gemfiles.
27
+
3
28
  ### 0.6.2 / 2020-06-18
4
29
 
5
30
  * Support for the proto3_optional
@@ -30,7 +30,7 @@ COPY --from=gcr.io/gapic-images/api-common-protos:beta /protos/ /workspace/commo
30
30
  COPY --from=builder /workspace/*.gem /workspace/
31
31
 
32
32
  # Install the subgenerator and other needed tools.
33
- RUN gem install --pre grpc-tools gapic-generator-<%= gem_name %>.gem \
33
+ RUN gem install grpc-tools gapic-generator-<%= gem_name %>.gem \
34
34
  && rm gapic-generator-<%= gem_name %>.gem \
35
35
  && mkdir -p --mode=777 /.cache
36
36
 
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "protobuf", "~> 3.8"
30
30
  spec.add_dependency "rubocop", "~> 0.61"
31
31
 
32
- spec.add_development_dependency "bundler", "~> 2.1"
33
32
  spec.add_development_dependency "minitest", "~> 5.0"
34
33
  spec.add_development_dependency "minitest-focus", "~> 1.0"
35
34
  spec.add_development_dependency "rake", "~> 10.0"
@@ -39,7 +39,7 @@ module Gapic
39
39
  write_file dir, file
40
40
  end
41
41
 
42
- system "rubocop -x #{dir} -o #{dir}/rubocop.out -c #{configuration}"
42
+ system "rubocop --cache false -x #{dir} -o #{dir}/rubocop.out -c #{configuration}"
43
43
 
44
44
  files.each do |file|
45
45
  read_file dir, file
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Gapic
18
18
  module Generator
19
- VERSION = "0.6.2"
19
+ VERSION = "0.6.7"
20
20
  end
21
21
  end
@@ -40,6 +40,31 @@ module Gapic
40
40
  MULTIPLIER_JSON_KEY = "backoffMultiplier"
41
41
  STATUS_CODES_JSON_KEY = "retryableStatusCodes"
42
42
 
43
+ # See https://grpc.github.io/grpc/core/md_doc_statuscodes.html for a
44
+ # list of error codes.
45
+ ERROR_CODE_MAPPING = [
46
+ "OK",
47
+ "CANCELLED",
48
+ "UNKNOWN",
49
+ "INVALID_ARGUMENT",
50
+ "DEADLINE_EXCEEDED",
51
+ "NOT_FOUND",
52
+ "ALREADY_EXISTS",
53
+ "PERMISSION_DENIED",
54
+ "RESOURCE_EXHAUSTED",
55
+ "FAILED_PRECONDITION",
56
+ "ABORTED",
57
+ "OUT_OF_RANGE",
58
+ "UNIMPLEMENTED",
59
+ "INTERNAL",
60
+ "UNAVAILABLE",
61
+ "DATA_LOSS",
62
+ "UNAUTHENTICATED"
63
+ ].freeze
64
+
65
+ ERROR_STRING_MAPPING = ERROR_CODE_MAPPING.each_with_index.each_with_object({}) do |(str, num), hash|
66
+ hash[str] = num
67
+ end.freeze
43
68
 
44
69
  ##
45
70
  # Parses ServiceConfig from a json of a GRPC service config
@@ -146,11 +171,26 @@ module Gapic
146
171
  initial_delay_seconds = parse_interval_seconds get(retry_policy_json, INITIAL_DELAY_JSON_KEY)
147
172
  max_delay_seconds = parse_interval_seconds get(retry_policy_json, MAX_DELAY_JSON_KEY)
148
173
  multiplier = get retry_policy_json, MULTIPLIER_JSON_KEY
149
- status_codes = get retry_policy_json, STATUS_CODES_JSON_KEY
174
+ status_codes = convert_codes get retry_policy_json, STATUS_CODES_JSON_KEY
150
175
 
151
176
  RetryPolicy.new initial_delay_seconds, max_delay_seconds, multiplier, status_codes
152
177
  end
153
178
 
179
+ ##
180
+ # Interpret input status codes. Convert strings to their associated integer codes.
181
+ #
182
+ def self.convert_codes input_codes
183
+ return nil if input_codes.nil?
184
+ Array(input_codes).map do |obj|
185
+ case obj
186
+ when String
187
+ ERROR_STRING_MAPPING[obj]
188
+ when Integer
189
+ obj
190
+ end
191
+ end.compact
192
+ end
193
+
154
194
  ##
155
195
  # Parses time expressed in secondds from the GRPC service config json
156
196
  # The time is encoded is a string as float or integer with a letter 's' afterwards
@@ -212,7 +252,7 @@ module Gapic
212
252
  end
213
253
 
214
254
  private_class_method :parse_service_names, :filter_service_method_names, :parse_config,
215
- :parse_retry_policy, :parse_interval_seconds, :valid_float?
255
+ :parse_retry_policy, :parse_interval_seconds, :valid_float?, :convert_codes
216
256
  end
217
257
  end
218
258
  end
@@ -48,6 +48,10 @@ module Gapic
48
48
  end
49
49
  end
50
50
 
51
+ def first_non_common_service
52
+ services.find { |service| service.common_service_delegate.nil? }
53
+ end
54
+
51
55
  def proto_files
52
56
  @proto_files ||= begin
53
57
  files = @api.files
@@ -203,7 +203,8 @@ module Gapic
203
203
  def client_scopes
204
204
  common_service_delegate&.client_scopes ||
205
205
  @service.scopes ||
206
- default_config(:oauth_scopes)
206
+ default_config(:oauth_scopes) ||
207
+ []
207
208
  end
208
209
 
209
210
  def credentials_name
@@ -44,14 +44,18 @@ module Gapic
44
44
  #
45
45
  # @param request [Google::Protobuf::Compiler::CodeGeneratorRequest]
46
46
  # The request object.
47
- def initialize request
47
+ # @param error_output [IO] An IO to write any errors/warnings to.
48
+ # @param configuration [Hash] Optional override of configuration.
49
+ def initialize request, error_output: STDERR, configuration: nil
48
50
  @request = request
49
51
  loader = Loader.new
50
52
  @files = request.proto_file.map do |fd|
51
53
  loader.load_file fd, request.file_to_generate.include?(fd.name)
52
54
  end
53
55
  @files.each { |f| f.parent = self }
56
+ @configuration = configuration
54
57
  @resource_types = analyze_resources
58
+ sanity_checks error_output
55
59
  end
56
60
 
57
61
  def containing_api
@@ -295,6 +299,18 @@ module Gapic
295
299
 
296
300
  private
297
301
 
302
+ # Perform a variety of sanity checks on the data, and prints errors to
303
+ # the given output as appropriate.
304
+ #
305
+ # @param output [IO] Stream to write outputs to.
306
+ def sanity_checks output
307
+ addrs = services.map { |service| service.address.join "." }
308
+ configuration[:common_services]&.each do |k, v|
309
+ output.puts "WARNING: configured common service #{k} is not present" unless addrs.include? k
310
+ output.puts "WARNING: configured common service delegate #{v} is not present" unless addrs.include? v
311
+ end
312
+ end
313
+
298
314
  # Does a pre-analysis of all resources defined in the job. This has
299
315
  # two effects:
300
316
  # * Side effect: each resource has its parent_resources field set.
@@ -16,7 +16,7 @@ $ gem install <%= gem.name %>
16
16
 
17
17
  ```ruby
18
18
  require "<%= gem.entrypoint_require %>"
19
- <%- service = gem.packages.first&.services.first -%>
19
+ <%- service = gem.first_non_common_service -%>
20
20
  <%- method = service&.methods.first -%>
21
21
  <%- if service && method -%>
22
22
 
@@ -87,7 +87,7 @@ class Configuration
87
87
 
88
88
  config_attr :endpoint, <%= service.client_endpoint.inspect %>, ::String
89
89
  config_attr :credentials, nil do |value|
90
- allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
90
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
91
91
  allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
92
92
  allowed.any? { |klass| klass === value }
93
93
  end
@@ -13,7 +13,11 @@ def <%= resource.path_helper %> **args
13
13
  <%- last_pattern_index = resource.patterns.count - 1 -%>
14
14
  <%- resource.patterns.each_with_index do |pattern, index| -%>
15
15
  <%- comma = last_pattern_index == index ? "" : "," -%>
16
+ <%- if pattern.formal_arguments.empty? -%>
17
+ <%= pattern.arguments_key.inspect %> => (proc do
18
+ <%- else -%>
16
19
  <%= pattern.arguments_key.inspect %> => (proc do |<%= pattern.formal_arguments %>|
20
+ <%- end -%>
17
21
  <%= indent render(partial: "service/client/resource/def", locals: { pattern: pattern }), 6 %>
18
22
  end)<%= comma %>
19
23
  <%- end -%>
@@ -86,8 +86,10 @@ def test_<%= method.name %>
86
86
  request.to_a.each do |r|
87
87
  assert_kind_of <%= method.request_type %>, r
88
88
  <%- fields.each do |field| -%>
89
- <%- if field.message? && field.repeated? -%>
90
- assert_kind_of <%= field.type_name_full %>, request.<%= field.name %>.first
89
+ <%- if field.message? && field.repeated? && !field.map? -%>
90
+ assert_kind_of <%= field.type_name_full %>, r.<%= field.name %>.first
91
+ <%- elsif field.map? -%>
92
+ assert_equal(<%= field.default_value %>, r.<%= field.name %>.to_h)
91
93
  <%- elsif field.message? -%>
92
94
  assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), r.<%= field.name %>
93
95
  <%- else -%>
@@ -70,8 +70,10 @@ def test_<%= method.name %>
70
70
  request.to_a.each do |r|
71
71
  assert_kind_of <%= method.request_type %>, r
72
72
  <%- fields.each do |field| -%>
73
- <%- if field.message? && field.repeated? -%>
74
- assert_kind_of <%= field.type_name_full %>, request.<%= field.name %>.first
73
+ <%- if field.message? && field.repeated? && !field.map? -%>
74
+ assert_kind_of <%= field.type_name_full %>, r.<%= field.name %>.first
75
+ <%- elsif field.map? -%>
76
+ assert_equal(<%= field.default_value %>, r.<%= field.name %>.to_h)
75
77
  <%- elsif field.message? -%>
76
78
  assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), r.<%= field.name %>
77
79
  <%- else -%>
@@ -17,8 +17,10 @@ def test_<%= method.name %>
17
17
  assert_equal :<%= method.name %>, name
18
18
  assert_kind_of <%= method.request_type %>, request
19
19
  <%- fields.each do |field| -%>
20
- <%- if field.message? && field.repeated? -%>
20
+ <%- if field.message? && field.repeated? && !field.map? -%>
21
21
  assert_kind_of <%= field.type_name_full %>, request.<%= field.name %>.first
22
+ <%- elsif field.map? -%>
23
+ assert_equal(<%= field.default_value %>, request.<%= field.name %>.to_h)
22
24
  <%- elsif field.message? -%>
23
25
  assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), request.<%= field.name %>
24
26
  <%- else -%>
@@ -9,10 +9,10 @@ class ClientStub
9
9
  @requests = []
10
10
  end
11
11
 
12
- def call_rpc *args
12
+ def call_rpc *args, **kwargs
13
13
  @call_rpc_count += 1
14
14
 
15
- @requests << @block&.call(*args)
15
+ @requests << @block&.call(*args, **kwargs)
16
16
 
17
17
  yield @response, @operation if block_given?
18
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gapic-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernest Landrito
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-06-19 00:00:00.000000000 Z
13
+ date: 2020-08-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -40,20 +40,6 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '3.8'
43
- - !ruby/object:Gem::Dependency
44
- name: bundler
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '2.1'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '2.1'
57
43
  - !ruby/object:Gem::Dependency
58
44
  name: google-style
59
45
  requirement: !ruby/object:Gem::Requirement
@@ -74,14 +60,14 @@ dependencies:
74
60
  requirements:
75
61
  - - "~>"
76
62
  - !ruby/object:Gem::Version
77
- version: 1.30.0.pre1
63
+ version: 1.30.1
78
64
  type: :development
79
65
  prerelease: false
80
66
  version_requirements: !ruby/object:Gem::Requirement
81
67
  requirements:
82
68
  - - "~>"
83
69
  - !ruby/object:Gem::Version
84
- version: 1.30.0.pre1
70
+ version: 1.30.1
85
71
  - !ruby/object:Gem::Dependency
86
72
  name: minitest
87
73
  requirement: !ruby/object:Gem::Requirement