gapic-generator-cloud 0.1.7 → 0.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/bin/ruby-cloud-docker-entrypoint +49 -30
- data/lib/gapic/generator/cloud/version.rb +1 -1
- data/lib/gapic/generators/cloud_generator.rb +45 -1
- data/lib/gapic/presenters/wrapper_gem_presenter.rb +119 -0
- data/lib/gapic/presenters/wrapper_service_presenter.rb +49 -0
- data/templates/cloud/gem/authentication.erb +14 -14
- data/templates/cloud/gem/license.erb +190 -188
- data/templates/cloud/gem/rakefile.erb +74 -2
- data/templates/cloud/gem/rubocop.erb +3 -0
- data/templates/cloud/gem/yardopts.erb +1 -1
- data/templates/cloud/wrapper_gem/_main.erb +75 -0
- data/templates/cloud/wrapper_gem/client_test.erb +22 -0
- data/templates/cloud/wrapper_gem/dashed.erb +22 -0
- data/templates/cloud/wrapper_gem/gemfile.erb +17 -0
- data/templates/cloud/wrapper_gem/gemspec.erb +40 -0
- data/templates/cloud/wrapper_gem/main.erb +5 -0
- data/templates/cloud/wrapper_gem/rakefile.erb +190 -0
- data/templates/cloud/wrapper_gem/readme.erb +95 -0
- data/templates/cloud/wrapper_gem/rubocop.erb +23 -0
- data/templates/cloud/wrapper_gem/test_helper.erb +9 -0
- data/templates/cloud/wrapper_gem/version_test.erb +11 -0
- data/templates/cloud/wrapper_gem/yardopts.erb +15 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94f5a540b0be42593cb412dd12b4faedde7bfb63ab763a17fc0996b092aad140
|
4
|
+
data.tar.gz: f56a2ad37c354bfc8bfcaceec8ba2243fdd91fd90adcc225c63f1e3d4e9259af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3967ad36a668b618cfcb254aee896451bc404a885f0d0ebee309878f56c1df5868ebe5fe237c990b9c51bd39ea4fb9626f4a919e1b1ff4c4a5165d1574b7605c
|
7
|
+
data.tar.gz: 73232e7e89e8f450e428c8cc13bc474ad77023d780e2ae29e8426f942940cdb6f07cb1ad0da8d59304d2f1a5956835f014d3ccec607a52cb9efa45866b2576cc
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Release History for gapic-generator-cloud
|
2
2
|
|
3
|
+
### 0.2.0 / 2020-03-23
|
4
|
+
|
5
|
+
* Includes changes from gapic-generator 0.2.0
|
6
|
+
* The cloud generator can now be configured to generate wrapper gems.
|
7
|
+
|
3
8
|
### 0.1.7 / 2020-03-18
|
4
9
|
|
5
10
|
* Includes changes from gapic-generator 0.1.7
|
@@ -18,38 +18,51 @@
|
|
18
18
|
require "optparse"
|
19
19
|
require "fileutils"
|
20
20
|
|
21
|
+
bool_option_map = {
|
22
|
+
":gem.:free_tier" => "ruby-cloud-free-tier",
|
23
|
+
":gem.:yard_strict" => "ruby-cloud-yard-strict"
|
24
|
+
}
|
25
|
+
value_option_map = {
|
26
|
+
"configuration" => "ruby-cloud-config",
|
27
|
+
":gem.:name" => "ruby-cloud-gem-name",
|
28
|
+
":gem.:title" => "ruby-cloud-title",
|
29
|
+
":gem.:description" => "ruby-cloud-description",
|
30
|
+
":gem.:summary" => "ruby-cloud-summary",
|
31
|
+
":gem.:homepage" => "ruby-cloud-homepage",
|
32
|
+
":gem.:env_prefix" => "ruby-cloud-env-prefix",
|
33
|
+
":gem.:version_dependencies" => "ruby-cloud-wrapper-of",
|
34
|
+
":gem.:migration_version" => "ruby-cloud-migration-version",
|
35
|
+
":gem.:product_documentation_url" => "ruby-cloud-product-url",
|
36
|
+
":gem.:api_id" => "ruby-cloud-api-id",
|
37
|
+
":gem.:factory_method_suffix" => "ruby-cloud-factory-method-suffix"
|
38
|
+
}
|
39
|
+
path_option_map = {
|
40
|
+
"samples" => ["ruby-cloud-samples", "samples"],
|
41
|
+
"grpc_service_config" => "ruby-cloud-grpc-service-config"
|
42
|
+
}
|
43
|
+
|
21
44
|
parameters = {}
|
22
45
|
|
23
46
|
OptionParser.new do |op|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
.map { |path| File.expand_path path, "/in" }
|
30
|
-
.join(";")
|
31
|
-
parameters["samples"] = paths
|
32
|
-
end
|
33
|
-
op.on "--ruby-cloud-grpc-service-config FILE" do |val|
|
34
|
-
paths = val.split(";")
|
35
|
-
.map { |path| File.expand_path path, "/in" }
|
36
|
-
.join(";")
|
37
|
-
parameters["grpc_service_config"] = paths
|
38
|
-
end
|
39
|
-
op.on "--ruby-cloud-gem-name NAME" do |val|
|
40
|
-
parameters[":gem.:name"] = val
|
47
|
+
bool_option_map.each do |key, flags|
|
48
|
+
flags = Array(flags).map { |f| "--#{f}" }
|
49
|
+
op.on(*flags) do
|
50
|
+
parameters[key] = "true"
|
51
|
+
end
|
41
52
|
end
|
42
|
-
|
43
|
-
|
53
|
+
value_option_map.each do |key, flags|
|
54
|
+
flags = Array(flags).map { |f| "--#{f} VAL" }
|
55
|
+
op.on(*flags) do |val|
|
56
|
+
parameters[key] = val
|
57
|
+
end
|
44
58
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
parameters[":gem.:env_prefix"] = val
|
59
|
+
path_option_map.each do |key, flags|
|
60
|
+
flags = Array(flags).map { |f| "--#{f} PATH" }
|
61
|
+
op.on(*flags) do |paths|
|
62
|
+
parameters[key] = paths.split(";")
|
63
|
+
.map { |path| File.expand_path path, "/in" }
|
64
|
+
.join(";")
|
65
|
+
end
|
53
66
|
end
|
54
67
|
end.parse! ARGV
|
55
68
|
|
@@ -59,11 +72,17 @@ parameter_strs =
|
|
59
72
|
"#{k}=#{v}"
|
60
73
|
end
|
61
74
|
|
75
|
+
ruby_plugin_args =
|
76
|
+
if parameters[":gem.:version_dependencies"]
|
77
|
+
[]
|
78
|
+
else
|
79
|
+
["--ruby_out=/out/lib", "--grpc_out=/out/lib"]
|
80
|
+
end
|
81
|
+
|
62
82
|
protoc_cmd = [
|
63
83
|
"grpc_tools_ruby_protoc",
|
64
|
-
"--proto_path=/protos/", "--proto_path=/in/"
|
65
|
-
|
66
|
-
"--grpc_out=/out/lib",
|
84
|
+
"--proto_path=/protos/", "--proto_path=/in/"
|
85
|
+
] + ruby_plugin_args + [
|
67
86
|
"--ruby_cloud_out=/out/",
|
68
87
|
"--ruby_cloud_opt", parameter_strs.join(",")
|
69
88
|
] + ARGV + Dir.glob("/in/**/*.proto").sort
|
@@ -15,6 +15,8 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
17
|
require "gapic/generators/default_generator"
|
18
|
+
require "gapic/presenters"
|
19
|
+
require "gapic/presenters/wrapper_gem_presenter"
|
18
20
|
|
19
21
|
module Gapic
|
20
22
|
module Generators
|
@@ -41,11 +43,14 @@ module Gapic
|
|
41
43
|
# Google::Protobuf::Compiler::CodeGeneratorResponse::File>]
|
42
44
|
# The files that were generated for the API.
|
43
45
|
def generate
|
46
|
+
gem_config = @api.configuration[:gem] ||= {}
|
47
|
+
return generate_wrapper if gem_config[:version_dependencies]
|
48
|
+
|
44
49
|
orig_files = super
|
45
50
|
|
46
51
|
cloud_files = []
|
47
52
|
|
48
|
-
gem = gem_presenter @api
|
53
|
+
gem = Gapic::Presenters.gem_presenter @api
|
49
54
|
|
50
55
|
# Additional Gem level files
|
51
56
|
cloud_files << g("gem/repo-metadata.erb", ".repo-metadata.json", gem: gem)
|
@@ -57,6 +62,45 @@ module Gapic
|
|
57
62
|
orig_files + cloud_files
|
58
63
|
end
|
59
64
|
|
65
|
+
# Disable Rubocop because we expect generate to grow and violate more
|
66
|
+
# and more style rules.
|
67
|
+
# rubocop:disable all
|
68
|
+
|
69
|
+
# Generates the files for a wrapper.
|
70
|
+
#
|
71
|
+
# @return [Array<Google::Protobuf::Compiler::CodeGeneratorResponse::File>]
|
72
|
+
# The files that were generated for the API.
|
73
|
+
#
|
74
|
+
def generate_wrapper
|
75
|
+
files = []
|
76
|
+
|
77
|
+
gem = Gapic::Presenters.wrapper_gem_presenter @api
|
78
|
+
|
79
|
+
files << g("gem/gitignore.erb", ".gitignore", gem: gem)
|
80
|
+
files << g("gem/repo-metadata.erb", ".repo-metadata.json", gem: gem)
|
81
|
+
files << g("wrapper_gem/rubocop.erb", ".rubocop.yml", gem: gem)
|
82
|
+
files << g("wrapper_gem/yardopts.erb", ".yardopts", gem: gem)
|
83
|
+
files << g("gem/authentication.erb", "AUTHENTICATION.md", gem: gem)
|
84
|
+
files << g("gem/changelog.erb", "CHANGELOG.md", gem: gem)
|
85
|
+
files << g("wrapper_gem/gemfile.erb", "Gemfile", gem: gem)
|
86
|
+
files << g("gem/license.erb", "LICENSE.md", gem: gem)
|
87
|
+
files << g("wrapper_gem/rakefile.erb", "Rakefile", gem: gem)
|
88
|
+
files << g("wrapper_gem/readme.erb", "README.md", gem: gem)
|
89
|
+
files << g("wrapper_gem/gemspec.erb", "#{gem.name}.gemspec", gem: gem)
|
90
|
+
files << g("wrapper_gem/dashed.erb", "lib/#{gem.name}.rb", gem: gem) if gem.needs_dashed_ruby_file?
|
91
|
+
files << g("wrapper_gem/main.erb", "lib/#{gem.namespace_file_path}", gem: gem)
|
92
|
+
files << g("gem/version.erb", "lib/#{gem.version_file_path}", gem: gem)
|
93
|
+
files << g("wrapper_gem/test_helper.erb", "test/helper.rb", gem: gem)
|
94
|
+
files << g("wrapper_gem/client_test.erb", "test/#{gem.namespace_require}/client_test.rb", gem: gem)
|
95
|
+
files << g("wrapper_gem/version_test.erb", "test/#{gem.namespace_require}/version_test.rb", gem: gem)
|
96
|
+
|
97
|
+
format_files files
|
98
|
+
|
99
|
+
files
|
100
|
+
end
|
101
|
+
|
102
|
+
# rubocop:enable all
|
103
|
+
|
60
104
|
private
|
61
105
|
|
62
106
|
##
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "gapic/presenters"
|
18
|
+
require "gapic/presenters/wrapper_service_presenter"
|
19
|
+
|
20
|
+
module Gapic
|
21
|
+
module Presenters
|
22
|
+
##
|
23
|
+
# A presenter for wrapper gems.
|
24
|
+
#
|
25
|
+
class WrapperGemPresenter < GemPresenter
|
26
|
+
def entrypoint_require
|
27
|
+
namespace_require
|
28
|
+
end
|
29
|
+
|
30
|
+
def services
|
31
|
+
@services ||= begin
|
32
|
+
files = @api.generate_files
|
33
|
+
files.map(&:services).flatten.map { |s| WrapperServicePresenter.new @api, s }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def namespace_require
|
38
|
+
ruby_file_path @api, namespace
|
39
|
+
end
|
40
|
+
|
41
|
+
def namespace_file_path
|
42
|
+
"#{namespace_require}.rb"
|
43
|
+
end
|
44
|
+
|
45
|
+
def needs_dashed_ruby_file?
|
46
|
+
name != namespace_file_path
|
47
|
+
end
|
48
|
+
|
49
|
+
def migration_version
|
50
|
+
gem_config :migration_version
|
51
|
+
end
|
52
|
+
|
53
|
+
def pre_migration_version
|
54
|
+
m = /^(\d)+\./.match migration_version.to_s
|
55
|
+
return nil unless m
|
56
|
+
"#{m[1].to_i - 1}.x"
|
57
|
+
end
|
58
|
+
|
59
|
+
def migration?
|
60
|
+
migration_version ? true : false
|
61
|
+
end
|
62
|
+
|
63
|
+
def extra_files
|
64
|
+
files = ["README.md", "AUTHENTICATION.md", "LICENSE.md", ".yardopts"]
|
65
|
+
files << "MIGRATING.md" if migration?
|
66
|
+
files
|
67
|
+
end
|
68
|
+
|
69
|
+
def factory_method_suffix
|
70
|
+
gem_config(:factory_method_suffix).to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
def version_dependencies
|
74
|
+
gem_config(:version_dependencies).to_s.split(";").map { |str| str.split ":" }
|
75
|
+
end
|
76
|
+
|
77
|
+
def gem_version_dependencies
|
78
|
+
version_dependencies.sort_by { |version, _requirement| version }
|
79
|
+
.map { |version, requirement| ["#{name}-#{version}", requirement] }
|
80
|
+
end
|
81
|
+
|
82
|
+
def versioned_gems
|
83
|
+
gem_version_dependencies.map { |name, _requirement| name }
|
84
|
+
end
|
85
|
+
|
86
|
+
def default_version
|
87
|
+
version_dependencies.first&.first
|
88
|
+
end
|
89
|
+
|
90
|
+
def google_cloud_short_name
|
91
|
+
m = /^google-cloud-(.*)$/.match name
|
92
|
+
return nil unless m
|
93
|
+
m[1].tr "-", "_"
|
94
|
+
end
|
95
|
+
|
96
|
+
def docs_link version: nil, class_name: nil, text: nil
|
97
|
+
gem_name = version ? "#{name}-#{version}" : name
|
98
|
+
base_url = "https://googleapis.dev/ruby/#{gem_name}/latest"
|
99
|
+
if class_name
|
100
|
+
path = namespace.gsub "::", "/"
|
101
|
+
path = "#{path}/#{version.capitalize}" if version
|
102
|
+
class_path = class_name.gsub "::", "/"
|
103
|
+
text ||= namespaced_class class_name, version: version
|
104
|
+
return "[#{text}](#{base_url}/#{path}/#{class_path}.html)"
|
105
|
+
end
|
106
|
+
"[#{text || name}](#{base_url})"
|
107
|
+
end
|
108
|
+
|
109
|
+
def namespaced_class name, version: nil
|
110
|
+
base = version ? "#{namespace}::#{version.capitalize}" : namespace
|
111
|
+
"#{base}::#{name}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.wrapper_gem_presenter api
|
116
|
+
WrapperGemPresenter.new api
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "gapic/presenters"
|
18
|
+
|
19
|
+
module Gapic
|
20
|
+
module Presenters
|
21
|
+
##
|
22
|
+
# A presenter for wrapper services.
|
23
|
+
#
|
24
|
+
class WrapperServicePresenter < ServicePresenter
|
25
|
+
def gem
|
26
|
+
WrapperGemPresenter.new @api
|
27
|
+
end
|
28
|
+
|
29
|
+
def factory_method_name
|
30
|
+
method_name = ActiveSupport::Inflector.underscore name
|
31
|
+
suffix = gem.factory_method_suffix
|
32
|
+
method_name = "#{method_name}#{suffix}" unless method_name.end_with? suffix
|
33
|
+
method_name
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_client_call
|
37
|
+
"#{gem.namespace}.#{factory_method_name}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def configure_client_call
|
41
|
+
"#{gem.namespace}.configure"
|
42
|
+
end
|
43
|
+
|
44
|
+
def credentials_class_xref
|
45
|
+
"`#{credentials_name_full}`"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -28,16 +28,16 @@ export <%= gem.env_prefix %>_CREDENTIALS=path/to/keyfile.json
|
|
28
28
|
3. Initialize the client.
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
require "<%=
|
31
|
+
require "<%= gem.entrypoint_require %>"
|
32
32
|
|
33
|
-
client = <%= service.
|
33
|
+
client = <%= service.create_client_call %>
|
34
34
|
```
|
35
35
|
|
36
36
|
## Credential Lookup
|
37
37
|
|
38
38
|
The <%= gem.name %> library aims to make authentication
|
39
39
|
as simple as possible, and provides several mechanisms to configure your system
|
40
|
-
without **Service Account Credentials** directly in code.
|
40
|
+
without requiring **Service Account Credentials** directly in code.
|
41
41
|
|
42
42
|
**Credentials** are discovered in the following order:
|
43
43
|
|
@@ -67,7 +67,7 @@ containers where writing files is difficult or not encouraged.
|
|
67
67
|
|
68
68
|
The environment variables that <%= gem.name %>
|
69
69
|
checks for credentials are configured on the service Credentials class (such as
|
70
|
-
|
70
|
+
<%= service.credentials_class_xref %>):
|
71
71
|
|
72
72
|
1. `<%= gem.env_prefix %>_CREDENTIALS` - Path to JSON file, or JSON contents
|
73
73
|
2. `<%= gem.env_prefix %>_KEYFILE` - Path to JSON file, or JSON contents
|
@@ -76,11 +76,11 @@ checks for credentials are configured on the service Credentials class (such as
|
|
76
76
|
5. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
|
77
77
|
|
78
78
|
```ruby
|
79
|
-
require "<%=
|
79
|
+
require "<%= gem.entrypoint_require %>"
|
80
80
|
|
81
81
|
ENV["<%= gem.env_prefix %>_CREDENTIALS"] = "path/to/keyfile.json"
|
82
82
|
|
83
|
-
client = <%= service.
|
83
|
+
client = <%= service.create_client_call %>
|
84
84
|
```
|
85
85
|
|
86
86
|
### Configuration
|
@@ -89,9 +89,9 @@ The **Credentials JSON** can be configured instead of placing them in
|
|
89
89
|
environment variables. Either on an individual client initialization:
|
90
90
|
|
91
91
|
```ruby
|
92
|
-
require "<%=
|
92
|
+
require "<%= gem.entrypoint_require %>"
|
93
93
|
|
94
|
-
client = <%= service.
|
94
|
+
client = <%= service.create_client_call %> do |config|
|
95
95
|
config.credentials = "path/to/keyfile.json"
|
96
96
|
end
|
97
97
|
```
|
@@ -99,13 +99,13 @@ end
|
|
99
99
|
Or configured globally for all clients:
|
100
100
|
|
101
101
|
```ruby
|
102
|
-
require "<%=
|
102
|
+
require "<%= gem.entrypoint_require %>"
|
103
103
|
|
104
|
-
<%= service.
|
104
|
+
<%= service.configure_client_call %> do |config|
|
105
105
|
config.credentials = "path/to/keyfile.json"
|
106
106
|
end
|
107
107
|
|
108
|
-
client = <%= service.
|
108
|
+
client = <%= service.create_client_call %>
|
109
109
|
```
|
110
110
|
|
111
111
|
### Cloud SDK
|
@@ -138,9 +138,9 @@ Google Cloud requires **Service Account Credentials** to
|
|
138
138
|
connect to the APIs. You will use the **JSON key file** to
|
139
139
|
connect to most services with <%= gem.name %>.
|
140
140
|
|
141
|
-
If you are not running this client within
|
142
|
-
environments](#google-cloud-platform-environments), you
|
143
|
-
Developers service account.
|
141
|
+
If you are not running this client within
|
142
|
+
[Google Cloud Platform environments](#google-cloud-platform-environments), you
|
143
|
+
need a Google Developers service account.
|
144
144
|
|
145
145
|
1. Visit the [Google Developers Console][dev-console].
|
146
146
|
2. Create a new project or click on an existing project.
|