secrets_loader 0.1.0 → 0.1.1

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: 66c152a442564426ece6727b486f48dd3faf06da872bbbd2ce535b3359d40bbc
4
- data.tar.gz: ef85681b569a6b9f35d7c29e92265a5482ab89a998f3d14a5e7a4568fb00ea05
3
+ metadata.gz: 22aaca96c675ed6ca13f10aada23394ded63cd3724faef972f713187bfb850a4
4
+ data.tar.gz: 8c1fe854500b268efb1baf8f2d251c95c1944016deef4f9133a8266a6f7180c2
5
5
  SHA512:
6
- metadata.gz: e78030147a1f93c1d53a72b154fd5f162c074ddb20e9d4d5f45ee3bf490a9ad39c02713cb5b84b2a41bbe5f7feda129b218d1268780a1149ab2aac620f291cac
7
- data.tar.gz: fab4dc52e6902dff66fcce744e2e4213faa2f5b094b3bd8ca953b89899bd7f6804817af3bb6233c6a1fb80304e61f6f67f9dbac00eb14e5e37734aef4a855a51
6
+ metadata.gz: 90925e8a9187b9fe3ba034fa483929f8a2addceba019da9c5bccaf6d9ef4d5eba60d15c1fe647cd8b6d3ecbdaa708cf6664a4a8d1ee0e896d1146fcd50198dea
7
+ data.tar.gz: aad01e4ec3245a679c857ce0c4cbbd6ae08da1cdaeecb3df62b34cc8b9fd95d88a0d86b10024c5953d1299a4f6582f43a546d23e2278ee2fc819cee002f5bc00
data/Makefile CHANGED
@@ -5,3 +5,7 @@ test:
5
5
  .PHONY: lint
6
6
  lint:
7
7
  bundle exec rubocop -a
8
+
9
+ .PHONY: release
10
+ release:
11
+ bundle exec rake release
@@ -1,33 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'secrets_loader/version'
4
3
  require 'json'
4
+ require 'secrets_loader/config'
5
+ require 'secrets_loader/version'
5
6
 
6
7
  module SecretsLoader
7
8
  class << self
8
9
  attr_accessor :config
9
10
 
10
11
  def load
11
- return unless enable_secrets_loader?
12
+ return unless enable?
12
13
 
13
- load_secret_values.each do |key, value|
14
- if ENV.has_key?(key)
14
+ secret_values.each do |key, value|
15
+ if ENV.has_key?(key.to_s)
15
16
  warn "WARNING: Skipping key #{key.inspect}. Already set in ENV."
16
17
  else
17
- ENV[key] = value.to_s
18
+ ENV[key.to_s] = value.to_s
18
19
  end
19
20
  end
20
21
  end
21
22
 
22
- def load_secret_values
23
- secrets_manager = config.client
24
- secret_string = secrets_manager.get_secret_value(secret_id: config.secret_id).secret_string
25
- JSON.parse(secret_string)
23
+ private
24
+
25
+ def secret_values
26
+ config.loader.load
26
27
  end
27
28
 
28
- def enable_secrets_loader?
29
- return false if ENV['ENABLE_SECRETS_LOADER'].nil? || ENV['ENABLE_SECRETS_LOADER'].empty?
30
- !(config.secret_id.nil? || config.secret_id.empty?)
29
+ def enable?
30
+ config.loader.enable?
31
31
  end
32
32
  end
33
+
34
+ self.config = SecretsLoader::Config.new
33
35
  end
@@ -4,15 +4,16 @@ require 'aws-sdk-secretsmanager'
4
4
 
5
5
  module SecretsLoader
6
6
  class Config
7
- attr_accessor :secret_id
8
- attr_writer :client
7
+ attr_writer :loader
9
8
 
10
- def initialize
11
- @secret_id = ENV['SECRETS_MANAGER_SECRET_ID']
9
+ def loader
10
+ @loader ||= default_loader
12
11
  end
13
12
 
14
- def client
15
- @client ||= Aws::SecretsManager::Client.new
13
+ private
14
+
15
+ def default_loader
16
+ SecretsLoader::Loader::SecretsManager.new
16
17
  end
17
18
  end
18
19
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SecretsLoader
4
+ module Loader
5
+ class Base
6
+ def enable?
7
+ !(ENV['ENABLE_SECRETS_LOADER'].nil? || ENV['ENABLE_SECRETS_LOADER'].empty?)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'secrets_loader/loader/base'
5
+ require 'aws-sdk-secretsmanager'
6
+
7
+ module SecretsLoader
8
+ module Loader
9
+ class SecretsManager < Base
10
+ attr_accessor :client, :secret_id
11
+
12
+ def initialize(client: Aws::SecretsManager::Client.new, secret_id: ENV['SECRETS_MANAGER_SECRET_ID'])
13
+ @client = client
14
+ @secret_id = secret_id
15
+ end
16
+
17
+ def enable?
18
+ return false unless super
19
+
20
+ !(secret_id.nil? || secret_id.empty?)
21
+ end
22
+
23
+ def load
24
+ secret_string = client.get_secret_value(secret_id: secret_id).secret_string
25
+ JSON.parse(secret_string)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecretsLoader
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secrets_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tzmfreedom
@@ -128,6 +128,8 @@ files:
128
128
  - bin/setup
129
129
  - lib/secrets_loader.rb
130
130
  - lib/secrets_loader/config.rb
131
+ - lib/secrets_loader/loader/base.rb
132
+ - lib/secrets_loader/loader/secrets_manager.rb
131
133
  - lib/secrets_loader/railtie.rb
132
134
  - lib/secrets_loader/version.rb
133
135
  - secrets_loader.gemspec