google_cloud_env_secrets 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cae42f0b4569a668a8cd720672427c63862a2873c3029d811f6ffbe784ca0a5
|
4
|
+
data.tar.gz: fdff6f40d8b416e10e77b8097b23e6c222295d6cc02e90d981c3ad82b2176c36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c48d2996eb230b92c7a48fe5b8610bc1267d1da340237c53e18311506799a7a0e13978c1a8edb1d503e4aefa1badffe2b4ed2cdc3b4ea386a26dc6052ba836e5
|
7
|
+
data.tar.gz: 37de843da13be35009b5371c98403ee1ec8420182160b3ab8f7211e9db8a450a164b915e6c015ec3553b9f9d72b32d847956824a71b677915ae823e6e636fccf
|
data/README.md
CHANGED
@@ -28,7 +28,12 @@ Configure this gem with environment vars:
|
|
28
28
|
| `GOOGLE_APPLICATION_CREDENTIALS` | Manually set path to Google Application Credentials. |
|
29
29
|
| `GOOGLE_PROJECT` | Manually set the Google project. Automatically detected otherwise. |
|
30
30
|
| `GOOGLE_SECRETS_PREFIX` | Only load secrets that start with prefix. |
|
31
|
+
| `GOOGLE_SECRETS_FORCE` | Replace existing ENV vars with secret's value. Default `true`. |
|
31
32
|
|
33
|
+
Google Secrets are available after the [before_configuration hook](https://guides.rubyonrails.org/configuring.html#initialization-events).
|
34
|
+
You can call `GoogleCloudEnvSecrets.load` if you need the ENV secrets sooner than that.
|
35
|
+
|
36
|
+
See [docs](https://www.rubydoc.info/github/mattes/rails_google_cloud_env_secrets/main), too.
|
32
37
|
|
33
38
|
## Required IAM Roles
|
34
39
|
|
@@ -1,14 +1,25 @@
|
|
1
1
|
module GoogleCloudEnvSecrets
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
|
-
initializer "google_cloud_env_secrets.initialize", after: :bootstrap_hook do |app|
|
4
|
-
GoogleCloudEnvSecrets.configure do |config|
|
5
|
-
config.credentials = ENV["GOOGLE_APPLICATION_CREDENTIALS"] || nil
|
6
|
-
config.project = ENV["GOOGLE_PROJECT"] || Google::Cloud.env.project_id
|
7
|
-
config.prefix = ENV["GOOGLE_SECRETS_PREFIX"] || nil
|
8
|
-
end
|
9
3
|
|
10
|
-
|
11
|
-
|
4
|
+
# load Google Secrets during Rails `before_configuration` hook
|
5
|
+
config.before_configuration do
|
6
|
+
GoogleCloudEnvSecrets.load
|
12
7
|
end
|
13
8
|
end
|
9
|
+
|
10
|
+
# load Google Secrets into ENV
|
11
|
+
def self.load
|
12
|
+
GoogleCloudEnvSecrets.configure do |config|
|
13
|
+
config.credentials = ENV["GOOGLE_APPLICATION_CREDENTIALS"] || nil
|
14
|
+
config.project = ENV["GOOGLE_PROJECT"] || Google::Cloud.env.project_id
|
15
|
+
config.prefix = ENV["GOOGLE_SECRETS_PREFIX"] || nil
|
16
|
+
|
17
|
+
if ENV.has_key?("GOOGLE_SECRETS_FORCE")
|
18
|
+
config.force = ENV["GOOGLE_SECRETS_FORCE"]&.to_s&.downcase == "true"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
secrets = GoogleCloudEnvSecrets.all
|
23
|
+
GoogleCloudEnvSecrets.inject_env!(secrets, GoogleCloudEnvSecrets.configuration.force)
|
24
|
+
end
|
14
25
|
end
|
@@ -2,6 +2,11 @@ module GoogleCloudEnvSecrets
|
|
2
2
|
def self.all
|
3
3
|
@secrets = nil unless self.configuration.cache_secrets
|
4
4
|
@secrets ||= begin
|
5
|
+
# Skip if not running on Google Cloud and credentials are not set explicitly
|
6
|
+
if self.configuration.credentials.nil? && Google::Cloud.env.project_id.nil?
|
7
|
+
return {}
|
8
|
+
end
|
9
|
+
|
5
10
|
# Configure and initialize
|
6
11
|
# https://googleapis.dev/ruby/google-cloud-secret_manager/latest/Google/Cloud/SecretManager.html
|
7
12
|
Google::Cloud::SecretManager.configure do |config|
|
@@ -38,17 +43,22 @@ module GoogleCloudEnvSecrets
|
|
38
43
|
|
39
44
|
secrets
|
40
45
|
end
|
41
|
-
|
46
|
+
|
47
|
+
@secrets || {}
|
42
48
|
end
|
43
49
|
|
44
50
|
def self.find(name)
|
45
|
-
self.all
|
46
|
-
@secrets[name.to_s]
|
51
|
+
self.all[name.to_s]
|
47
52
|
end
|
48
53
|
|
49
|
-
def self.inject_env!(secrets = {})
|
54
|
+
def self.inject_env!(secrets = {}, force = true, env = ENV)
|
50
55
|
secrets.each do |name, value|
|
51
|
-
|
56
|
+
name = name.to_s
|
57
|
+
if force
|
58
|
+
env[name] = value
|
59
|
+
else
|
60
|
+
env[name] unless env.has_key?(name)
|
61
|
+
end
|
52
62
|
end
|
53
63
|
end
|
54
64
|
end
|
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: 0.1.
|
4
|
+
version: 0.1.2
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|