gapic-generator-cloud 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,9 +4,12 @@ inherit_gem:
4
4
 
5
5
  AllCops:
6
6
  Exclude:
7
+ - "<%= gem.name %>.gemspec"
7
8
  - "lib/**/*_pb.rb"
8
9
  - "proto_docs/**/*"
9
10
  - "test/**/*"
11
+ - "acceptance/**/*"
12
+ - "Rakefile"
10
13
 
11
14
  Metrics/AbcSize:
12
15
  Exclude:
@@ -1,6 +1,6 @@
1
1
  <%- assert_locals gem -%>
2
2
  --no-private
3
- --title=<%= gem.title %>
3
+ --title=<%= gem.title %> API
4
4
  --exclude _pb\.rb$
5
5
  --markup markdown
6
6
  --markup-provider redcarpet
@@ -0,0 +1,75 @@
1
+ <%- assert_locals gem -%>
2
+ <% @requires = capture do %>
3
+ <%- if gem.needs_dashed_ruby_file? -%>
4
+ require "<%= gem.name %>"
5
+ <%- end -%>
6
+ <% end %>
7
+ <%- gem.services.each do |service| -%>
8
+ ##
9
+ # Create a new client object for <%= service.name %>.
10
+ #
11
+ # By default, this returns an instance of
12
+ # <%= gem.docs_link version: gem.default_version, class_name: "#{service.name}::Client" %>
13
+ # for version <%= gem.default_version.capitalize %> of the API.
14
+ # However, you can specify specify a different API version by passing it in the
15
+ # `version` parameter. If the <%= service.name %> service is
16
+ # supported by that API version, and the corresponding gem is available, the
17
+ # appropriate versioned client will be returned.
18
+ #
19
+ <%- if service.doc_description -%>
20
+ # ## About <%= service.name %>
21
+ #
22
+ <%= indent service.doc_description(disable_xrefs: true), "# " %>
23
+ #
24
+ <%- end -%>
25
+ # @param version [String, Symbol] The API version to connect to. Optional.
26
+ # Defaults to `:<%= gem.default_version %>`.
27
+ # @return [<%= service.name %>::Client] A client object for the specified version.
28
+ #
29
+ def self.<%= service.factory_method_name %> version: :<%= gem.default_version %>, &block
30
+ require "<%= gem.namespace_require %>/#{version.to_s.downcase}"
31
+
32
+ package_name = <%= gem.namespace %>
33
+ .constants
34
+ .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
35
+ .first
36
+ package_module = <%= gem.namespace %>.const_get package_name
37
+ package_module.const_get(:<%= service.name %>).const_get(:Client).new(&block)
38
+ end
39
+
40
+ <%- end -%>
41
+ <%- if gem.google_cloud_short_name -%>
42
+ ##
43
+ # Configure the <%= gem.name %> library.
44
+ #
45
+ # The following configuration parameters are supported:
46
+ #
47
+ # * `credentials` (*type:* `String, Hash, Google::Auth::Credentials`) -
48
+ # The path to the keyfile as a String, the contents of the keyfile as a
49
+ # Hash, or a Google::Auth::Credentials object.
50
+ # * `lib_name` (*type:* `String`) -
51
+ # The library name as recorded in instrumentation and logging.
52
+ # * `lib_version` (*type:* `String`) -
53
+ # The library version as recorded in instrumentation and logging.
54
+ # * `interceptors` (*type:* `Array<GRPC::ClientInterceptor>`) -
55
+ # An array of interceptors that are run before calls are executed.
56
+ # * `timeout` (*type:* `Integer`) -
57
+ # Default timeout in milliseconds.
58
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) -
59
+ # Additional gRPC headers to be sent with the call.
60
+ # * `retry_policy` (*type:* `Hash`) -
61
+ # The retry policy. The value is a hash with the following keys:
62
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
63
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
64
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
65
+ # * `:retry_codes` (*type:* `Array<String>`) -
66
+ # The error codes that should trigger a retry.
67
+ #
68
+ # @return [Google::Cloud::Config] The default configuration used by this library
69
+ #
70
+ def self.configure
71
+ yield Google::Cloud.configure.<%= gem.google_cloud_short_name %> if block_given?
72
+
73
+ Google::Cloud.configure.<%= gem.google_cloud_short_name %>
74
+ end
75
+ <%- end -%>
@@ -0,0 +1,22 @@
1
+ <%- assert_locals gem -%>
2
+ <%= render partial: "shared/header" -%>
3
+
4
+ require "helper"
5
+ require "<%= gem.namespace_require %>"
6
+ require "gapic/common"
7
+ require "gapic/grpc"
8
+
9
+ class <%= gem.namespace %>::ClientConstructionMinitest < Minitest::Test
10
+ <%- gem.services.each do |service| -%>
11
+ def test_<%= service.factory_method_name %>
12
+ Gapic::ServiceStub.stub :new, :stub do
13
+ grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
14
+ client = <%= gem.namespace %>.<%= service.factory_method_name %> do |config|
15
+ config.credentials = grpc_channel
16
+ end
17
+ assert_kind_of <%= gem.namespaced_class "#{service.name}::Client", version: gem.default_version %>, client
18
+ end
19
+ end
20
+
21
+ <%- end -%>
22
+ end
@@ -0,0 +1,22 @@
1
+ <%- assert_locals gem -%>
2
+ <%= render partial: "shared/header" -%>
3
+
4
+ <%- if gem.google_cloud_short_name -%>
5
+ gem "google-cloud-core"
6
+ require "google/cloud" unless defined? Google::Cloud.new
7
+ require "google/cloud/config"
8
+ require "googleauth"
9
+
10
+ # Set the default configuration
11
+ Google::Cloud.configure.add_config! :<%= gem.google_cloud_short_name %> do |config|
12
+ config.add_field! :credentials, nil, match: [String, Hash, Google::Auth::Credentials]
13
+ config.add_field! :lib_name, nil, match: String
14
+ config.add_field! :lib_version, nil, match: String
15
+ config.add_field! :interceptors, nil, match: Array
16
+ config.add_field! :timeout, nil, match: Numeric
17
+ config.add_field! :metadata, nil, match: Hash
18
+ config.add_field! :retry_policy, nil, match: [Hash, Proc]
19
+ end
20
+
21
+ <%- end -%>
22
+ require "<%= gem.version_require %>"
@@ -0,0 +1,17 @@
1
+ <%- assert_locals gem -%>
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
5
+
6
+ gem "google-cloud-core", path: "../google-cloud-core"
7
+ gem "google-cloud-env", path: "../google-cloud-env"
8
+ gem "google-cloud-errors", path: "../google-cloud-errors"
9
+ <%- gem.gem_version_dependencies.each do |name, _requirement| -%>
10
+ gem "<%= name %>", path: "../<%= name %>"
11
+ <%- end -%>
12
+
13
+ gem "rake"
14
+
15
+ # Pin minitest to 5.11.x to avoid warnings emitted by 5.12.
16
+ # See https://github.com/googleapis/google-cloud-ruby/issues/4110
17
+ gem "minitest", "~> 5.11.3"
@@ -0,0 +1,40 @@
1
+ <%- assert_locals gem -%>
2
+ # -*- ruby -*-
3
+ # encoding: utf-8
4
+
5
+ require File.expand_path("lib/<%= gem.version_require %>", __dir__)
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "<%= gem.name %>"
9
+ gem.version = <%= gem.version_name_full %>
10
+
11
+ gem.authors = <%= gem.authors.inspect %>
12
+ gem.email = <%= gem.email.inspect %>
13
+ gem.description = <%= gem.description.inspect %>
14
+ gem.summary = <%= gem.summary.inspect %>
15
+ gem.homepage = <%= gem.homepage.inspect %>
16
+ gem.license = "Apache-2.0"
17
+
18
+ gem.platform = Gem::Platform::RUBY
19
+
20
+ gem.files = `git ls-files -- lib/*`.split("\n") +
21
+ <%= gem.extra_files.inspect %>
22
+ gem.require_paths = ["lib"]
23
+
24
+ gem.required_ruby_version = ">= 2.4"
25
+
26
+ gem.add_dependency "google-cloud-core", "~> 1.5"
27
+ <%- gem.gem_version_dependencies.each do |name, requirement| -%>
28
+ gem.add_dependency "<%= name %>", "~> <%= requirement %>"
29
+ <%- end -%>
30
+
31
+ gem.add_development_dependency "autotest-suffix", "~> 1.1"
32
+ gem.add_development_dependency "google-style", "~> 1.24.0"
33
+ gem.add_development_dependency "minitest", "~> 5.10"
34
+ gem.add_development_dependency "minitest-autotest", "~> 1.0"
35
+ gem.add_development_dependency "minitest-focus", "~> 1.1"
36
+ gem.add_development_dependency "minitest-rg", "~> 5.2"
37
+ gem.add_development_dependency "redcarpet", "~> 3.0"
38
+ gem.add_development_dependency "simplecov", "~> 0.9"
39
+ gem.add_development_dependency "yard", "~> 0.9"
40
+ end
@@ -0,0 +1,5 @@
1
+ <%- assert_locals gem -%>
2
+ <%= render partial: "wrapper_gem/main",
3
+ layout: "layouts/ruby",
4
+ locals: { gem: gem, namespace: gem.namespace }
5
+ %>
@@ -0,0 +1,190 @@
1
+ <%- assert_locals gem -%>
2
+ <%- service = gem.services.first -%>
3
+ <%- assert_locals service -%>
4
+ <%= render partial: "shared/header" -%>
5
+
6
+ require "bundler/setup"
7
+ require "bundler/gem_tasks"
8
+
9
+ require "rubocop/rake_task"
10
+ RuboCop::RakeTask.new
11
+
12
+ require "rake/testtask"
13
+ desc "Run tests."
14
+ Rake::TestTask.new do |t|
15
+ t.libs << "test"
16
+ t.test_files = FileList["test/**/*_test.rb"]
17
+ t.warning = true
18
+ end
19
+
20
+ namespace :test do
21
+ desc "Runs tests with coverage."
22
+ task :coverage do
23
+ require "simplecov"
24
+ SimpleCov.start do
25
+ command_name "<%= gem.name %>"
26
+ track_files "lib/**/*.rb"
27
+ add_filter "test/"
28
+ end
29
+
30
+ Rake::Task[:test].invoke
31
+ end
32
+ end
33
+
34
+ desc "Runs the smoke tests."
35
+ Rake::TestTask.new :smoke_test do |t|
36
+ t.test_files = FileList["acceptance/**/*smoke_test.rb"]
37
+ t.warning = false
38
+ end
39
+
40
+ namespace :smoke_test do
41
+ desc "Runs smoke tests with coverage."
42
+ task :coverage do
43
+ require "simplecov"
44
+ SimpleCov.start do
45
+ command_name "<%= gem.name %>"
46
+ track_files "lib/**/*.rb"
47
+ add_filter "test/"
48
+ end
49
+
50
+ Rake::Task[:smoke_test].invoke
51
+ end
52
+ end
53
+
54
+ # Acceptance tests
55
+ desc "Run the <%= gem.name %> acceptance tests."
56
+ task :acceptance, :project, :keyfile do |t, args|
57
+ project = args[:project]
58
+ project ||=
59
+ ENV["<%= gem.env_prefix %>_TEST_PROJECT"] ||
60
+ ENV["GCLOUD_TEST_PROJECT"]
61
+ keyfile = args[:keyfile]
62
+ keyfile ||=
63
+ ENV["<%= gem.env_prefix %>_TEST_KEYFILE"] ||
64
+ ENV["GCLOUD_TEST_KEYFILE"]
65
+ if keyfile
66
+ keyfile = File.read keyfile
67
+ else
68
+ keyfile ||=
69
+ ENV["<%= gem.env_prefix %>_TEST_KEYFILE_JSON"] ||
70
+ ENV["GCLOUD_TEST_KEYFILE_JSON"]
71
+ end
72
+ if project.nil? || keyfile.nil?
73
+ fail "You must provide a project and keyfile. e.g. rake acceptance[test123, /path/to/keyfile.json] or <%= gem.env_prefix %>_TEST_PROJECT=test123 <%= gem.env_prefix %>_TEST_KEYFILE=/path/to/keyfile.json rake acceptance"
74
+ end
75
+ require "<%= service.credentials_require %>"
76
+ <%= service.credentials_name_full %>.env_vars.each do |path|
77
+ ENV[path] = nil
78
+ end
79
+ ENV["<%= gem.env_prefix %>_PROJECT"] = project
80
+ ENV["<%= gem.env_prefix %>_TEST_PROJECT"] = project
81
+ ENV["<%= gem.env_prefix %>_KEYFILE_JSON"] = keyfile
82
+
83
+ Rake::Task["acceptance:run"].invoke
84
+ end
85
+
86
+ namespace :acceptance do
87
+ task :run do
88
+ if File.directory? "acceptance"
89
+ Rake::Task[:smoke_test].invoke
90
+ else
91
+ puts "The <%= gem.name %> gem has no acceptance tests."
92
+ end
93
+ end
94
+
95
+ desc "Run acceptance tests with coverage."
96
+ task :coverage do
97
+ end
98
+
99
+ desc "Run acceptance cleanup."
100
+ task :cleanup do
101
+ end
102
+ end
103
+
104
+ task :samples do
105
+ Rake::Task["samples:latest"].invoke
106
+ end
107
+
108
+ namespace :samples do
109
+ task :latest do
110
+ if File.directory? "samples"
111
+ Dir.chdir "samples" do
112
+ Bundler.with_clean_env do
113
+ ENV["GOOGLE_CLOUD_SAMPLES_TEST"] = "not_master"
114
+ sh "bundle update"
115
+ sh "bundle exec rake test_master"
116
+ end
117
+ end
118
+ else
119
+ puts "The <%= gem.name %> gem has no samples to test."
120
+ end
121
+ end
122
+
123
+ task :master do
124
+ if File.directory? "samples"
125
+ Dir.chdir "samples" do
126
+ Bundler.with_clean_env do
127
+ ENV["GOOGLE_CLOUD_SAMPLES_TEST"] = "master"
128
+ sh "bundle update"
129
+ sh "bundle exec rake test_master"
130
+ end
131
+ end
132
+ else
133
+ puts "The <%= gem.name %> gem has no samples to test."
134
+ end
135
+ end
136
+ end
137
+
138
+ require "yard"
139
+ require "yard/rake/yardoc_task"
140
+ YARD::Rake::YardocTask.new do |y|
141
+ <%- if gem.yard_strict? -%>
142
+ y.options << "--fail-on-warning"
143
+ <%- end -%>
144
+ end
145
+
146
+ desc "Run yard-doctest example tests."
147
+ task :doctest do
148
+ puts "The <%= gem.name %> gem does not have doctest tests."
149
+ end
150
+
151
+ desc "Run the CI build"
152
+ task :ci do
153
+ header "BUILDING <%= gem.name %>"
154
+ header "<%= gem.name %> rubocop", "*"
155
+ Rake::Task[:rubocop].invoke
156
+ header "<%= gem.name %> yard", "*"
157
+ Rake::Task[:yard].invoke
158
+ header "<%= gem.name %> test", "*"
159
+ Rake::Task[:test].invoke
160
+ end
161
+
162
+ namespace :ci do
163
+ desc "Run the CI build, with smoke tests."
164
+ task :smoke_test do
165
+ Rake::Task[:ci].invoke
166
+ header "<%= gem.name %> smoke_test", "*"
167
+ Rake::Task[:smoke_test].invoke
168
+ end
169
+ desc "Run the CI build, with acceptance tests."
170
+ task :acceptance do
171
+ Rake::Task[:ci].invoke
172
+ header "<%= gem.name %> acceptance", "*"
173
+ Rake::Task[:acceptance].invoke
174
+ end
175
+ task :a do
176
+ # This is a handy shortcut to save typing
177
+ Rake::Task["ci:acceptance"].invoke
178
+ end
179
+ end
180
+
181
+ task default: :test
182
+
183
+ def header str, token = "#"
184
+ line_length = str.length + 8
185
+ puts ""
186
+ puts token * line_length
187
+ puts "#{token * 3} #{str} #{token * 3}"
188
+ puts token * line_length
189
+ puts ""
190
+ end
@@ -0,0 +1,95 @@
1
+ # Ruby Client for the <%= gem.title %> API
2
+
3
+ <%= gem.summary %>
4
+
5
+ <%= gem.description %>
6
+
7
+ Actual client classes for the various versions of this API are defined in
8
+ _versioned_ client gems, with names of the form `<%= gem.name %>-v*`.
9
+ The gem `<%= gem.name %>` is a convenience wrapper library that brings the
10
+ verisoned gems in as dependencies, and provides high-level methods for
11
+ constructing clients.
12
+
13
+ View the [Client Library Documentation](<%= gem.library_documentation_url %>)
14
+ for this library, <%= gem.name %>, to see the convenience methods for
15
+ constructing client objects. Reference documentation for the client objects
16
+ themselves can be found in the client library documentation for the versioned
17
+ client gems:
18
+ <%- last_index = gem.versioned_gems.size - 1 -%>
19
+ <%- gem.versioned_gems.each_with_index do |name, i| -%>
20
+ <%- sep = i == last_index ? "." : "," -%>
21
+ [<%= name %>](https://googleapis.dev/ruby/<%= name %>/latest)<%= sep %>
22
+ <%- end -%>
23
+
24
+ <%- if gem.product_documentation_url -%>
25
+ See also the [Product Documentation](<%= gem.product_documentation_url %>)
26
+ for more usage information.
27
+
28
+ <%- end -%>
29
+ ## Quick Start
30
+
31
+ ```
32
+ $ gem install <%= gem.name %>
33
+ ```
34
+
35
+ In order to use this library, you first need to go through the following steps:
36
+
37
+ 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
38
+ <%- if gem.free_tier? -%>
39
+ 1. This API has a free tier. You may not need to
40
+ [enable billing](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
41
+ to get started.
42
+ <%- else -%>
43
+ 1. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
44
+ <%- end -%>
45
+ <%- if gem.api_id -%>
46
+ 1. [Enable the API.](https://console.cloud.google.com/apis/library/<%= gem.api_id %>.googleapis.com)
47
+ <%- end -%>
48
+ 1. {file:AUTHENTICATION.md Set up authentication.}
49
+
50
+ <%- if gem.migration? %>
51
+ ## Migrating from <%= gem.pre_migration_version %> versions
52
+
53
+ The <%= gem.migration_version %> release of the <%= gem.name %> client is a significant upgrade
54
+ based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-ruby),
55
+ and includes substantial interface changes. Existing code written for earlier
56
+ versions of this library will likely require updates to use this version.
57
+ See the {file:MIGRATING.md MIGRATING.md} document for more information.
58
+
59
+ <%- end -%>
60
+ ## Enabling Logging
61
+
62
+ To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
63
+ The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as shown below,
64
+ or a [`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
65
+ that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
66
+ and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
67
+
68
+ Configuring a Ruby stdlib logger:
69
+
70
+ ```ruby
71
+ require "logger"
72
+
73
+ module MyLogger
74
+ LOGGER = Logger.new $stderr, level: Logger::WARN
75
+ def logger
76
+ LOGGER
77
+ end
78
+ end
79
+
80
+ # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
81
+ module GRPC
82
+ extend MyLogger
83
+ end
84
+ ```
85
+
86
+ ## Supported Ruby Versions
87
+
88
+ This library is supported on Ruby 2.4+.
89
+
90
+ Google provides official support for Ruby versions that are actively supported
91
+ by Ruby Core—that is, Ruby versions that are either in normal maintenance or
92
+ in security maintenance, and not end of life. Currently, this means Ruby 2.4
93
+ and later. Older versions of Ruby _may_ still work, but are unsupported and not
94
+ recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
95
+ about the Ruby support schedule.