gapic-generator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/gapic/generator/version.rb +1 -1
- data/lib/gapic/grpc_service_config/parser.rb +43 -21
- data/templates/default/gem/gemspec.erb +1 -1
- data/templates/default/service/client/_self_configure.erb +1 -21
- data/templates/default/service/client/_self_configure_defaults.erb +22 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e29f5e9a5cd2e6c4cf68d8e28fe095b5a0f5155f7c892f0b9b5429914b5dfb
|
4
|
+
data.tar.gz: 5ea2ad00f9c340675f2bd4f1b16d02dbb5d2e2b7444b450d326993de263a1cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f975242f0242375263e065351763fb67594ba65fc571f882bb54ce1877a5e14ad1419ecaf75e5c58ea0c29c81f5e8becdef635f1013111b624acd3e06248e92
|
7
|
+
data.tar.gz: 10abc98e678f667815d6e325cb27d582d4cbe27f4037edc66cde40ae8eb76b0d7b6fc884258d8ec5473612d327059baffbea94f3e9edf1ba83ae29f2d988e655
|
data/CHANGELOG.md
CHANGED
@@ -26,8 +26,8 @@ module Gapic
|
|
26
26
|
# usable by the microgenerator templates
|
27
27
|
#
|
28
28
|
module Parser
|
29
|
-
METHOD_CONFIG_JSON_KEY = "
|
30
|
-
RETRY_POLICY_JSON_KEY = "
|
29
|
+
METHOD_CONFIG_JSON_KEY = "methodConfig"
|
30
|
+
RETRY_POLICY_JSON_KEY = "retryPolicy"
|
31
31
|
|
32
32
|
NAMES_JSON_KEY = "name"
|
33
33
|
SERVICE_NAME_JSON_KEY = "service"
|
@@ -35,10 +35,10 @@ module Gapic
|
|
35
35
|
|
36
36
|
TIMEOUT_JSON_KEY = "timeout"
|
37
37
|
|
38
|
-
INITIAL_DELAY_JSON_KEY = "
|
39
|
-
MAX_DELAY_JSON_KEY = "
|
40
|
-
MULTIPLIER_JSON_KEY = "
|
41
|
-
STATUS_CODES_JSON_KEY = "
|
38
|
+
INITIAL_DELAY_JSON_KEY = "initialBackoff"
|
39
|
+
MAX_DELAY_JSON_KEY = "maxBackoff"
|
40
|
+
MULTIPLIER_JSON_KEY = "backoffMultiplier"
|
41
|
+
STATUS_CODES_JSON_KEY = "retryableStatusCodes"
|
42
42
|
|
43
43
|
|
44
44
|
##
|
@@ -52,21 +52,21 @@ module Gapic
|
|
52
52
|
service_level_result = {}
|
53
53
|
service_method_level_result = {}
|
54
54
|
|
55
|
-
if !service_config_json.nil? &&
|
56
|
-
method_configs_json = service_config_json
|
55
|
+
if !service_config_json.nil? && key?(service_config_json, METHOD_CONFIG_JSON_KEY)
|
56
|
+
method_configs_json = get service_config_json, METHOD_CONFIG_JSON_KEY
|
57
57
|
|
58
58
|
method_configs_json.each do |method_config_json|
|
59
59
|
method_config = parse_config method_config_json
|
60
|
-
service_names = parse_service_names method_config_json
|
61
|
-
service_method_names = filter_service_method_names method_config_json
|
60
|
+
service_names = parse_service_names get(method_config_json, NAMES_JSON_KEY)
|
61
|
+
service_method_names = filter_service_method_names get(method_config_json, NAMES_JSON_KEY)
|
62
62
|
|
63
63
|
service_names.each do |service_name|
|
64
64
|
service_level_result[service_name] = method_config
|
65
65
|
end
|
66
66
|
|
67
67
|
service_method_names.each do |service_method_name|
|
68
|
-
service_name = service_method_name
|
69
|
-
method_name = service_method_name
|
68
|
+
service_name = get service_method_name, SERVICE_NAME_JSON_KEY
|
69
|
+
method_name = get service_method_name, METHOD_NAME_JSON_KEY
|
70
70
|
|
71
71
|
service_method_level_result[service_name] ||= {}
|
72
72
|
service_method_level_result[service_name][method_name] = method_config
|
@@ -92,10 +92,10 @@ module Gapic
|
|
92
92
|
#
|
93
93
|
def self.parse_service_names method_config_json_names
|
94
94
|
service_names_jsons = method_config_json_names.select do |names_json|
|
95
|
-
names_json.size == 1 &&
|
95
|
+
names_json.size == 1 && key?(names_json, SERVICE_NAME_JSON_KEY)
|
96
96
|
end
|
97
97
|
|
98
|
-
service_names_jsons.map { |names_json| names_json
|
98
|
+
service_names_jsons.map { |names_json| get names_json, SERVICE_NAME_JSON_KEY }
|
99
99
|
end
|
100
100
|
|
101
101
|
##
|
@@ -113,7 +113,7 @@ module Gapic
|
|
113
113
|
#
|
114
114
|
def self.filter_service_method_names method_config_json_names
|
115
115
|
method_config_json_names.select do |names_json|
|
116
|
-
names_json.size == 2 &&
|
116
|
+
names_json.size == 2 && key?(names_json, SERVICE_NAME_JSON_KEY) && key?(names_json, METHOD_NAME_JSON_KEY)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -126,8 +126,8 @@ module Gapic
|
|
126
126
|
# @return [Gapic::GrpcServiceConfig::MethodConfig] parsed MethodConfig
|
127
127
|
#
|
128
128
|
def self.parse_config method_config_json
|
129
|
-
timeout_seconds = parse_interval_seconds method_config_json
|
130
|
-
retry_policy = parse_retry_policy method_config_json
|
129
|
+
timeout_seconds = parse_interval_seconds get(method_config_json, TIMEOUT_JSON_KEY)
|
130
|
+
retry_policy = parse_retry_policy get(method_config_json, RETRY_POLICY_JSON_KEY)
|
131
131
|
|
132
132
|
MethodConfig.new timeout_seconds, retry_policy
|
133
133
|
end
|
@@ -143,10 +143,10 @@ module Gapic
|
|
143
143
|
def self.parse_retry_policy retry_policy_json
|
144
144
|
return nil if retry_policy_json.nil? || retry_policy_json.empty?
|
145
145
|
|
146
|
-
initial_delay_seconds = parse_interval_seconds retry_policy_json
|
147
|
-
max_delay_seconds = parse_interval_seconds retry_policy_json
|
148
|
-
multiplier = retry_policy_json
|
149
|
-
status_codes = retry_policy_json
|
146
|
+
initial_delay_seconds = parse_interval_seconds get(retry_policy_json, INITIAL_DELAY_JSON_KEY)
|
147
|
+
max_delay_seconds = parse_interval_seconds get(retry_policy_json, MAX_DELAY_JSON_KEY)
|
148
|
+
multiplier = get retry_policy_json, MULTIPLIER_JSON_KEY
|
149
|
+
status_codes = get retry_policy_json, STATUS_CODES_JSON_KEY
|
150
150
|
|
151
151
|
RetryPolicy.new initial_delay_seconds, max_delay_seconds, multiplier, status_codes
|
152
152
|
end
|
@@ -175,6 +175,28 @@ module Gapic
|
|
175
175
|
Float(timestring_nos)
|
176
176
|
end
|
177
177
|
|
178
|
+
##
|
179
|
+
# Determines if the key or its underscore form exists
|
180
|
+
#
|
181
|
+
# @param hash [Hash] hash structure
|
182
|
+
# @param key [String] lowerCamelCase string
|
183
|
+
# @return [Boolean]
|
184
|
+
#
|
185
|
+
def self.key? hash, key
|
186
|
+
hash.key?(key) || hash.key?(ActiveSupport::Inflector.underscore(key))
|
187
|
+
end
|
188
|
+
|
189
|
+
##
|
190
|
+
# Look up a key including checking its underscore form
|
191
|
+
#
|
192
|
+
# @param hash [Hash] hash structure
|
193
|
+
# @param key [String] lowerCamelCase string
|
194
|
+
# @return [Object] the result, or `nil` if not found
|
195
|
+
#
|
196
|
+
def self.get hash, key
|
197
|
+
hash[key] || hash[ActiveSupport::Inflector.underscore(key)]
|
198
|
+
end
|
199
|
+
|
178
200
|
##
|
179
201
|
# Determines if a given string can be converted to a float
|
180
202
|
#
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |gem|
|
|
30
30
|
|
31
31
|
gem.add_development_dependency "google-style", "~> 1.24.0"
|
32
32
|
gem.add_development_dependency "minitest", "~> 5.10"
|
33
|
-
gem.add_development_dependency "rake", "
|
33
|
+
gem.add_development_dependency "rake", ">= 12.0"
|
34
34
|
gem.add_development_dependency "redcarpet", "~> 3.0"
|
35
35
|
gem.add_development_dependency "simplecov", "~> 0.18"
|
36
36
|
gem.add_development_dependency "yard", "~> 0.9"
|
@@ -2,27 +2,7 @@
|
|
2
2
|
<%- method_service ||= service -%>
|
3
3
|
@configure ||= begin
|
4
4
|
default_config = <%= service.client_name %>::Configuration.new
|
5
|
-
|
6
|
-
|
7
|
-
<%- if service.grpc_service_config.timeout_seconds -%>
|
8
|
-
default_config.timeout = <%= service.grpc_service_config.timeout_seconds %>
|
9
|
-
<%- end -%>
|
10
|
-
<%- if service.grpc_service_config.retry_policy -%>
|
11
|
-
default_config.retry_policy = <%= indent_tail render(partial: "service/client/self_configure_retry_policy", locals: { retry_policy: service.grpc_service_config.retry_policy }), 2 %>
|
12
|
-
<%- end -%>
|
13
|
-
<%- end -%>
|
14
|
-
<%- method_service.methods.each do |method| -%>
|
15
|
-
<%- if method.grpc_service_config && !method.grpc_service_config.empty? -%>
|
16
|
-
|
17
|
-
<%- if method.grpc_service_config.timeout_seconds -%>
|
18
|
-
default_config.rpcs.<%= method.name %>.timeout = <%= method.grpc_service_config.timeout_seconds %>
|
19
|
-
<%- end -%>
|
20
|
-
<%- if method.grpc_service_config.retry_policy -%>
|
21
|
-
default_config.rpcs.<%= method.name %>.retry_policy =<%= indent_tail render(partial: "service/client/self_configure_retry_policy", locals: { retry_policy: method.grpc_service_config.retry_policy }), 2 %>
|
22
|
-
<%- end -%>
|
23
|
-
<%- end -%>
|
24
|
-
<%- end -%>
|
25
|
-
|
5
|
+
<%= render partial: "service/client/self_configure_defaults", locals: {service: service} %>
|
26
6
|
default_config
|
27
7
|
end
|
28
8
|
yield @configure if block_given?
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<%- assert_locals service -%>
|
2
|
+
<%- method_service ||= service -%>
|
3
|
+
<%- if service.grpc_service_config && !service.grpc_service_config.empty? -%>
|
4
|
+
|
5
|
+
<%- if service.grpc_service_config.timeout_seconds -%>
|
6
|
+
default_config.timeout = <%= service.grpc_service_config.timeout_seconds %>
|
7
|
+
<%- end -%>
|
8
|
+
<%- if service.grpc_service_config.retry_policy -%>
|
9
|
+
default_config.retry_policy = <%= indent_tail render(partial: "service/client/self_configure_retry_policy", locals: { retry_policy: service.grpc_service_config.retry_policy }), 2 %>
|
10
|
+
<%- end -%>
|
11
|
+
<%- end -%>
|
12
|
+
<%- method_service.methods.each do |method| -%>
|
13
|
+
<%- if method.grpc_service_config && !method.grpc_service_config.empty? -%>
|
14
|
+
|
15
|
+
<%- if method.grpc_service_config.timeout_seconds -%>
|
16
|
+
default_config.rpcs.<%= method.name %>.timeout = <%= method.grpc_service_config.timeout_seconds %>
|
17
|
+
<%- end -%>
|
18
|
+
<%- if method.grpc_service_config.retry_policy -%>
|
19
|
+
default_config.rpcs.<%= method.name %>.retry_policy =<%= indent_tail render(partial: "service/client/self_configure_retry_policy", locals: { retry_policy: method.grpc_service_config.retry_policy }), 2 %>
|
20
|
+
<%- end -%>
|
21
|
+
<%- end -%>
|
22
|
+
<%- 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.1.
|
4
|
+
version: 0.1.1
|
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-03-
|
13
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
name: rake
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- - "
|
131
|
+
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '12.0'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- - "
|
138
|
+
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '12.0'
|
141
141
|
- !ruby/object:Gem::Dependency
|
@@ -278,6 +278,7 @@ files:
|
|
278
278
|
- templates/default/service/client/_requires.erb
|
279
279
|
- templates/default/service/client/_resource.erb
|
280
280
|
- templates/default/service/client/_self_configure.erb
|
281
|
+
- templates/default/service/client/_self_configure_defaults.erb
|
281
282
|
- templates/default/service/client/_self_configure_retry_policy.erb
|
282
283
|
- templates/default/service/client/method/_def.erb
|
283
284
|
- templates/default/service/client/method/def/_options_defaults.erb
|