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
@@ -1,156 +0,0 @@
1
- <%- assert_locals gem -%>
2
- <%- service = gem.first_non_common_service.usable_service_presenter -%>
3
- <%- assert_locals service -%>
4
- # Authentication
5
-
6
- In general, the <%= gem.name %> library uses
7
- [Service Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
8
- credentials to connect to Google Cloud services. When running within
9
- [Google Cloud Platform environments](#google-cloud-platform-environments) the
10
- credentials will be discovered automatically. When running on other
11
- environments, the Service Account credentials can be specified by providing the
12
- path to the
13
- [JSON keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys)
14
- for the account (or the JSON itself) in
15
- [environment variables](#environment-variables). Additionally, Cloud SDK
16
- credentials can also be discovered automatically, but this is only recommended
17
- during development.
18
-
19
- ## Quickstart
20
-
21
- 1. [Create a service account and credentials](#creating-a-service-account).
22
- 2. Set the [environment variable](#environment-variables).
23
-
24
- ```sh
25
- export <%= gem.cloud_env_prefix %>_CREDENTIALS=path/to/keyfile.json
26
- ```
27
-
28
- 3. Initialize the client.
29
-
30
- ```ruby
31
- require "<%= gem.entrypoint_require %>"
32
-
33
- client = <%= service.create_client_call %>
34
- ```
35
-
36
- ## Credential Lookup
37
-
38
- The <%= gem.name %> library aims to make authentication
39
- as simple as possible, and provides several mechanisms to configure your system
40
- without requiring **Service Account Credentials** directly in code.
41
-
42
- **Credentials** are discovered in the following order:
43
-
44
- 1. Specify credentials in method arguments
45
- 2. Specify credentials in configuration
46
- 3. Discover credentials path in environment variables
47
- 4. Discover credentials JSON in environment variables
48
- 5. Discover credentials file in the Cloud SDK's path
49
- 6. Discover GCP credentials
50
-
51
- ### Google Cloud Platform environments
52
-
53
- When running on Google Cloud Platform (GCP), including Google Compute Engine
54
- (GCE), Google Kubernetes Engine (GKE), Google App Engine (GAE), Google Cloud
55
- Functions (GCF) and Cloud Run, **Credentials** are discovered automatically.
56
- Code should be written as if already authenticated.
57
-
58
- ### Environment Variables
59
-
60
- The **Credentials JSON** can be placed in environment variables instead of
61
- declaring them directly in code. Each service has its own environment variable,
62
- allowing for different service accounts to be used for different services. (See
63
- the READMEs for the individual service gems for details.) The path to the
64
- **Credentials JSON** file can be stored in the environment variable, or the
65
- **Credentials JSON** itself can be stored for environments such as Docker
66
- containers where writing files is difficult or not encouraged.
67
-
68
- The environment variables that <%= gem.name %>
69
- checks for credentials are configured on the service Credentials class (such as
70
- <%= service.credentials_class_xref %>):
71
-
72
- <%- if gem.env_prefix -%>
73
- * `<%= gem.env_prefix %>_CREDENTIALS` - Path to JSON file, or JSON contents
74
- * `<%= gem.env_prefix %>_KEYFILE` - Path to JSON file, or JSON contents
75
- <%- end -%>
76
- * `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
77
- * `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
78
- * `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
79
-
80
- ```ruby
81
- require "<%= gem.entrypoint_require %>"
82
-
83
- ENV["<%= gem.cloud_env_prefix %>_CREDENTIALS"] = "path/to/keyfile.json"
84
-
85
- client = <%= service.create_client_call %>
86
- ```
87
-
88
- ### Configuration
89
-
90
- The path to the **Credentials JSON** file can be configured instead of storing
91
- it in an environment variable. Either on an individual client initialization:
92
-
93
- ```ruby
94
- require "<%= gem.entrypoint_require %>"
95
-
96
- client = <%= service.create_client_call %> do |config|
97
- config.credentials = "path/to/keyfile.json"
98
- end
99
- ```
100
-
101
- Or globally for all clients:
102
-
103
- ```ruby
104
- require "<%= gem.entrypoint_require %>"
105
-
106
- <%= service.configure_client_call %> do |config|
107
- config.credentials = "path/to/keyfile.json"
108
- end
109
-
110
- client = <%= service.create_client_call %>
111
- ```
112
-
113
- ### Cloud SDK
114
-
115
- This option allows for an easy way to authenticate during development. If
116
- credentials are not provided in code or in environment variables, then Cloud SDK
117
- credentials are discovered.
118
-
119
- To configure your system for this, simply:
120
-
121
- 1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
122
- 2. Authenticate using OAuth 2.0 `$ gcloud auth login`
123
- 3. Write code as if already authenticated.
124
-
125
- **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
126
- *should* only be used during development.
127
-
128
- ## Creating a Service Account
129
-
130
- Google Cloud requires **Service Account Credentials** to
131
- connect to the APIs. You will use the **JSON key file** to
132
- connect to most services with <%= gem.name %>.
133
-
134
- If you are not running this client within
135
- [Google Cloud Platform environments](#google-cloud-platform-environments), you
136
- need a Google Developers service account.
137
-
138
- 1. Visit the [Google Cloud Console](https://console.cloud.google.com/project).
139
- 2. Create a new project or click on an existing project.
140
- 3. Activate the menu in the upper left and select **APIs & Services**. From
141
- here, you will enable the APIs that your application requires.
142
-
143
- *Note: You may need to enable billing in order to use these services.*
144
-
145
- 4. Select **Credentials** from the side navigation.
146
-
147
- Find the "Create credentials" drop down near the top of the page, and select
148
- "Service account" to be guided through downloading a new JSON key file.
149
-
150
- If you want to re-use an existing service account, you can easily generate a
151
- new key file. Just select the account you wish to re-use, click the pencil
152
- tool on the right side to edit the service account, select the **Keys** tab,
153
- and then select **Add Key**.
154
-
155
- The key file you download will be used by this library to authenticate API
156
- requests and should be stored in a secure location.
@@ -1,4 +0,0 @@
1
- <%- assert_locals method -%>
2
- rescue ::Faraday::Error => e
3
- gapic_error = ::Gapic::Rest::Error.wrap_faraday_error e
4
- raise ::Google::Cloud::Error.from_error(gapic_error)
@@ -1,29 +0,0 @@
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
- <%- client_class_name_suffix = service.generate_rest_clients? ? "Rest::#{service.client_name}" : service.client_name -%>
12
- def test_<%= service.factory_method_name %>
13
- Gapic::ServiceStub.stub :new, :stub do
14
- <%- if service.generate_rest_clients? -%>
15
- client = <%= gem.namespace %>.<%= service.factory_method_name %> do |config|
16
- config.credentials = :dummy_credentials
17
- end
18
- <%- else -%>
19
- grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
20
- client = <%= gem.namespace %>.<%= service.factory_method_name %> do |config|
21
- config.credentials = grpc_channel
22
- end
23
- <%- end -%>
24
- assert_kind_of <%= gem.namespaced_class "#{service.module_name}::#{client_class_name_suffix}", version: gem.default_version %>, client
25
- end
26
- end
27
-
28
- <%- end -%>
29
- end
@@ -1,8 +0,0 @@
1
- <%- assert_locals gem -%>
2
- source "https://rubygems.org"
3
-
4
- gemspec
5
-
6
- <%- gem.versioned_gems.each do |name| -%>
7
- gem "<%= name %>", path: "../<%= name %>"
8
- <%- end -%>