figaro_secrets 0.1.4 → 0.1.5

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: f924f84a7974b3b7ed76416272b02ed11aa05d5c5308ed321f6303ca62059bef
4
- data.tar.gz: 23c6e0bd5f4d70f4bf350e8c2e885edb7fa6ca8b30b6f53170ce0dfeaadfde3c
3
+ metadata.gz: 9a0478128bb05c3c03af5f294b6c7b9913ef2f8c4485ca1ea9f453947e62273e
4
+ data.tar.gz: 539d85c1403364e8f187c6dfd8460dfb47e34e1b25f4431059c2782a931234ef
5
5
  SHA512:
6
- metadata.gz: 9d88b7299937274f943e7cb17ccb500edaf02cc3a482cfa449389d9c1a077eecdb5ad0fad689db1812bc993a9192e0d1ec40e961e62c0a4deb0264b3e83cd497
7
- data.tar.gz: 6e685071593bb55f9964a721351a820a1b395f0ed892db5ed9b409a3438036b4f3726980970cdd1d4fe063d83936633b929b60edc7d02e61ca69f7f777f2dc83
6
+ metadata.gz: 18034a3935719b2367f24f076e077c413721d5cee978fba5f9144fd9227e477732b5608e6fea39bb69ed276083818196aa58bfe43512bebcf1722c32e399e9a5
7
+ data.tar.gz: 779e0a97476b88436e415128bdcd95ad17627b5ceb904eae02c88fa6336c59a568e3b8fd40da287ae7ec9480bb4d5a32301bdc812b82f4d60b7f8481012d9beb
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- figaro_secrets (0.1.4)
4
+ figaro_secrets (0.1.5)
5
5
  aws-sdk-secretsmanager
6
6
  figaro
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- aws-eventstream (1.0.2)
12
- aws-partitions (1.151.0)
13
- aws-sdk-core (3.48.4)
11
+ aws-eventstream (1.0.3)
12
+ aws-partitions (1.157.0)
13
+ aws-sdk-core (3.49.0)
14
14
  aws-eventstream (~> 1.0, >= 1.0.2)
15
15
  aws-partitions (~> 1.0)
16
16
  aws-sigv4 (~> 1.1)
data/README.md CHANGED
@@ -18,6 +18,34 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ Currently, `figaro_secrets` only supports AWS Secrets Manager.
22
+
23
+ ### Text secret
24
+
25
+ Format:
26
+ ```
27
+ secretsmanager:{secret_name}
28
+ ```
29
+
30
+ Example:
31
+ ```
32
+ # config/application.yml
33
+ GITHUB_API_TOKEN: "secretsmanager:github_api_token"
34
+ ```
35
+
36
+ ### JSON secret
37
+
38
+ Format:
39
+ ```
40
+ secretsmanager:{secret_name}:{key}
41
+ ```
42
+
43
+ Example:
44
+ ```
45
+ # config/application.yml
46
+ GITHUB_API_TOKEN: "secretsmanager:github:api_token"
47
+ ```
48
+
21
49
  ## Development
22
50
 
23
51
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -8,6 +8,10 @@ module FigaroSecrets
8
8
  Parser.new.parse_secrets(configuration)
9
9
  end
10
10
 
11
+ def self.secrets(configuration)
12
+ @parser ||= Parser.new.secrets(configuration)
13
+ end
14
+
11
15
  def self.log_error(message)
12
16
  Rails.logger&.error(message) || $stderr.puts(message)
13
17
  end
@@ -3,7 +3,19 @@ require "figaro/application"
3
3
  module FigaroSecrets
4
4
  module Hook
5
5
  def configuration
6
- @configuration_with_secrets = FigaroSecrets.parse_secrets(super)
6
+ @figaro_secrets_configuration ||= FigaroSecrets.parse_secrets(figaro_configuration)
7
+ end
8
+
9
+ def secrets
10
+ FigaroSecrets.parse_secrets(unparsed_secrets)
11
+ end
12
+
13
+ def unparsed_secrets
14
+ FigaroSecrets.secrets(figaro_configuration)
15
+ end
16
+
17
+ def figaro_configuration
18
+ global_configuration.merge(environment_configuration)
7
19
  end
8
20
 
9
21
  Figaro::Application.prepend(self)
@@ -3,11 +3,17 @@ module FigaroSecrets
3
3
  SECRET_REGEX = /^secretsmanager:(?<secret>.*)/
4
4
 
5
5
  def parse_secrets(configuration)
6
- configuration.inject({}) do |memo, (key, value)|
6
+ secrets(configuration).inject(configuration) do |memo, (key, value)|
7
7
  memo.merge(key => parse_secret(key, value))
8
8
  end
9
9
  end
10
10
 
11
+ def secrets(configuration)
12
+ configuration.select do |_key, value|
13
+ value =~ SECRET_REGEX
14
+ end
15
+ end
16
+
11
17
  def parse_secret(key, value)
12
18
  return unless FigaroSecrets.enabled?
13
19
 
@@ -0,0 +1,36 @@
1
+ module FigaroSecrets
2
+ module Tasks
3
+ def self.list(environment: self.environment)
4
+ title "Retrieving #{environment} configuration"
5
+ config = Figaro.adapter.new(environment: environment).configuration
6
+ output = []
7
+ config.keys.sort.each do |key|
8
+ output << "#{key}=#{config[key].inspect}"
9
+ end
10
+ puts output
11
+ puts "\n"
12
+ end
13
+
14
+ def self.secrets(environment: self.environment)
15
+ title "Retrieving secrets from #{environment} configuration"
16
+ figaro = Figaro.adapter.new(environment: environment)
17
+ unparsed_secrets = figaro.unparsed_secrets
18
+ secrets = figaro.secrets
19
+
20
+ unparsed_secrets.each do |key, value|
21
+ parsed_value = secrets[key]
22
+ puts key
23
+ puts " #{value} => #{parsed_value.inspect}"
24
+ end
25
+ puts "\n"
26
+ end
27
+
28
+ def self.title(title)
29
+ puts "\n#{title}\n\n"
30
+ end
31
+
32
+ def self.environment
33
+ ENV["RAILS_ENV"] || ENV["APP_ENV"] || "development"
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module FigaroSecrets
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -1,16 +1,13 @@
1
+ require 'figaro_secrets/tasks'
2
+
1
3
  namespace :figaro_secrets do
2
4
  task :list, [:environment] do |t, args|
3
- require "figaro"
4
- environment = args[:environment] || ENV["RAILS_ENV"] || "development"
5
- puts "\n"
6
- puts "Retrieving #{environment} configuration"
7
- puts "\n"
8
- config = Figaro.adapter.new(environment: environment).configuration
9
- output = []
10
- config.keys.sort.each do |key|
11
- output << "#{key} #{config[key].inspect}"
12
- end
13
- system("echo \"#{output.join("\n")}\" | column -t")
14
- puts "\n"
5
+ FigaroSecrets::Tasks.list(**args)
6
+ end
7
+
8
+ task :secrets, [:environment] do |t, args|
9
+ FigaroSecrets::Tasks.secrets(**args)
15
10
  end
16
11
  end
12
+
13
+ task figaro_secrets: "figaro_secrets:list"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figaro_secrets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Kaufman-Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-23 00:00:00.000000000 Z
11
+ date: 2019-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: figaro
@@ -98,6 +98,7 @@ files:
98
98
  - lib/figaro_secrets/hook.rb
99
99
  - lib/figaro_secrets/parser.rb
100
100
  - lib/figaro_secrets/secrets_manager.rb
101
+ - lib/figaro_secrets/tasks.rb
101
102
  - lib/figaro_secrets/version.rb
102
103
  - lib/railtie.rb
103
104
  - lib/tasks/figaro_secrets.rake