gapic-generator 0.6.3 → 0.6.8

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: 745e30ea242120669b722820eaa82bfe276d83ae511865f7f9ba50ae8eac0fa3
4
- data.tar.gz: 0dcdb8ac89fdaa5e568a09b5e0606e546211280844aba34c49c08662cc609dfc
3
+ metadata.gz: 7cb3044a15ef0354c0aa76903f7bf51e1218b96b0ba7b5923c1b996119dcc5c5
4
+ data.tar.gz: 4a6b8fa141b8474ed05188f097febfe550901d00b832b153b9fcd3710f01c7a1
5
5
  SHA512:
6
- metadata.gz: 7e5d18b93ad455ac93e48f0650184c2d6e482f3c8cdd5abb8b4e3c1a3b08832d074b5424d9eafd0aa984669d8f5dae7b2375aece2897f7e253fbe35aa9909981
7
- data.tar.gz: 495752c28967d05bc8f133b8248ab96cab896ae3406cd2ad60602c530b7f3a15ef149b8a079b76bbb876a2abf6f75c133cf396136bd09bf5bc8526efe7fc73b6
6
+ metadata.gz: d8680d28265909b97ca6071a0a28165368d68f861ec4d13615abdf9931b063dfa336e5e8c382a12be24daa4f34b247e1b3da3c28a8550ff27366493ae4a9d113
7
+ data.tar.gz: 95057a02f066f096c326020e4fbd83bf9ca24f279722812072eefd34df8e2184fe6b72c8d785c37596f0a626279d73fea810fd5c793e96b49c8cbfeb0148ac2e
@@ -1,5 +1,29 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.6.8 / 2020-09-16
4
+
5
+ * Add samples tasks to generated gapic rakefiles.
6
+ * Disable Style/AsciiComments rule.
7
+
8
+ ### 0.6.7 / 2020-08-07
9
+
10
+ * Generated credentials config allows symbols.
11
+
12
+ ### 0.6.6 / 2020-08-05
13
+
14
+ * Use numeric error codes rather than strings in generated retry configs.
15
+
16
+ ### 0.6.5 / 2020-07-16
17
+
18
+ * Examples in auth, rakefile, and readme should pick a non-common service.
19
+ * Emit a warning if common_services config references a nonexistent service.
20
+
21
+ ### 0.6.4 / 2020-07-13
22
+
23
+ * Fix rubocop warning on a generated multi-path helper if it could take no arguments.
24
+ * Run the rubocop file formatting step without caching.
25
+ * Fix an issue where generating a service with no options would fail.
26
+
3
27
  ### 0.6.3 / 2020-06-27
4
28
 
5
29
  * Fixes for generated tests for some cases involving proto maps.
@@ -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
 
@@ -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.3"
19
+ VERSION = "0.6.8"
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
 
@@ -25,6 +25,8 @@ Metrics/PerceivedComplexity:
25
25
  Naming/FileName:
26
26
  Exclude:
27
27
  - "lib/<%= gem.name %>.rb"
28
+ Style/AsciiComments:
29
+ Enabled: false
28
30
  Style/CaseEquality:
29
31
  Enabled: false
30
32
  Style/IfUnlessModifier:
@@ -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 -%>
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.3
4
+ version: 0.6.8
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-27 00:00:00.000000000 Z
13
+ date: 2020-09-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -60,14 +60,14 @@ dependencies:
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 1.30.0.pre1
63
+ version: 1.30.1
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: 1.30.0.pre1
70
+ version: 1.30.1
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: minitest
73
73
  requirement: !ruby/object:Gem::Requirement