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 +4 -4
- data/Makefile +4 -0
- data/lib/secrets_loader.rb +14 -12
- data/lib/secrets_loader/config.rb +7 -6
- data/lib/secrets_loader/loader/base.rb +11 -0
- data/lib/secrets_loader/loader/secrets_manager.rb +29 -0
- data/lib/secrets_loader/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22aaca96c675ed6ca13f10aada23394ded63cd3724faef972f713187bfb850a4
|
4
|
+
data.tar.gz: 8c1fe854500b268efb1baf8f2d251c95c1944016deef4f9133a8266a6f7180c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90925e8a9187b9fe3ba034fa483929f8a2addceba019da9c5bccaf6d9ef4d5eba60d15c1fe647cd8b6d3ecbdaa708cf6664a4a8d1ee0e896d1146fcd50198dea
|
7
|
+
data.tar.gz: aad01e4ec3245a679c857ce0c4cbbd6ae08da1cdaeecb3df62b34cc8b9fd95d88a0d86b10024c5953d1299a4f6582f43a546d23e2278ee2fc819cee002f5bc00
|
data/Makefile
CHANGED
data/lib/secrets_loader.rb
CHANGED
@@ -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
|
12
|
+
return unless enable?
|
12
13
|
|
13
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
private
|
24
|
+
|
25
|
+
def secret_values
|
26
|
+
config.loader.load
|
26
27
|
end
|
27
28
|
|
28
|
-
def
|
29
|
-
|
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
|
-
|
8
|
-
attr_writer :client
|
7
|
+
attr_writer :loader
|
9
8
|
|
10
|
-
def
|
11
|
-
@
|
9
|
+
def loader
|
10
|
+
@loader ||= default_loader
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
private
|
14
|
+
|
15
|
+
def default_loader
|
16
|
+
SecretsLoader::Loader::SecretsManager.new
|
16
17
|
end
|
17
18
|
end
|
18
19
|
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
|
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.
|
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
|