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: cf3d77b020c1903519351fb8f207f5f10f1d8df9841fd0fef85a48293cc53df5
4
- data.tar.gz: c076fe09aaeceee9298c32260938179537bd53782cbd3138bcaa9ed56996a2b2
3
+ metadata.gz: 8ffdb42eb21d616a6cb019876bf789e683d28c64a9e558de253c3c72e0382a9c
4
+ data.tar.gz: 5761a861832c4ebe93b1eab5d93d9dfab3c04cccf378fa8444bebc19867a6c6e
5
5
  SHA512:
6
- metadata.gz: 26dd2b920d1847a9f527226afafdcb35645009da8930dc8d33f71faeceff49ba0816174b896d1dbbacabe434a0abd118c2a47a1fe7dc493bff9c364f8e53eaeb
7
- data.tar.gz: 92fb6cf48c62971bad44b425166b64ba75a5992b5e41756095bb08c529c7a388df7f6f6625a4cf47ba7841ae3857ab76346975b86c46729614ec441ad1731933
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 | Description |
27
- |----------------------------------|--------------------------------------------------------------------|
28
- | `GOOGLE_APPLICATION_CREDENTIALS` | Manually set path to Google Application Credentials. |
29
- | `GOOGLE_PROJECT` | Manually set the Google project. Automatically detected otherwise. |
30
- | `GOOGLE_SECRETS_PREFIX` | Only load secrets that start with prefix. |
31
- | `GOOGLE_SECRETS_OVERLOAD` | Replace existing ENV vars with secret's value. Default `true`. |
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
- j = JSON.load(File.open(credentials))
28
- j["project_id"]
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
- config.credentials = self.configuration.credentials
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.exists?(name)
58
+ def self.exist?(name)
55
59
  self.all.has_key?(name.to_s)
56
60
  end
57
61
 
@@ -1,3 +1,3 @@
1
1
  module GoogleCloudEnvSecrets
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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.exists?(name)
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.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-10 00:00:00.000000000 Z
11
+ date: 2020-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails