Skip to content

Commit

Permalink
feat(language)!: use clients created by the new generator
Browse files Browse the repository at this point in the history
Release-As: 1.0.0
  • Loading branch information
dazuma authored Mar 14, 2020
1 parent 6a670c4 commit bf63982
Show file tree
Hide file tree
Showing 34 changed files with 464 additions and 5,955 deletions.
23 changes: 16 additions & 7 deletions google-cloud-language/.gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Ignore bundler lockfiles
Gemfile.lock
coverage/*
gems.locked

# Ignore documentation output
doc/*
pkg/*
html/*
jsondoc/*
.yardoc/*

# Ignore YARD stuffs
.yardoc
# Ignore test output
coverage/*

# IDE settings
# Ignore build artifacts
pkg/*

# Ignore files commonly present in certain dev environments
.vagrant
.DS_STORE
.idea
*.iml

# Ignore synth output
__pycache__
3 changes: 0 additions & 3 deletions google-cloud-language/.repo-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
"name": "language",
"language": "ruby",
"distribution_name": "google-cloud-language",
"module_name": "Language",
"module_name_credentials": "Language::V1",
"env_var_prefix": "LANGUAGE",
"client_documentation": "https://googleapis.dev/ruby/google-cloud-language/latest"
}
9 changes: 5 additions & 4 deletions google-cloud-language/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ inherit_gem:

AllCops:
Exclude:
- "google-cloud-language.gemspec"
- "lib/google/**/*"
- "Rakefile"
- "test/**/*"
- "acceptance/**/*"
- "Rakefile"

Documentation:
Enabled: false

Naming/FileName:
Exclude:
- lib/google-cloud-language.rb
1 change: 1 addition & 0 deletions google-cloud-language/.yardopts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
-
README.md
AUTHENTICATION.md
MIGRATING.md
LICENSE
102 changes: 47 additions & 55 deletions google-cloud-language/AUTHENTICATION.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Authentication

In general, the google-cloud-language library uses [Service
Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
credentials to connect to Google Cloud services. When running within [Google
Cloud Platform environments](#google-cloud-platform-environments)
In general, the google-cloud-language library uses
[Service Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
credentials to connect to Google Cloud services. When running within
[Google Cloud Platform environments](#google-cloud-platform-environments)
the credentials will be discovered automatically. When running on other
environments, the Service Account credentials can be specified by providing the
path to the [JSON
keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys) for
the account (or the JSON itself) in [environment
variables](#environment-variables). Additionally, Cloud SDK credentials can also
be discovered automatically, but this is only recommended during development.
path to the
[JSON keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys)
for the account (or the JSON itself) in
[environment variables](#environment-variables).
Additionally, Cloud SDK credentials can also be discovered automatically, but
this is only recommended during development.

## Quickstart

Expand All @@ -26,23 +27,14 @@ export LANGUAGE_CREDENTIALS=/path/to/json`
```ruby
require "google/cloud/language"
client = Google::Cloud::Language.new
client = Google::Cloud::Language.language_service
```

## Project and Credential Lookup

The google-cloud-language library aims to make authentication
as simple as possible, and provides several mechanisms to configure your system
without providing **Project ID** and **Service Account Credentials** directly in
code.

**Project ID** is discovered in the following order:

1. Specify project ID in method arguments
2. Specify project ID in configuration
3. Discover project ID in environment variables
4. Discover GCP project ID
5. Discover project ID in credentials JSON
without providing **Service Account Credentials** directly in code.

**Credentials** are discovered in the following order:

Expand All @@ -57,26 +49,21 @@ code.
When running on Google Cloud Platform (GCP), including Google Compute Engine (GCE),
Google Kubernetes Engine (GKE), Google App Engine (GAE), Google Cloud Functions
(GCF) and Cloud Run, the **Project ID** and **Credentials** and are discovered
automatically. Code should be written as if already authenticated.
(GCF) and Cloud Run, the **Credentials** and are discovered automatically. Code
should be written as if already authenticated.
### Environment Variables
The **Project ID** and **Credentials JSON** can be placed in environment
variables instead of declaring them directly in code. Each service has its own
environment variable, allowing for different service accounts to be used for
different services. (See the READMEs for the individual service gems for
details.) The path to the **Credentials JSON** file can be stored in the
environment variable, or the **Credentials JSON** itself can be stored for
environments such as Docker containers where writing files is difficult or not
encouraged.
The environment variables that google-cloud-language checks for project ID are:
1. `LANGUAGE_PROJECT`
2. `GOOGLE_CLOUD_PROJECT`
The **Credentials JSON** can be placed in environment variables instead of
declaring them directly in code. Each service has its own environment variable,
allowing for different service accounts to be used for different services.
(See the READMEs for the individual service gems for details.) The path to the
**Credentials JSON** file can be stored in the environment variable, or the
**Credentials JSON** itself can be stored for environments such as Docker
containers where writing files is difficult or not encouraged.
The environment variables that google-cloud-language checks for credentials are configured on {Google::Cloud::Language::V1::Credentials}:
The environment variables that google-cloud-language checks for credentials are
configured on the service Credentials class.
1. `LANGUAGE_CREDENTIALS` - Path to JSON file, or JSON contents
2. `LANGUAGE_KEYFILE` - Path to JSON file, or JSON contents
Expand All @@ -87,25 +74,35 @@ The environment variables that google-cloud-language checks for credentials are
```ruby
require "google/cloud/language"
ENV["LANGUAGE_PROJECT"] = "my-project-id"
ENV["LANGUAGE_CREDENTIALS"] = "path/to/keyfile.json"
client = Google::Cloud::Language.new
client = Google::Cloud::Language.language_service
```
### Configuration
The **Project ID** and **Credentials JSON** can be configured instead of placing them in environment variables or providing them as arguments.
The **Credentials JSON** can be configured instead of placing them in
environment variables or providing them as arguments. You can set credentials
on individual client initialization:
```ruby
require "google/cloud/language"
client = Google::Cloud::Language.language_service do |config|
config.credentials = "path/to/keyfile.json"
end
```
Or globally for all clients:
```ruby
require "google/cloud/language"
Google::Cloud::Language.configure do |config|
config.project_id = "my-project-id"
config.credentials = "path/to/keyfile.json"
end
client = Google::Cloud::Language.new
client = Google::Cloud::Language.language_service
```
### Cloud SDK
Expand Down Expand Up @@ -134,24 +131,24 @@ To configure your system for this, simply:
## Creating a Service Account
Google Cloud requires a **Project ID** and **Service Account Credentials** to
connect to the APIs. You will use the **Project ID** and **JSON key file** to
connect to most services with google-cloud-language.
Google Cloud requires **Service Account Credentials** to connect to the APIs.
You will use the **JSON key file** to connect to most services with
google-cloud-language.
If you are not running this client within [Google Cloud Platform
environments](#google-cloud-platform-environments), you need a Google
Developers service account.
If you are not running this client within
[Google Cloud Platform environments](#google-cloud-platform-environments),
you need a Google Developers service account.
1. Visit the [Google Developers Console][dev-console].
1. Create a new project or click on an existing project.
1. Activate the slide-out navigation tray and select **API Manager**. From
2. Create a new project or click on an existing project.
3. Activate the slide-out navigation tray and select **API Manager**. From
here, you will enable the APIs that your application requires.
![Enable the APIs that your application requires][enable-apis]
*Note: You may need to enable billing in order to use these services.*
1. Select **Credentials** from the side navigation.
4. Select **Credentials** from the side navigation.
You should see a screen like one of the following.
Expand All @@ -170,8 +167,3 @@ Developers service account.
The key file you download will be used by this library to authenticate API
requests and should be stored in a secure location.
## Troubleshooting
If you're having trouble authenticating you can ask for help by following the
{file:TROUBLESHOOTING.md Troubleshooting Guide}.
6 changes: 6 additions & 0 deletions google-cloud-language/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ source "https://rubygems.org"

gemspec

gem "google-cloud-core", path: "../google-cloud-core"
gem "google-cloud-env", path: "../google-cloud-env"
gem "google-cloud-errors", path: "../google-cloud-errors"
gem "google-cloud-language-v1", path: "../google-cloud-language-v1"
gem "google-cloud-language-v1beta2", path: "../google-cloud-language-v1beta2"

gem "rake"

# Pin minitest to 5.11.x to avoid warnings emitted by 5.12.
Expand Down
Loading

0 comments on commit bf63982

Please sign in to comment.