Skip to content

Commit 065f079

Browse files
feat(access-approval): initial synth of the access-approval wrapper (#5115)
* feat: synth of access-aprroval wrapper
1 parent b1fb4cf commit 065f079

20 files changed

+1087
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ gem "actionpack", "~> 5.0"
1919
gem "railties", "~> 5.0"
2020
gem "rack", ">= 0.1"
2121

22+
gem "google-cloud-access_approval", path: "google-cloud-access_approval"
2223
gem "google-cloud-access_approval-v1", path: "google-cloud-access_approval-v1"
2324
gem "google-cloud-core", path: "google-cloud-core"
2425
gem "google-cloud-env", path: "google-cloud-env"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Ignore bundler lockfiles
2+
Gemfile.lock
3+
gems.locked
4+
5+
# Ignore documentation output
6+
doc/*
7+
.yardoc/*
8+
9+
# Ignore test output
10+
coverage/*
11+
12+
# Ignore build artifacts
13+
pkg/*
14+
15+
# Ignore files commonly present in certain dev environments
16+
.vagrant
17+
.DS_STORE
18+
.idea
19+
*.iml
20+
21+
# Ignore synth output
22+
__pycache__
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"language": "ruby",
3+
"distribution_name": "google-cloud-access_approval",
4+
"client_documentation": "https://googleapis.dev/ruby/google-cloud-access_approval/latest"
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
inherit_gem:
2+
google-style: google-style.yml
3+
4+
AllCops:
5+
Exclude:
6+
- "google-cloud-access_approval.gemspec"
7+
- "Rakefile"
8+
- "acceptance/**/*"
9+
- "test/**/*"
10+
11+
Bundler/OrderedGems:
12+
Enabled: false
13+
Documentation:
14+
Enabled: false
15+
16+
Metrics/BlockLength:
17+
Exclude:
18+
- "samples/acceptance/*.rb"
19+
20+
Naming/FileName:
21+
Exclude:
22+
- "lib/google-cloud-access_approval.rb"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--no-private
2+
--title=Access Approval API
3+
--exclude _pb\.rb$
4+
--markup markdown
5+
--markup-provider redcarpet
6+
7+
./lib/**/*.rb
8+
-
9+
README.md
10+
AUTHENTICATION.md
11+
LICENSE.md
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Authentication
2+
3+
In general, the google-cloud-access_approval library uses
4+
[Service Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
5+
credentials to connect to Google Cloud services. When running within
6+
[Google Cloud Platform environments](#google-cloud-platform-environments) the
7+
credentials will be discovered automatically. When running on other
8+
environments, the Service Account credentials can be specified by providing the
9+
path to the
10+
[JSON keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys)
11+
for the account (or the JSON itself) in
12+
[environment variables](#environment-variables). Additionally, Cloud SDK
13+
credentials can also be discovered automatically, but this is only recommended
14+
during development.
15+
16+
## Quickstart
17+
18+
1. [Create a service account and credentials](#creating-a-service-account).
19+
2. Set the [environment variable](#environment-variables).
20+
21+
```sh
22+
export ACCESS_APPROVAL_CREDENTIALS=path/to/keyfile.json
23+
```
24+
25+
3. Initialize the client.
26+
27+
```ruby
28+
require "google/cloud/access_approval"
29+
30+
client = Google::Cloud::AccessApproval.access_approval
31+
```
32+
33+
## Credential Lookup
34+
35+
The google-cloud-access_approval library aims to make authentication
36+
as simple as possible, and provides several mechanisms to configure your system
37+
without requiring **Service Account Credentials** directly in code.
38+
39+
**Credentials** are discovered in the following order:
40+
41+
1. Specify credentials in method arguments
42+
2. Specify credentials in configuration
43+
3. Discover credentials path in environment variables
44+
4. Discover credentials JSON in environment variables
45+
5. Discover credentials file in the Cloud SDK's path
46+
6. Discover GCP credentials
47+
48+
### Google Cloud Platform environments
49+
50+
When running on Google Cloud Platform (GCP), including Google Compute Engine
51+
(GCE), Google Kubernetes Engine (GKE), Google App Engine (GAE), Google Cloud
52+
Functions (GCF) and Cloud Run, **Credentials** are discovered automatically.
53+
Code should be written as if already authenticated.
54+
55+
### Environment Variables
56+
57+
The **Credentials JSON** can be placed in environment variables instead of
58+
declaring them directly in code. Each service has its own environment variable,
59+
allowing for different service accounts to be used for different services. (See
60+
the READMEs for the individual service gems for details.) The path to the
61+
**Credentials JSON** file can be stored in the environment variable, or the
62+
**Credentials JSON** itself can be stored for environments such as Docker
63+
containers where writing files is difficult or not encouraged.
64+
65+
The environment variables that google-cloud-access_approval
66+
checks for credentials are configured on the service Credentials class (such as
67+
`Google::Cloud::AccessApproval::V1::AccessApproval::Credentials`):
68+
69+
1. `ACCESS_APPROVAL_CREDENTIALS` - Path to JSON file, or JSON contents
70+
2. `ACCESS_APPROVAL_KEYFILE` - Path to JSON file, or JSON contents
71+
3. `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
72+
4. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
73+
5. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
74+
75+
```ruby
76+
require "google/cloud/access_approval"
77+
78+
ENV["ACCESS_APPROVAL_CREDENTIALS"] = "path/to/keyfile.json"
79+
80+
client = Google::Cloud::AccessApproval.access_approval
81+
```
82+
83+
### Configuration
84+
85+
The **Credentials JSON** can be configured instead of placing them in
86+
environment variables. Either on an individual client initialization:
87+
88+
```ruby
89+
require "google/cloud/access_approval"
90+
91+
client = Google::Cloud::AccessApproval.access_approval do |config|
92+
config.credentials = "path/to/keyfile.json"
93+
end
94+
```
95+
96+
Or configured globally for all clients:
97+
98+
```ruby
99+
require "google/cloud/access_approval"
100+
101+
Google::Cloud::AccessApproval.configure do |config|
102+
config.credentials = "path/to/keyfile.json"
103+
end
104+
105+
client = Google::Cloud::AccessApproval.access_approval
106+
```
107+
108+
### Cloud SDK
109+
110+
This option allows for an easy way to authenticate during development. If
111+
credentials are not provided in code or in environment variables, then Cloud SDK
112+
credentials are discovered.
113+
114+
To configure your system for this, simply:
115+
116+
1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
117+
2. Authenticate using OAuth 2.0 `$ gcloud auth login`
118+
3. Write code as if already authenticated.
119+
120+
**NOTE:** This is _not_ recommended for running in production. The Cloud SDK
121+
*should* only be used during development.
122+
123+
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
124+
[dev-console]: https://console.cloud.google.com/project
125+
126+
[enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
127+
128+
[create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
129+
[create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
130+
[reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
131+
132+
## Creating a Service Account
133+
134+
Google Cloud requires **Service Account Credentials** to
135+
connect to the APIs. You will use the **JSON key file** to
136+
connect to most services with google-cloud-access_approval.
137+
138+
If you are not running this client within
139+
[Google Cloud Platform environments](#google-cloud-platform-environments), you
140+
need a Google Developers service account.
141+
142+
1. Visit the [Google Developers Console][dev-console].
143+
2. Create a new project or click on an existing project.
144+
3. Activate the slide-out navigation tray and select **API Manager**. From
145+
here, you will enable the APIs that your application requires.
146+
147+
![Enable the APIs that your application requires][enable-apis]
148+
149+
*Note: You may need to enable billing in order to use these services.*
150+
151+
4. Select **Credentials** from the side navigation.
152+
153+
You should see a screen like one of the following.
154+
155+
![Create a new service account][create-new-service-account]
156+
157+
![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
158+
159+
Find the "Add credentials" drop down and select "Service account" to be
160+
guided through downloading a new JSON key file.
161+
162+
If you want to re-use an existing service account, you can easily generate a
163+
new key file. Just select the account you wish to re-use, and click "Generate
164+
new JSON key":
165+
166+
![Re-use an existing service account][reuse-service-account]
167+
168+
The key file you download will be used by this library to authenticate API
169+
requests and should be stored in a secure location.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Release History
2+

google-cloud-access_approval/Gemfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source "https://rubygems.org"
2+
3+
gemspec
4+
5+
gem "google-cloud-core", path: "../google-cloud-core"
6+
gem "google-cloud-env", path: "../google-cloud-env"
7+
gem "google-cloud-errors", path: "../google-cloud-errors"
8+
gem "google-cloud-access_approval-v1", path: "../google-cloud-access_approval-v1"
9+
10+
gem "rake"
11+
12+
# Pin minitest to 5.11.x to avoid warnings emitted by 5.12.
13+
# See https://github.com/googleapis/google-cloud-ruby/issues/4110
14+
gem "minitest", "~> 5.11.3"

0 commit comments

Comments
 (0)