gapic-generator-cloud 0.11.0 → 0.45.1

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +302 -0
  3. data/README.md +82 -61
  4. data/bin/protoc-gen-bazel_ruby_cloud +2 -2
  5. data/bin/protoc-gen-ruby_cloud +2 -2
  6. data/lib/gapic/generator/cloud/version.rb +1 -1
  7. data/lib/gapic/generators/cloud_generator.rb +20 -19
  8. data/lib/gapic/generators/cloud_generator_parameters.rb +4 -1
  9. data/lib/gapic/presenters/cloud_gem_presenter.rb +56 -15
  10. data/lib/gapic/presenters/wrapper_gem_presenter.rb +31 -9
  11. data/lib/gapic/presenters/wrapper_service_presenter.rb +3 -3
  12. data/templates/cloud/gem/authentication.text.erb +125 -0
  13. data/templates/cloud/gem/{rakefile.erb → rakefile.text.erb} +0 -32
  14. data/templates/cloud/gem/{readme.erb → readme.text.erb} +48 -26
  15. data/templates/cloud/gem/{repo-metadata.erb → repo-metadata.text.erb} +3 -4
  16. data/templates/cloud/gem/{rubocop.erb → rubocop.text.erb} +3 -0
  17. data/templates/cloud/service/rest/client/method/def/_rescue.text.erb +3 -0
  18. data/templates/cloud/wrapper_gem/{_main.erb → _main.text.erb} +67 -16
  19. data/templates/cloud/wrapper_gem/client_test.text.erb +59 -0
  20. data/templates/cloud/wrapper_gem/gemfile.text.erb +29 -0
  21. data/templates/cloud/wrapper_gem/{gemspec.erb → gemspec.text.erb} +2 -11
  22. data/templates/cloud/wrapper_gem/{rakefile.erb → rakefile.text.erb} +2 -32
  23. data/templates/cloud/wrapper_gem/{readme.erb → readme.text.erb} +45 -37
  24. data/templates/cloud/wrapper_gem/{version_test.erb → version_test.text.erb} +1 -1
  25. metadata +33 -163
  26. data/templates/cloud/gem/authentication.erb +0 -156
  27. data/templates/cloud/service/rest/client/method/def/_rescue.erb +0 -4
  28. data/templates/cloud/wrapper_gem/client_test.erb +0 -29
  29. data/templates/cloud/wrapper_gem/gemfile.erb +0 -8
  30. /data/templates/cloud/gem/{gitignore.erb → gitignore.text.erb} +0 -0
  31. /data/templates/cloud/gem/{license.erb → license.text.erb} +0 -0
  32. /data/templates/cloud/gem/{yardopts.erb → yardopts.text.erb} +0 -0
  33. /data/templates/cloud/service/client/{_credentials.erb → _credentials.text.erb} +0 -0
  34. /data/templates/cloud/service/client/{_requires.erb → _requires.text.erb} +0 -0
  35. /data/templates/cloud/service/client/{_self_configure.erb → _self_configure.text.erb} +0 -0
  36. /data/templates/cloud/service/client/method/def/{_rescue.erb → _rescue.text.erb} +0 -0
  37. /data/templates/cloud/service/client/method/docs/{_error.erb → _error.text.erb} +0 -0
  38. /data/templates/cloud/service/rest/client/method/docs/{_error.erb → _error.text.erb} +0 -0
  39. /data/templates/cloud/shared/{_license.erb → _license.text.erb} +0 -0
  40. /data/templates/cloud/wrapper_gem/{entrypoint.erb → entrypoint.text.erb} +0 -0
  41. /data/templates/cloud/wrapper_gem/{main.erb → main.text.erb} +0 -0
  42. /data/templates/cloud/wrapper_gem/{rubocop.erb → rubocop.text.erb} +0 -0
  43. /data/templates/cloud/wrapper_gem/{yardopts.erb → yardopts.text.erb} +0 -0
@@ -23,6 +23,19 @@ module Gapic
23
23
  # A presenter subclass for cloud gems.
24
24
  #
25
25
  class CloudGemPresenter < GemPresenter
26
+ # @private
27
+ # A list of gem name patterns for gems that don't look like cloud but are
28
+ PSEUDO_CLOUD_GEMS = [
29
+ /^google-iam-credentials/,
30
+ /^google-identity-access_context_manager/,
31
+ /^grafeas/,
32
+ /^stackdriver/
33
+ ].freeze
34
+
35
+ # @private
36
+ # A list of gem name patterns for gems that look like cloud but aren't
37
+ NON_CLOUD_GEMS = [].freeze
38
+
26
39
  def license_name
27
40
  "Apache-2.0"
28
41
  end
@@ -56,23 +69,18 @@ module Gapic
56
69
  minfo ? minfo[1] : nil
57
70
  end
58
71
 
59
- alias_method :readme_description, :description # rubocop:disable Style/Alias
60
-
61
72
  ##
62
- # Overrides the gemspec description including a note that users should
63
- # consider installing the wrapper instead of this versioned gem.
64
- #
65
- # Note: The method `readme_description` was aliased to the superclass
66
- # method because the description without this note is used in the readme.
73
+ # Increments the original gemspec description for versioned gems, including a
74
+ # note that users should consider installing the wrapper gem instead.
67
75
  #
68
76
  # @return [String]
69
77
  #
70
- def description
71
- desc = readme_description
78
+ def gemspec_description
79
+ desc = super
72
80
  if has_wrapper?
73
- desc += " Note that #{name} is a version-specific client library." \
74
- " For most uses, we recommend installing the main client library" \
75
- " #{wrapper_name} instead. See the readme for more details."
81
+ desc += " Note that #{name} is a version-specific client library. " \
82
+ "For most uses, we recommend installing the main client library " \
83
+ "#{wrapper_name} instead. See the readme for more details."
76
84
  end
77
85
  desc
78
86
  end
@@ -87,7 +95,7 @@ module Gapic
87
95
  #
88
96
  def generator_args_for_metadata
89
97
  result = {}
90
- result["ruby-cloud-description"] = description
98
+ result["ruby-cloud-description"] = gemspec_description
91
99
  result["ruby-cloud-env-prefix"] = env_prefix if env_prefix
92
100
  result["ruby-cloud-product-url"] = product_documentation_url if product_documentation_url
93
101
  path_overrides = @api.overrides_of(:file_path).map { |k, v| "#{k}=#{v}" }.join ";"
@@ -100,9 +108,42 @@ module Gapic
100
108
  end
101
109
 
102
110
  ##
103
- # Overrides the reference doc URL to point to the cloud-rad page
111
+ # Overrides the reference doc URL to point to either the cloud-rad page
112
+ # or the rubydoc.info page depending on whether it is a cloud product.
113
+ #
114
+ # @return [String]
115
+ #
104
116
  def library_documentation_url
105
- gem_config(:library_documentation_url) || "https://cloud.google.com/ruby/docs/reference/#{name}/latest"
117
+ gem_config(:library_documentation_url) || begin
118
+ if cloud_product?
119
+ "https://cloud.google.com/ruby/docs/reference/#{name}/latest"
120
+ else
121
+ "https://rubydoc.info/gems/#{name}"
122
+ end
123
+ end
124
+ end
125
+
126
+ ##
127
+ # Whether this gem is for a cloud platform product. This controls, for
128
+ # example, whether the reference documentation appears under the
129
+ # cloud.google.com website.
130
+ #
131
+ # This first uses the `is_cloud_product` config. If that isn't set, it
132
+ # tries the overrides in the `PSEUDO_CLOUD_GEMS` and `NON_CLOUD_GEMS`
133
+ # constants. Finally, it looks for whether any services populate the
134
+ # `Google::Cloud` namespace.
135
+ #
136
+ # @return [boolean]
137
+ #
138
+ def cloud_product?
139
+ configured = gem_config :is_cloud_product
140
+ return configured unless configured.nil?
141
+ return @api.api_metadata.organization == "CLOUD" if @api.api_metadata.organization
142
+ return true if PSEUDO_CLOUD_GEMS.any? { |pattern| pattern === name }
143
+ return false if NON_CLOUD_GEMS.any? { |pattern| pattern === name }
144
+ services.any? do |service|
145
+ service.namespace =~ /^(::)?Google::Cloud::/
146
+ end
106
147
  end
107
148
  end
108
149
 
@@ -14,6 +14,7 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require "gapic/model/mixins"
17
18
  require "gapic/presenters"
18
19
  require "gapic/presenters/wrapper_service_presenter"
19
20
 
@@ -29,8 +30,11 @@ module Gapic
29
30
 
30
31
  def services
31
32
  @services ||= begin
32
- files = @api.generate_files
33
- files.map(&:services).flatten.map { |s| WrapperServicePresenter.new self, @api, s }
33
+ @api.generate_files
34
+ .map(&:services)
35
+ .flatten
36
+ .map { |s| WrapperServicePresenter.new self, @api, s }
37
+ .find_all { |s| !s.is_hosted_mixin? }
34
38
  end
35
39
  end
36
40
 
@@ -62,6 +66,18 @@ module Gapic
62
66
  gem_config :migration_version
63
67
  end
64
68
 
69
+ ##
70
+ # Generates a description text for README files, accounting for markdown
71
+ # rendering, properly escaping variables and disabling xrefs in the wrapper.
72
+ #
73
+ # @return [Array<String>] The description text as an array of lines.
74
+ #
75
+ def readme_description
76
+ has_markdown = description.strip.start_with? "#"
77
+ desc = has_markdown ? description.split("\n") : [description.gsub(/\s+/, " ").strip]
78
+ Gapic::FormattingUtils.format_doc_lines @api, desc, disable_xrefs: true
79
+ end
80
+
65
81
  # A description of the versions prior to the migration version.
66
82
  # Could be "a.x" if the migration version is 1.0 or later, otherwise
67
83
  # falls back to "pre-a.b".
@@ -132,15 +148,21 @@ module Gapic
132
148
  m[1].tr "-", "_"
133
149
  end
134
150
 
135
- def docs_link version: nil, class_name: nil, text: nil
136
- gem_name = version ? "#{name}-#{version}" : name
137
- base_url = "https://googleapis.dev/ruby/#{gem_name}/latest"
151
+ def docs_link version: nil, class_name: nil, text: nil, gem_name: nil
152
+ gem_name ||= version ? "#{name}-#{version}" : name
153
+ base_url =
154
+ if cloud_product?
155
+ "https://cloud.google.com/ruby/docs/reference/#{gem_name}/latest"
156
+ else
157
+ "https://rubydoc.info/gems/#{gem_name}"
158
+ end
138
159
  if class_name
139
- path = namespace.gsub "::", "/"
140
- path = "#{path}/#{version.capitalize}" if version
141
- class_path = class_name.gsub "::", "/"
160
+ separator = cloud_product? ? "-" : "/"
161
+ path = namespace.gsub "::", separator
162
+ path = "#{path}#{separator}#{version.capitalize}" if version
163
+ class_path = class_name.gsub "::", separator
142
164
  text ||= namespaced_class class_name, version: version
143
- return "[#{text}](#{base_url}/#{path}/#{class_path}.html)"
165
+ return "[#{text}](#{base_url}/#{path}#{separator}#{class_path})"
144
166
  end
145
167
  "[#{text || name}](#{base_url})"
146
168
  end
@@ -35,7 +35,7 @@ module Gapic
35
35
  suffix = gem.factory_method_suffix
36
36
  method_name = "#{method_name}#{suffix}" unless method_name.end_with? suffix
37
37
  method_name = "#{method_name}_client" if Gapic::RubyInfo.excluded_method_names.include? method_name
38
- method_name
38
+ @api.fix_file_path method_name
39
39
  end
40
40
  end
41
41
 
@@ -48,9 +48,9 @@ module Gapic
48
48
  # @return [WrapperServicePresenter,WrapperServiceRestPresenter,nil]
49
49
  #
50
50
  def usable_service_presenter
51
- if @api.generate_grpc_clients?
51
+ if generate_grpc_clients?
52
52
  self
53
- elsif @api.generate_rest_clients? && methods_rest_bindings?
53
+ elsif generate_rest_clients?
54
54
  rest
55
55
  end
56
56
  end
@@ -0,0 +1,125 @@
1
+ <%- assert_locals gem -%>
2
+ <%- service = gem.first_non_common_service.usable_service_presenter -%>
3
+ <%- assert_locals service -%>
4
+ # Authentication
5
+
6
+ The recommended way to authenticate to the <%= gem.name %> library is to use
7
+ [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials).
8
+ To review all of your authentication options, see [Credentials lookup](#credential-lookup).
9
+
10
+ ## Quickstart
11
+
12
+ The following example shows how to set up authentication for a local development
13
+ environment with your user credentials.
14
+
15
+ **NOTE:** This method is _not_ recommended for running in production. User credentials
16
+ should be used only during development.
17
+
18
+ 1. [Download and install the Google Cloud CLI](https://cloud.google.com/sdk).
19
+ 2. Set up a local ADC file with your user credentials:
20
+
21
+ ```sh
22
+ gcloud auth application-default login
23
+ ```
24
+
25
+ 3. Write code as if already authenticated.
26
+
27
+ For more information about setting up authentication for a local development environment, see
28
+ [Set up Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-dev).
29
+
30
+ ## Credential Lookup
31
+
32
+ The <%= gem.name %> library provides several mechanisms to configure your system.
33
+ Generally, using Application Default Credentials to facilitate automatic
34
+ credentials discovery is the easist method. But if you need to explicitly specify
35
+ credentials, there are several methods available to you.
36
+
37
+ Credentials are accepted in the following ways, in the following order or precedence:
38
+
39
+ 1. Credentials specified in method arguments
40
+ 2. Credentials specified in configuration
41
+ 3. Credentials pointed to or included in environment variables
42
+ 4. Credentials found in local ADC file
43
+ 5. Credentials returned by the metadata server for the attached service account (GCP)
44
+
45
+ ### Configuration
46
+
47
+ You can configure a path to a JSON credentials file, either for an individual client object or
48
+ globally, for all client objects. The JSON file can contain credentials created for
49
+ [workload identity federation](https://cloud.google.com/iam/docs/workload-identity-federation),
50
+ [workforce identity federation](https://cloud.google.com/iam/docs/workforce-identity-federation), or a
51
+ [service account key](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-key).
52
+
53
+ Note: Service account keys are a security risk if not managed correctly. You should
54
+ [choose a more secure alternative to service account keys](https://cloud.google.com/docs/authentication#auth-decision-tree)
55
+ whenever possible.
56
+
57
+ To configure a credentials file for an individual client initialization:
58
+
59
+ ```ruby
60
+ require "<%= gem.entrypoint_require %>"
61
+
62
+ client = <%= service.create_client_call %> do |config|
63
+ config.credentials = "path/to/credentialfile.json"
64
+ end
65
+ ```
66
+
67
+ To configure a credentials file globally for all clients:
68
+
69
+ ```ruby
70
+ require "<%= gem.entrypoint_require %>"
71
+
72
+ <%= service.configure_client_call %> do |config|
73
+ config.credentials = "path/to/credentialfile.json"
74
+ end
75
+
76
+ client = <%= service.create_client_call %>
77
+ ```
78
+
79
+ ### Environment Variables
80
+
81
+ You can also use an environment variable to provide a JSON credentials file.
82
+ The environment variable can contain a path to the credentials file or, for
83
+ environments such as Docker containers where writing files is not encouraged,
84
+ you can include the credentials file itself.
85
+
86
+ The JSON file can contain credentials created for
87
+ [workload identity federation](https://cloud.google.com/iam/docs/workload-identity-federation),
88
+ [workforce identity federation](https://cloud.google.com/iam/docs/workforce-identity-federation), or a
89
+ [service account key](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-key).
90
+
91
+ Note: Service account keys are a security risk if not managed correctly. You should
92
+ [choose a more secure alternative to service account keys](https://cloud.google.com/docs/authentication#auth-decision-tree)
93
+ whenever possible.
94
+
95
+ The environment variables that <%= gem.name %>
96
+ checks for credentials are:
97
+
98
+ * `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
99
+ * `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
100
+
101
+ ```ruby
102
+ require "<%= gem.entrypoint_require %>"
103
+
104
+ ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/credentialfile.json"
105
+
106
+ client = <%= service.create_client_call %>
107
+ ```
108
+
109
+ ### Local ADC file
110
+
111
+ You can set up a local ADC file with your user credentials for authentication during
112
+ development. If credentials are not provided in code or in environment variables,
113
+ then the local ADC credentials are discovered.
114
+
115
+ Follow the steps in [Quickstart](#quickstart) to set up a local ADC file.
116
+
117
+ ### Google Cloud Platform environments
118
+
119
+ When running on Google Cloud Platform (GCP), including Google Compute Engine
120
+ (GCE), Google Kubernetes Engine (GKE), Google App Engine (GAE), Google Cloud
121
+ Functions (GCF) and Cloud Run, credentials are retrieved from the attached
122
+ service account automatically. Code should be written as if already authenticated.
123
+
124
+ For more information, see
125
+ [Set up ADC for Google Cloud services](https://cloud.google.com/docs/authentication/provide-credentials-adc#attached-sa).
@@ -16,40 +16,12 @@ Rake::TestTask.new do |t|
16
16
  t.warning = false
17
17
  end
18
18
 
19
- namespace :test do
20
- desc "Runs tests with coverage."
21
- task :coverage do
22
- require "simplecov"
23
- SimpleCov.start do
24
- command_name "<%= gem.name %>"
25
- track_files "lib/**/*.rb"
26
- add_filter "test/"
27
- end
28
-
29
- Rake::Task[:test].invoke
30
- end
31
- end
32
-
33
19
  desc "Runs the smoke tests."
34
20
  Rake::TestTask.new :smoke_test do |t|
35
21
  t.test_files = FileList["acceptance/**/*smoke_test.rb"]
36
22
  t.warning = false
37
23
  end
38
24
 
39
- namespace :smoke_test do
40
- desc "Runs smoke tests with coverage."
41
- task :coverage do
42
- require "simplecov"
43
- SimpleCov.start do
44
- command_name "<%= gem.name %>"
45
- track_files "lib/**/*.rb"
46
- add_filter "test/"
47
- end
48
-
49
- Rake::Task[:smoke_test].invoke
50
- end
51
- end
52
-
53
25
  # Acceptance tests
54
26
  desc "Run the <%= gem.name %> acceptance tests."
55
27
  task :acceptance, :project, :keyfile do |t, args|
@@ -93,10 +65,6 @@ namespace :acceptance do
93
65
  end
94
66
  end
95
67
 
96
- desc "Run acceptance tests with coverage."
97
- task :coverage do
98
- end
99
-
100
68
  desc "Run acceptance cleanup."
101
69
  task :cleanup do
102
70
  end
@@ -2,7 +2,11 @@
2
2
 
3
3
  <%= gem.summary %>
4
4
 
5
- <%= gem.readme_description %>
5
+ <%- if gem.summary != gem.description %>
6
+ <% gem.readme_description.each do |line| %>
7
+ <%= line %>
8
+ <% end %>
9
+ <%- end %>
6
10
 
7
11
  <%= gem.homepage %>
8
12
 
@@ -65,44 +69,62 @@ See also the [Product Documentation](<%= gem.product_documentation_url %>)
65
69
  for general usage information.
66
70
 
67
71
  <%- end -%>
68
- <%- if gem.show_grpc_logging_docs? -%>
69
- ## Enabling Logging
72
+ <%- if gem.show_logging_docs? -%>
73
+ ## Debug Logging
74
+
75
+ This library comes with opt-in Debug Logging that can help you troubleshoot
76
+ your application's integration with the API. When logging is activated, key
77
+ events such as requests and responses, along with data payloads and metadata
78
+ such as headers and client configuration, are logged to the standard error
79
+ stream.
80
+
81
+ **WARNING:** Client Library Debug Logging includes your data payloads in
82
+ plaintext, which could include sensitive data such as PII for yourself or your
83
+ customers, private keys, or other security data that could be compromising if
84
+ leaked. Always practice good data hygiene with your application logs, and follow
85
+ the principle of least access. Google also recommends that Client Library Debug
86
+ Logging be enabled only temporarily during active debugging, and not used
87
+ permanently in production.
88
+
89
+ To enable logging, set the environment variable `GOOGLE_SDK_RUBY_LOGGING_GEMS`
90
+ to the value `all`. Alternatively, you can set the value to a comma-delimited
91
+ list of client library gem names. This will select the default logging behavior,
92
+ which writes logs to the standard error stream. On a local workstation, this may
93
+ result in logs appearing on the console. When running on a Google Cloud hosting
94
+ service such as [Google Cloud Run](https://cloud.google.com/run), this generally
95
+ results in logs appearing alongside your application logs in the
96
+ [Google Cloud Logging](https://cloud.google.com/logging/) service.
70
97
 
71
- To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
72
- The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as shown below,
73
- or a [`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
74
- that will write logs to [Cloud Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
75
- and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
76
-
77
- Configuring a Ruby stdlib logger:
98
+ <%- service = gem.quick_start_service.usable_service_presenter -%>
99
+ <%- if service -%>
100
+ You can customize logging by modifying the `logger` configuration when
101
+ constructing a client object. For example:
78
102
 
79
103
  ```ruby
104
+ require "<%= gem.entrypoint_require %>"
80
105
  require "logger"
81
106
 
82
- module MyLogger
83
- LOGGER = Logger.new $stderr, level: Logger::WARN
84
- def logger
85
- LOGGER
86
- end
87
- end
88
-
89
- # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
90
- module GRPC
91
- extend MyLogger
107
+ client = <%= service.create_client_call %> do |config|
108
+ config.logger = Logger.new "my-app.log"
92
109
  end
93
110
  ```
94
-
95
111
  <%- end -%>
112
+ <%- end -%>
113
+
114
+ ## Google Cloud Samples
115
+
116
+ To browse ready to use code samples check [Google Cloud Samples](https://cloud.google.com/docs/samples).
117
+
96
118
  ## Supported Ruby Versions
97
119
 
98
- This library is supported on Ruby 2.5+.
120
+ This library is supported on Ruby 3.0+.
99
121
 
100
122
  Google provides official support for Ruby versions that are actively supported
101
123
  by Ruby Core—that is, Ruby versions that are either in normal maintenance or
102
- in security maintenance, and not end of life. Currently, this means Ruby 2.5
103
- and later. Older versions of Ruby _may_ still work, but are unsupported and not
104
- recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
105
- about the Ruby support schedule.
124
+ in security maintenance, and not end of life. Older versions of Ruby _may_
125
+ still work, but are unsupported and not recommended. See
126
+ https://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby
127
+ support schedule.
106
128
  <%- if gem.wrapper_name -%>
107
129
 
108
130
  ## Which client should I use?
@@ -3,11 +3,10 @@
3
3
  <%- if gem.api_id -%>
4
4
  "api_id": "<%= gem.api_id %>",
5
5
  <%- end -%>
6
- <%- if gem.api_shortname -%>
7
- "api_shortname": "<%= gem.api_shortname %>",
8
- <%- end -%>
6
+ "api_shortname": "<%= gem.api_shortname || 'unknown' %>",
9
7
  "client_documentation": "<%= gem.library_documentation_url %>",
10
8
  "distribution_name": "<%= gem.name %>",
9
+ "is_cloud": <%= gem.cloud_product? %>,
11
10
  <%- if gem.issue_tracker_url -%>
12
11
  "issue_tracker": "<%= gem.issue_tracker_url %>",
13
12
  <%- end -%>
@@ -19,7 +18,7 @@
19
18
  <%- if gem.product_documentation_url -%>
20
19
  "product_documentation": "<%= gem.product_documentation_url %>",
21
20
  <%- end -%>
22
- "release_level": "unknown",
21
+ "release_level": "unreleased",
23
22
  "repo": "googleapis/google-cloud-ruby",
24
23
  "requires_billing": <%= !gem.free_tier? %>,
25
24
  <%- gem.generator_args_for_metadata.each do |key, val| -%>
@@ -26,6 +26,9 @@ Metrics/ModuleLength:
26
26
  Enabled: false
27
27
  Metrics/PerceivedComplexity:
28
28
  Enabled: false
29
+ Naming/AccessorMethodName:
30
+ Exclude:
31
+ - "snippets/**/*.rb"
29
32
  Naming/FileName:
30
33
  Exclude:
31
34
  - "lib/<%= gem.name %>.rb"
@@ -0,0 +1,3 @@
1
+ <%- assert_locals method -%>
2
+ rescue ::Gapic::Rest::Error => e
3
+ raise ::Google::Cloud::Error.from_error(e)
@@ -14,35 +14,42 @@ require "google/cloud/config"
14
14
 
15
15
  # Set the default configuration
16
16
  ::Google::Cloud.configure.add_config! :<%= gem.google_cloud_short_name %> do |config|
17
- config.add_field! :endpoint, <%= gem.services.first&.client_endpoint.inspect %>, match: ::String
17
+ config.add_field! :endpoint, nil, match: ::String
18
18
  config.add_field! :credentials, nil, match: [::String, ::Hash, ::Google::Auth::Credentials]
19
19
  config.add_field! :scope, nil, match: [::Array, ::String]
20
20
  config.add_field! :lib_name, nil, match: ::String
21
21
  config.add_field! :lib_version, nil, match: ::String
22
- <%- unless gem.generate_rest_clients? -%>
22
+ <%- if gem.generate_grpc_clients? -%>
23
23
  config.add_field! :interceptors, nil, match: ::Array
24
24
  <%- end -%>
25
25
  config.add_field! :timeout, nil, match: ::Numeric
26
26
  config.add_field! :metadata, nil, match: ::Hash
27
- <%- unless gem.generate_rest_clients? -%>
28
27
  config.add_field! :retry_policy, nil, match: [::Hash, ::Proc]
29
28
  config.add_field! :quota_project, nil, match: ::String
30
- <%- end -%>
29
+ config.add_field! :universe_domain, nil, match: ::String
31
30
  end
32
31
  <%- end -%>
33
32
  <% end %>
34
33
  <%- gem.services.each do |service| -%>
35
- <%- client_class_name_suffix = service.generate_rest_clients? ? "Rest::#{service.client_name}" : service.client_name -%>
36
34
  ##
37
35
  # Create a new client object for <%= service.module_name %>.
38
36
  #
39
37
  # By default, this returns an instance of
40
- # <%= gem.docs_link version: gem.default_version, class_name: "#{service.module_name}::#{client_class_name_suffix}" %>
41
- # for version <%= gem.default_version.capitalize %> of the API.
42
- # However, you can specify specify a different API version by passing it in the
38
+ # <%= gem.docs_link version: gem.default_version, class_name: service.client_suffix_for_default_transport %>
39
+ # for a <%= gem.default_transport_name %> client for version <%= gem.default_version.capitalize %> of the API.
40
+ # However, you can specify a different API version by passing it in the
43
41
  # `version` parameter. If the <%= service.module_name %> service is
44
42
  # supported by that API version, and the corresponding gem is available, the
45
43
  # appropriate versioned client will be returned.
44
+ <%- if service.supports_multiple_transports? -%>
45
+ # You can also specify a different transport by passing `:rest` or `:grpc` in
46
+ # the `transport` parameter.
47
+ <%- end -%>
48
+ #
49
+ # Raises an exception if the currently installed versioned client gem for the
50
+ # given API version does not support the <% if service.supports_multiple_transports? %>given transport of the <% end %><%= service.module_name %> service.
51
+ # You can determine whether the method will succeed by calling
52
+ # {<%= gem.namespace %>.<%= service.factory_method_name %>_available?}.
46
53
  #
47
54
  <%- if service.doc_description -%>
48
55
  # ## About <%= service.module_name %>
@@ -52,17 +59,63 @@ end
52
59
  <%- end -%>
53
60
  # @param version [::String, ::Symbol] The API version to connect to. Optional.
54
61
  # Defaults to `:<%= gem.default_version %>`.
55
- # @return [<%= service.module_name %>::<%= client_class_name_suffix %>] A client object for the specified version.
62
+ <%- if service.supports_multiple_transports? -%>
63
+ # @param transport [:grpc, :rest] The transport to use. Defaults to `<%= gem.default_transport.inspect %>`.
64
+ <%- end -%>
65
+ # @return [::Object] A client object for the specified version.
56
66
  #
57
- def self.<%= service.factory_method_name %> version: :<%= gem.default_version %>, &block
67
+ def self.<%= service.factory_method_name %> version: :<%= gem.default_version %><% if service.supports_multiple_transports? %>, transport: <%= gem.default_transport.inspect %><% end %>, &block
58
68
  require "<%= gem.namespace_require %>/#{version.to_s.downcase}"
59
69
 
60
70
  package_name = <%= gem.namespace %>
61
71
  .constants
62
72
  .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
63
73
  .first
64
- package_module = <%= gem.namespace %>.const_get package_name
65
- package_module.const_get(:<%= service.module_name %>)<% if service.generate_rest_clients? %>.const_get(:Rest)<% end %>.const_get(:Client).new(&block)
74
+ service_module = <%= gem.namespace %>.const_get(package_name).const_get(:<%= service.module_name %>)
75
+ <%- if service.supports_multiple_transports? -%>
76
+ service_module = service_module.const_get(:Rest) if transport == :rest
77
+ service_module.const_get(:Client).new(&block)
78
+ <%- else -%>
79
+ service_module<% if service.generate_rest_clients? %>.const_get(:Rest)<% end %>.const_get(:Client).new(&block)
80
+ <%- end -%>
81
+ end
82
+
83
+ ##
84
+ # Determines whether the <%= service.module_name %> service is supported by the current client.
85
+ # If true, you can retrieve a client object by calling {<%= gem.namespace %>.<%= service.factory_method_name %>}.
86
+ # If false, that method will raise an exception. This could happen if the given
87
+ # API version does not exist or does not support the <%= service.module_name %> service,
88
+ # or if the versioned client gem needs an update to support the <%= service.module_name %> service.
89
+ #
90
+ # @param version [::String, ::Symbol] The API version to connect to. Optional.
91
+ # Defaults to `:<%= gem.default_version %>`.
92
+ <%- if service.supports_multiple_transports? -%>
93
+ # @param transport [:grpc, :rest] The transport to use. Defaults to `<%= gem.default_transport.inspect %>`.
94
+ <%- end -%>
95
+ # @return [boolean] Whether the service is available.
96
+ #
97
+ def self.<%= service.factory_method_name %>_available? version: :<%= gem.default_version %><% if service.supports_multiple_transports? %>, transport: <%= gem.default_transport.inspect %><% end %>
98
+ require "<%= gem.namespace_require %>/#{version.to_s.downcase}"
99
+ package_name = <%= gem.namespace %>
100
+ .constants
101
+ .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
102
+ .first
103
+ return false unless package_name
104
+ service_module = <%= gem.namespace %>.const_get package_name
105
+ return false unless service_module.const_defined? :<%= service.module_name %>
106
+ service_module = service_module.const_get :<%= service.module_name %>
107
+ <%- if service.supports_multiple_transports? -%>
108
+ if transport == :rest
109
+ return false unless service_module.const_defined? :Rest
110
+ service_module = service_module.const_get :Rest
111
+ end
112
+ <%- elsif service.generate_rest_clients? -%>
113
+ return false unless service_module.const_defined? :Rest
114
+ service_module = service_module.const_get :Rest
115
+ <%- end -%>
116
+ service_module.const_defined? :Client
117
+ rescue ::LoadError
118
+ false
66
119
  end
67
120
 
68
121
  <%- end -%>
@@ -79,15 +132,14 @@ end
79
132
  # The library name as recorded in instrumentation and logging.
80
133
  # * `lib_version` (*type:* `String`) -
81
134
  # The library version as recorded in instrumentation and logging.
82
- <%- unless gem.generate_rest_clients? -%>
135
+ <%- if gem.generate_grpc_clients? -%>
83
136
  # * `interceptors` (*type:* `Array<GRPC::ClientInterceptor>`) -
84
137
  # An array of interceptors that are run before calls are executed.
85
138
  <%- end -%>
86
139
  # * `timeout` (*type:* `Numeric`) -
87
140
  # Default timeout in seconds.
88
141
  # * `metadata` (*type:* `Hash{Symbol=>String}`) -
89
- # Additional <% if gem.generate_rest_clients? %>REST<% else %>gRPC<% end %> headers to be sent with the call.
90
- <%- unless gem.generate_rest_clients? -%>
142
+ # Additional headers to be sent with the call.
91
143
  # * `retry_policy` (*type:* `Hash`) -
92
144
  # The retry policy. The value is a hash with the following keys:
93
145
  # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
@@ -95,7 +147,6 @@ end
95
147
  # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
96
148
  # * `:retry_codes` (*type:* `Array<String>`) -
97
149
  # The error codes that should trigger a retry.
98
- <%- end -%>
99
150
  #
100
151
  # @return [::Google::Cloud::Config] The default configuration used by this library
101
152
  #