figaro_secrets 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 70682fa36df97a38a8249d7f57217d249a85ef1437cf5d006619529f5c9289ad
4
+ data.tar.gz: 5c9ea1a8149680bc5f8c61b2c9aab6e721dd211cd8b6a7626fef18b17160e0aa
5
+ SHA512:
6
+ metadata.gz: deb80b05bce5743d5f5095865e5f7583742ef9d4d38356fa15943340fa30f71102d8567097e8ec8ca6126cdb4d7339c7bdbe082ea898c243c075e3448ba04763
7
+ data.tar.gz: 972c874ea77770ac3546931684f7bbc7560893c1c2cf77d5fa96398be4bd8291779741166871d4007553fbabc10b18d26eb48897e9d4525cd78b8db051f3e964
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ .ruby-version
3
+ pkg
4
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in figaro_secrets.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ figaro_secrets (0.1.0)
5
+ aws-sdk-secretsmanager
6
+ figaro
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aws-eventstream (1.0.2)
12
+ aws-partitions (1.145.0)
13
+ aws-sdk-core (3.48.2)
14
+ aws-eventstream (~> 1.0, >= 1.0.2)
15
+ aws-partitions (~> 1.0)
16
+ aws-sigv4 (~> 1.1)
17
+ jmespath (~> 1.0)
18
+ aws-sdk-secretsmanager (1.24.0)
19
+ aws-sdk-core (~> 3, >= 3.48.2)
20
+ aws-sigv4 (~> 1.1)
21
+ aws-sigv4 (1.1.0)
22
+ aws-eventstream (~> 1.0, >= 1.0.2)
23
+ figaro (1.1.1)
24
+ thor (~> 0.14)
25
+ jmespath (1.4.0)
26
+ minitest (5.11.3)
27
+ rake (10.5.0)
28
+ thor (0.20.3)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler
35
+ figaro_secrets!
36
+ minitest
37
+ rake
38
+
39
+ BUNDLED WITH
40
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Cory Kaufman-Schofield
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Figaro Secrets
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'figaro_secrets'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install figaro_secrets
18
+
19
+ ## Usage
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
24
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
25
+ prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To
28
+ release a new version, update the version number in `version.rb`, and then run
29
+ `bundle exec rake release`, which will create a git tag for the version, push
30
+ git commits and tags, and push the `.gem` file to
31
+ [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/allspiritseve/figaro_secrets.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "figaro_secrets"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require "figaro_secrets/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.authors = ["Cory Kaufman-Schofield"]
8
+ spec.email = ["cory@corykaufman.com"]
9
+ spec.homepage = "https://github.com/allspiritseve/figaro_secrets"
10
+ spec.license = "MIT"
11
+ spec.name = "figaro_secrets"
12
+ spec.summary = "Secrets for Figaro"
13
+ spec.version = FigaroSecrets::VERSION
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "figaro"
20
+ spec.add_dependency "aws-sdk-secretsmanager"
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "minitest"
25
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "figaro_secrets/version"
4
+ require "figaro_secrets/parser"
5
+
6
+ module FigaroSecrets
7
+ def self.parse_secrets(configuration)
8
+ Parser.new.parse_secrets(configuration)
9
+ end
10
+
11
+ def self.log_error(message)
12
+ Rails.logger&.error(message) || $stderr.puts(message)
13
+ end
14
+ end
15
+
16
+ require "figaro_secrets/hook"
@@ -0,0 +1,11 @@
1
+ require "figaro/application"
2
+
3
+ module FigaroSecrets
4
+ module Hook
5
+ def configuration
6
+ @configuration_with_secrets = FigaroSecrets.parse_secrets(super)
7
+ end
8
+
9
+ Figaro::Application.prepend(self)
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require "figaro_secrets/secrets_manager"
2
+
3
+ module FigaroSecrets
4
+ class Parser
5
+ SECRET_REGEX = /^secretsmanager:(?<secret>.*)/
6
+
7
+ def parse_secrets(configuration)
8
+ configuration.inject({}) do |memo, (key, value)|
9
+ memo.merge(key => parse_secret(key, value))
10
+ end
11
+ end
12
+
13
+ def parse_secret(key, value)
14
+ if value =~ SECRET_REGEX
15
+ secrets_manager.get_secret($1)
16
+ else
17
+ value
18
+ end
19
+ end
20
+
21
+ def secrets_manager
22
+ @secrets_manager ||= SecretsManager.new
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require "aws-sdk-secretsmanager"
2
+
3
+ module FigaroSecrets
4
+ class SecretsManager
5
+ def get_secret(secret)
6
+ secret_name, key = secret.split(":")
7
+ response = client.get_secret_value(secret_id: secret_name)
8
+ secret = response.secret_string || Base64.decode64(response.secret_binary)
9
+ parsed_secret = JSON.parse(secret) rescue secret
10
+ if key && parsed_secret.is_a?(Hash)
11
+ parsed_secret[key]
12
+ else
13
+ parsed_secret
14
+ end
15
+ rescue JSON::ParserError => e
16
+ FigaroSecrets.log_error("Could not parse secret: #{e}")
17
+ rescue Aws::Errors::ServiceError => e
18
+ FigaroSecrets.log_error("Could not retrieve secret #{secret.inspect}: #{e}")
19
+ end
20
+
21
+ def client
22
+ @client ||= Aws::SecretsManager::Client.new
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module FigaroSecrets
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ require "figaro_secrets"
4
+
5
+ module FigaroSecrets
6
+ class ParserTest < Minitest::Test
7
+ def test_parse_secrets
8
+ parser = Parser.new
9
+ secrets_manager = Minitest::Mock.new
10
+ secrets_manager.expect(:get_secret, "red", ["color"])
11
+ secrets_manager.expect(:get_secret, "balloon", ["config:type"])
12
+ secrets_manager.expect(:get_secret, nil, ["missing"])
13
+ parser.instance_variable_set(:@secrets_manager, secrets_manager)
14
+
15
+ result = parser.parse_secrets(
16
+ color: "secretsmanager:color",
17
+ type: "secretsmanager:config:type",
18
+ missing: "secretsmanager:missing"
19
+ )
20
+
21
+ assert_equal result, { color: "red", type: "balloon", missing: nil }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class FigaroSecretsTest < Minitest::Test
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::FigaroSecrets::VERSION
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "minitest/autorun"
3
+
4
+ require "figaro"
5
+ require "figaro_secrets"
6
+
7
+ class Rails
8
+ def self.logger
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: figaro_secrets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cory Kaufman-Schofield
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: figaro
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-secretsmanager
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - cory@corykaufman.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - figaro_secrets.gemspec
99
+ - lib/figaro_secrets.rb
100
+ - lib/figaro_secrets/hook.rb
101
+ - lib/figaro_secrets/parser.rb
102
+ - lib/figaro_secrets/secrets_manager.rb
103
+ - lib/figaro_secrets/version.rb
104
+ - test/figaro_secrets/parser_test.rb
105
+ - test/figaro_secrets_test.rb
106
+ - test/test_helper.rb
107
+ homepage: https://github.com/allspiritseve/figaro_secrets
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.0.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Secrets for Figaro
131
+ test_files: []