Skip to content

Commit

Permalink
Merge pull request #49 from vapor-community/env
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Fallet authored Jul 31, 2022
2 parents 0321a5f + 9a4faf7 commit 9e37456
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Datastore/Sources/DatastoreClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ public final class GoogleCloudDatastoreClient {
eventLoop: eventLoop)

/// Set the projectId to use for this client. In order of priority:
/// - Environment Variable (GOOGLE_PROJECT_ID)
/// - Environment Variable (PROJECT_ID)
/// - Service Account's projectID
/// - `GoogleCloudDatastoreConfigurations` `project` property (optionally configured).
/// - `GoogleCloudCredentialsConfiguration's` `project` property (optionally configured).

guard let projectId = ProcessInfo.processInfo.environment["PROJECT_ID"] ??
guard let projectId = ProcessInfo.processInfo.environment["GOOGLE_PROJECT_ID"] ??
ProcessInfo.processInfo.environment["PROJECT_ID"] ??
(refreshableToken as? OAuthServiceAccount)?.credentials.projectId ??
config.project ?? credentials.project else {
throw GoogleCloudDatastoreError.projectIdMissing
Expand Down
1 change: 1 addition & 0 deletions Datastore/Sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let gcs = try GoogleCloudDatastoreClient(credentials: credentialsConfiguration,

```
The order of priority for which configured projectID the DatastoreClient will use is as follows:
1. `$GOOGLE_PROJECT_ID` environment variable.
1. `$PROJECT_ID` environment variable.
2. The Service Accounts projectID (Service account configured via the credentials path in the credentials configuration).
3. `GoogleCloudDatastoreConfiguration`'s `project` property.
Expand Down
3 changes: 2 additions & 1 deletion PubSub/Sources/PubSubClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public final class GoogleCloudPubSubClient {
withConfig: config,
andClient: httpClient,
eventLoop: eventLoop)
guard let projectId = ProcessInfo.processInfo.environment["PROJECT_ID"] ??
guard let projectId = ProcessInfo.processInfo.environment["GOOGLE_PROJECT_ID"] ??
ProcessInfo.processInfo.environment["PROJECT_ID"] ??
(refreshableToken as? OAuthServiceAccount)?.credentials.projectId ??
config.project ?? credentials.project else {
throw GoogleCloudPubSubError.projectIdMissing
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Now setup the configuration.
Optionally, you can register an empty `GoogleCloudCredentialsConfiguration()` and configure the following environment variables:

```shell
export PROJECT_ID=myprojectid-12345
export GOOGLE_PROJECT_ID=myprojectid-12345
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/service-account.json
```

Expand Down
1 change: 1 addition & 0 deletions SecretManager/Sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let smc = try GoogleCloudSecretManagerClient(credentials: credentialsConfigurati

```
The order of priority for which configured projectID the SecretManagerClient will use is as follows:
1. `$GOOGLE_PROJECT_ID` environment variable.
1. `$PROJECT_ID` environment variable.
2. The Service Accounts projectID (Service account configured via the credentials path in the credentials configuration).
3. `GoogleCloudSecretManagerConfiguration`'s `project` property.
Expand Down
4 changes: 3 additions & 1 deletion SecretManager/Sources/SecretManagerClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ public final class GoogleCloudSecretManagerClient {
eventLoop: eventLoop)

/// Set the projectId to use for this client. In order of priority:
/// - Environment Variable (GOOGLE_PROJECT_ID)
/// - Environment Variable (PROJECT_ID)
/// - Service Account's projectID
/// - `GoogleCloudSecretManagerConfigurations` `project` property (optionally configured).
/// - `GoogleCloudCredentialsConfiguration's` `project` property (optionally configured).

guard let projectId = ProcessInfo.processInfo.environment["PROJECT_ID"] ??
guard let projectId = ProcessInfo.processInfo.environment["GOOGLE_PROJECT_ID"] ??
ProcessInfo.processInfo.environment["PROJECT_ID"] ??
(refreshableToken as? OAuthServiceAccount)?.credentials.projectId ??
config.project ?? credentials.project else {
throw GoogleCloudSecretManagerError.projectIdMissing
Expand Down
1 change: 1 addition & 0 deletions Storage/Sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let gcs = try GoogleCloudStorageClient(credentials: credentialsConfiguration,

```
The order of priority for which configured projectID the StorageClient will use is as follows:
1. `$GOOGLE_PROJECT_ID` environment variable.
1. `$PROJECT_ID` environment variable.
2. The Service Accounts projectID (Service account configured via the credentials path in the credentials configuration).
3. `GoogleCloudStorageConfiguration`'s `project` property.
Expand Down
4 changes: 3 additions & 1 deletion Storage/Sources/StorageClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public final class GoogleCloudStorageClient {
eventLoop: eventLoop)

/// Set the projectId to use for this client. In order of priority:
/// - Environment Variable (GOOGLE_PROJECT_ID)
/// - Environment Variable (PROJECT_ID)
/// - Service Account's projectID
/// - `GoogleCloudStorageConfigurations` `project` property (optionally configured).
/// - `GoogleCloudCredentialsConfiguration's` `project` property (optionally configured).

guard let projectId = ProcessInfo.processInfo.environment["PROJECT_ID"] ??
guard let projectId = ProcessInfo.processInfo.environment["GOOGLE_PROJECT_ID"] ??
ProcessInfo.processInfo.environment["PROJECT_ID"] ??
(refreshableToken as? OAuthServiceAccount)?.credentials.projectId ??
storageConfig.project ?? credentials.project else {
throw GoogleCloudStorageError.projectIdMissing
Expand Down
1 change: 1 addition & 0 deletions Translation/Sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let gct = try GoogleCloudTranslationClient(credentials: credentialsConfiguration

```
The order of priority for which configured projectID the TranslationClient will use is as follows:
1. `$GOOGLE_PROJECT_ID` environment variable.
1. `$PROJECT_ID` environment variable.
2. The Service Accounts projectID (Service account configured via the credentials path in the credentials configuration).
3. `GoogleCloudTranslationConfiguration`'s `project` property.
Expand Down
4 changes: 3 additions & 1 deletion Translation/Sources/TranslationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ public final class GoogleCloudTranslationClient {
eventLoop: eventLoop)

/// Set the projectId to use for this client. In order of priority:
/// - Environment Variable (GOOGLE_PROJECT_ID)
/// - Environment Variable (PROJECT_ID)
/// - Service Account's projectID
/// - `GoogleCloudTranslationConfigurations` `project` property (optionally configured).
/// - `GoogleCloudCredentialsConfiguration's` `project` property (optionally configured).

guard let projectId = ProcessInfo.processInfo.environment["PROJECT_ID"] ??
guard let projectId = ProcessInfo.processInfo.environment["GOOGLE_PROJECT_ID"] ??
ProcessInfo.processInfo.environment["PROJECT_ID"] ??
(refreshableToken as? OAuthServiceAccount)?.credentials.projectId ??
config.project ?? credentials.project else {
throw GoogleCloudTranslationError.projectIdMissing
Expand Down

0 comments on commit 9e37456

Please sign in to comment.