google_cloud_env_secrets 1.0.0 → 1.0.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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ffdb42eb21d616a6cb019876bf789e683d28c64a9e558de253c3c72e0382a9c
|
4
|
+
data.tar.gz: 5761a861832c4ebe93b1eab5d93d9dfab3c04cccf378fa8444bebc19867a6c6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 988ddf45d7210a08f200070cc6ef8a8416d4f35213f5cf202a6544aed08755bf187bd604f82f884a07e63f20307df35f62b2a3b64cf109fdbba3701886ce19e0
|
7
|
+
data.tar.gz: c4c95a3d190def351086673ad62f9aa6a234b2e609ace0723f5aefa03a25a39930b90fe02f9654e23030ddfdbede34c865ca2bd92ba7df0b24fe94089f5a7b6f
|
data/README.md
CHANGED
@@ -23,12 +23,15 @@ $ gem install google_cloud_env_secrets
|
|
23
23
|
|
24
24
|
Configure this gem with environment vars:
|
25
25
|
|
26
|
-
| Variable
|
27
|
-
|
28
|
-
| `GOOGLE_APPLICATION_CREDENTIALS`
|
29
|
-
| `GOOGLE_PROJECT`
|
30
|
-
| `GOOGLE_SECRETS_PREFIX`
|
31
|
-
| `GOOGLE_SECRETS_OVERLOAD`
|
26
|
+
| Variable | Description |
|
27
|
+
|---------------------------------------|--------------------------------------------------------------------|
|
28
|
+
| `GOOGLE_APPLICATION_CREDENTIALS` | Google Application Credentials, path or data (not base64 encoded). |
|
29
|
+
| `GOOGLE_PROJECT` | Google project |
|
30
|
+
| `GOOGLE_SECRETS_PREFIX` | Only load secrets that start with given prefix. |
|
31
|
+
| `GOOGLE_SECRETS_OVERLOAD` | Replace existing ENV vars with secret's value. Default `true`. |
|
32
|
+
|
33
|
+
The `GOOGLE_APPLICATION_CREDENTIALS` and `GOOGLE_PROJECT` variables are both optional. If not given,
|
34
|
+
we will detect them automatically, if run on Google Cloud.
|
32
35
|
|
33
36
|
Google Secrets are available after the [before_configuration hook](https://guides.rubyonrails.org/configuring.html#initialization-events).
|
34
37
|
You can call `GoogleCloudEnvSecrets.load` if you need the ENV secrets sooner than that.
|
@@ -24,8 +24,13 @@ module GoogleCloudEnvSecrets
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.parse_project_from_credentials(credentials)
|
27
|
-
|
28
|
-
|
27
|
+
if File.exist?(credentials)
|
28
|
+
j = JSON.parse(File.read(credentials))
|
29
|
+
return j["project_id"]
|
30
|
+
else
|
31
|
+
j = JSON.parse(credentials)
|
32
|
+
return j["project_id"]
|
33
|
+
end
|
29
34
|
rescue
|
30
35
|
nil
|
31
36
|
end
|
@@ -10,7 +10,11 @@ module GoogleCloudEnvSecrets
|
|
10
10
|
# Configure and initialize
|
11
11
|
# https://googleapis.dev/ruby/google-cloud-secret_manager/latest/Google/Cloud/SecretManager.html
|
12
12
|
Google::Cloud::SecretManager.configure do |config|
|
13
|
-
|
13
|
+
if File.exist?(self.configuration.credentials)
|
14
|
+
config.credentials = self.configuration.credentials # load by file
|
15
|
+
else
|
16
|
+
config.credentials = JSON.parse(self.configuration.credentials) # load data
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
client = Google::Cloud::SecretManager.secret_manager_service
|
@@ -51,7 +55,7 @@ module GoogleCloudEnvSecrets
|
|
51
55
|
self.all[name.to_s]
|
52
56
|
end
|
53
57
|
|
54
|
-
def self.
|
58
|
+
def self.exist?(name)
|
55
59
|
self.all.has_key?(name.to_s)
|
56
60
|
end
|
57
61
|
|
@@ -2,7 +2,7 @@ desc "Fetch Google Cloud Secret"
|
|
2
2
|
task :google_cloud_secret do
|
3
3
|
name = ENV["NAME"].strip
|
4
4
|
|
5
|
-
fail "#{name} not found" unless GoogleCloudEnvSecrets.
|
5
|
+
fail "#{name} not found" unless GoogleCloudEnvSecrets.exist?(name)
|
6
6
|
|
7
7
|
$stdout.sync = true
|
8
8
|
print GoogleCloudEnvSecrets.find(name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_cloud_env_secrets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Kadenbach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|