google_cloud_env_secrets 0.1.3 → 1.0.0

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: 4ee7773da01382b043a980f90375c8733c9d41b2c1a73ebc8d6c5c1eef11cec1
4
- data.tar.gz: 6f746927ed45e047ac21d1bb84395a1e67b0d94532e4453a33ef3e3fc4f73da9
3
+ metadata.gz: cf3d77b020c1903519351fb8f207f5f10f1d8df9841fd0fef85a48293cc53df5
4
+ data.tar.gz: c076fe09aaeceee9298c32260938179537bd53782cbd3138bcaa9ed56996a2b2
5
5
  SHA512:
6
- metadata.gz: 8e5d309de642723cf494de58304f26cf31d010de89a884409781349ad98ab8f1befa1bdd6cc86096ea95fd4b596568390bae363cbd530281a251fac9069f0760
7
- data.tar.gz: 7bf7c6e95b485544b0b68f83177a3bf466facc2c6b1b82a93f28aedaf7ccd2234eb4d679c3a0cb3e24e1443cd2ade86069d650eae3a57aa86934639a061db417
6
+ metadata.gz: 26dd2b920d1847a9f527226afafdcb35645009da8930dc8d33f71faeceff49ba0816174b896d1dbbacabe434a0abd118c2a47a1fe7dc493bff9c364f8e53eaeb
7
+ data.tar.gz: 92fb6cf48c62971bad44b425166b64ba75a5992b5e41756095bb08c529c7a388df7f6f6625a4cf47ba7841ae3857ab76346975b86c46729614ec441ad1731933
data/README.md CHANGED
@@ -28,7 +28,7 @@ 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
+ | `GOOGLE_SECRETS_OVERLOAD` | Replace existing ENV vars with secret's value. Default `true`. |
32
32
 
33
33
  Google Secrets are available after the [before_configuration hook](https://guides.rubyonrails.org/configuring.html#initialization-events).
34
34
  You can call `GoogleCloudEnvSecrets.load` if you need the ENV secrets sooner than that.
@@ -1,14 +1,16 @@
1
+ require "json"
2
+
1
3
  module GoogleCloudEnvSecrets
2
4
  class Configuration
3
5
  attr_accessor :project
4
6
  attr_accessor :credentials
5
7
  attr_accessor :cache_secrets
6
8
  attr_accessor :prefix
7
- attr_accessor :force
9
+ attr_accessor :overload
8
10
 
9
11
  def initialize
10
12
  @cache_secrets = true
11
- @force = true
13
+ @overload = true
12
14
  end
13
15
  end
14
16
 
@@ -20,4 +22,11 @@ module GoogleCloudEnvSecrets
20
22
  self.configuration ||= Configuration.new
21
23
  yield(configuration)
22
24
  end
25
+
26
+ def self.parse_project_from_credentials(credentials)
27
+ j = JSON.load(File.open(credentials))
28
+ j["project_id"]
29
+ rescue
30
+ nil
31
+ end
23
32
  end
@@ -5,21 +5,25 @@ module GoogleCloudEnvSecrets
5
5
  config.before_configuration do
6
6
  GoogleCloudEnvSecrets.load
7
7
  end
8
+
9
+ rake_tasks do
10
+ load "tasks/google_cloud_env_secrets_tasks.rake"
11
+ end
8
12
  end
9
13
 
10
14
  # load Google Secrets into ENV
11
15
  def self.load
12
16
  GoogleCloudEnvSecrets.configure do |config|
13
17
  config.credentials = ENV["GOOGLE_APPLICATION_CREDENTIALS"] || nil
14
- config.project = ENV["GOOGLE_PROJECT"] || Google::Cloud.env.project_id
18
+ config.project = ENV["GOOGLE_PROJECT"] || GoogleCloudEnvSecrets.parse_project_from_credentials(config.credentials) || Google::Cloud.env.project_id
15
19
  config.prefix = ENV["GOOGLE_SECRETS_PREFIX"] || nil
16
20
 
17
- if ENV.has_key?("GOOGLE_SECRETS_FORCE")
18
- config.force = ENV["GOOGLE_SECRETS_FORCE"]&.to_s&.downcase == "true"
21
+ if ENV.has_key?("GOOGLE_SECRETS_OVERLOAD")
22
+ config.overload = ENV["GOOGLE_SECRETS_OVERLOAD"]&.to_s&.downcase == "true"
19
23
  end
20
24
  end
21
25
 
22
26
  secrets = GoogleCloudEnvSecrets.all
23
- GoogleCloudEnvSecrets.inject_env!(secrets, GoogleCloudEnvSecrets.configuration.force)
27
+ GoogleCloudEnvSecrets.inject_env!(secrets, GoogleCloudEnvSecrets.configuration.overload)
24
28
  end
25
29
  end
@@ -51,10 +51,14 @@ module GoogleCloudEnvSecrets
51
51
  self.all[name.to_s]
52
52
  end
53
53
 
54
- def self.inject_env!(secrets = {}, force = true, env = ENV)
54
+ def self.exists?(name)
55
+ self.all.has_key?(name.to_s)
56
+ end
57
+
58
+ def self.inject_env!(secrets = {}, overload = true, env = ENV)
55
59
  secrets.each do |name, value|
56
60
  name = name.to_s
57
- if force
61
+ if overload
58
62
  env[name] = value
59
63
  else
60
64
  env[name] ||= value
@@ -1,3 +1,3 @@
1
1
  module GoogleCloudEnvSecrets
2
- VERSION = "0.1.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,5 +1,9 @@
1
1
  desc "Fetch Google Cloud Secret"
2
2
  task :google_cloud_secret do
3
- name = ARGV[1]
4
- puts GoogleCloudEnvSecrets.find(name)
3
+ name = ENV["NAME"].strip
4
+
5
+ fail "#{name} not found" unless GoogleCloudEnvSecrets.exists?(name)
6
+
7
+ $stdout.sync = true
8
+ print GoogleCloudEnvSecrets.find(name)
5
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_cloud_env_secrets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Kadenbach