hekate 0.1.0.pre2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58c21dd8015a2aefbf6f460ff6bc600e7432a272
4
+ data.tar.gz: 3f51922fdbb0a536052f00c1d29234a20099565e
5
+ SHA512:
6
+ metadata.gz: 3ef8ef172ccf94ba6b5fbfabc36ea770cfe5df502f307833fcdb780fb9fe50b28ad31a9e06158eef0e7d128e435ef2be4893189c48ebf46817ae6e5948aa3fb9
7
+ data.tar.gz: ff9d412530a6a08d26ab9c5dbcf64ced7661d69037aac55e273cc54eab5472ecce1c55fd59dbea9851f33715298f4dbedcce2c8ce26e5b531dd5d413795f1dbb
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+
2
+ # rspec failure tracking
3
+ .rspec_status
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jason@cardtapp.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hekate.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,143 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hekate (0.1.0.pre)
5
+ aws-sdk (~> 2.9, >= 2.9.0)
6
+ commander (~> 4.4, >= 4.4.0)
7
+ ec2-metadata (~> 0.2, >= 0.2.0)
8
+ rails (~> 4)
9
+ railties (~> 4.2, >= 4.2.0)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actionmailer (4.2.8)
15
+ actionpack (= 4.2.8)
16
+ actionview (= 4.2.8)
17
+ activejob (= 4.2.8)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 1.0, >= 1.0.5)
20
+ actionpack (4.2.8)
21
+ actionview (= 4.2.8)
22
+ activesupport (= 4.2.8)
23
+ rack (~> 1.6)
24
+ rack-test (~> 0.6.2)
25
+ rails-dom-testing (~> 1.0, >= 1.0.5)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (4.2.8)
28
+ activesupport (= 4.2.8)
29
+ builder (~> 3.1)
30
+ erubis (~> 2.7.0)
31
+ rails-dom-testing (~> 1.0, >= 1.0.5)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (4.2.8)
34
+ activesupport (= 4.2.8)
35
+ globalid (>= 0.3.0)
36
+ activemodel (4.2.8)
37
+ activesupport (= 4.2.8)
38
+ builder (~> 3.1)
39
+ activerecord (4.2.8)
40
+ activemodel (= 4.2.8)
41
+ activesupport (= 4.2.8)
42
+ arel (~> 6.0)
43
+ activesupport (4.2.8)
44
+ i18n (~> 0.7)
45
+ minitest (~> 5.1)
46
+ thread_safe (~> 0.3, >= 0.3.4)
47
+ tzinfo (~> 1.1)
48
+ arel (6.0.4)
49
+ aws-sdk (2.9.39)
50
+ aws-sdk-resources (= 2.9.39)
51
+ aws-sdk-core (2.9.39)
52
+ aws-sigv4 (~> 1.0)
53
+ jmespath (~> 1.0)
54
+ aws-sdk-resources (2.9.39)
55
+ aws-sdk-core (= 2.9.39)
56
+ aws-sigv4 (1.0.0)
57
+ builder (3.2.3)
58
+ commander (4.4.3)
59
+ highline (~> 1.7.2)
60
+ concurrent-ruby (1.0.5)
61
+ diff-lcs (1.3)
62
+ ec2-metadata (0.2.2)
63
+ erubis (2.7.0)
64
+ globalid (0.4.0)
65
+ activesupport (>= 4.2.0)
66
+ highline (1.7.8)
67
+ i18n (0.8.4)
68
+ jmespath (1.3.1)
69
+ loofah (2.0.3)
70
+ nokogiri (>= 1.5.9)
71
+ mail (2.6.6)
72
+ mime-types (>= 1.16, < 4)
73
+ mime-types (3.1)
74
+ mime-types-data (~> 3.2015)
75
+ mime-types-data (3.2016.0521)
76
+ mini_portile2 (2.2.0)
77
+ minitest (5.10.2)
78
+ nokogiri (1.8.0)
79
+ mini_portile2 (~> 2.2.0)
80
+ rack (1.6.8)
81
+ rack-test (0.6.3)
82
+ rack (>= 1.0)
83
+ rails (4.2.8)
84
+ actionmailer (= 4.2.8)
85
+ actionpack (= 4.2.8)
86
+ actionview (= 4.2.8)
87
+ activejob (= 4.2.8)
88
+ activemodel (= 4.2.8)
89
+ activerecord (= 4.2.8)
90
+ activesupport (= 4.2.8)
91
+ bundler (>= 1.3.0, < 2.0)
92
+ railties (= 4.2.8)
93
+ sprockets-rails
94
+ rails-deprecated_sanitizer (1.0.3)
95
+ activesupport (>= 4.2.0.alpha)
96
+ rails-dom-testing (1.0.8)
97
+ activesupport (>= 4.2.0.beta, < 5.0)
98
+ nokogiri (~> 1.6)
99
+ rails-deprecated_sanitizer (>= 1.0.1)
100
+ rails-html-sanitizer (1.0.3)
101
+ loofah (~> 2.0)
102
+ railties (4.2.8)
103
+ actionpack (= 4.2.8)
104
+ activesupport (= 4.2.8)
105
+ rake (>= 0.8.7)
106
+ thor (>= 0.18.1, < 2.0)
107
+ rake (10.4.2)
108
+ rspec (3.5.0)
109
+ rspec-core (~> 3.5.0)
110
+ rspec-expectations (~> 3.5.0)
111
+ rspec-mocks (~> 3.5.0)
112
+ rspec-core (3.5.4)
113
+ rspec-support (~> 3.5.0)
114
+ rspec-expectations (3.5.0)
115
+ diff-lcs (>= 1.2.0, < 2.0)
116
+ rspec-support (~> 3.5.0)
117
+ rspec-mocks (3.5.0)
118
+ diff-lcs (>= 1.2.0, < 2.0)
119
+ rspec-support (~> 3.5.0)
120
+ rspec-support (3.5.0)
121
+ sprockets (3.7.1)
122
+ concurrent-ruby (~> 1.0)
123
+ rack (> 1, < 3)
124
+ sprockets-rails (3.2.0)
125
+ actionpack (>= 4.0)
126
+ activesupport (>= 4.0)
127
+ sprockets (>= 3.0.0)
128
+ thor (0.19.4)
129
+ thread_safe (0.3.6)
130
+ tzinfo (1.2.3)
131
+ thread_safe (~> 0.1)
132
+
133
+ PLATFORMS
134
+ ruby
135
+
136
+ DEPENDENCIES
137
+ bundler (~> 1.15)
138
+ hekate!
139
+ rake (~> 10.0)
140
+ rspec (~> 3.0)
141
+
142
+ BUNDLED WITH
143
+ 1.15.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 jasonrisch
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,41 @@
1
+ # Hekate
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hekate`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hekate'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hekate
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jasonrisch/hekate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'hekate'
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/hekate ADDED
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hekate'
4
+ require 'rubygems'
5
+ require 'commander/import'
6
+
7
+ # :name is optional, otherwise uses the basename of this executable
8
+ program :name, 'Hekate'
9
+ program :version, Hekate::VERSION
10
+ program :description, 'Gem for encrypting and storing rails application secrets as Amazon SSM parameters'
11
+
12
+ default_options = proc do |config|
13
+ config.option '--application STRING', String, 'The application name for which the imported secrets will be used'
14
+ config.option '--environment STRING', String, 'The rails environment for which the imported secrets will be used. Defaults to development'
15
+ config.option '--region STRING', String, 'The aws region to import into. Defaults to ENV["AWS_REGION"] || "us-west-2"'
16
+ end
17
+
18
+ is_valid = proc do |options|
19
+ say("<%= color('--application is required', RED) %>!") unless options.application
20
+ say("<%= color('--environment is required', RED) %>!") unless options.environment
21
+
22
+ options.application && options.environment
23
+ end
24
+
25
+ command :import do |c|
26
+ c.syntax = 'hekate import --region us-west-2 --environment development --application mycoolapp --file .env'
27
+ c.description = 'imports a .env formatted file into Amazon SSM'
28
+ default_options.call c
29
+ c.option '--file STRING', String, 'The dotenv formatted file to import'
30
+ c.action do |_args, options|
31
+ options.default \
32
+ environment: :development,
33
+ region: Hekate::Engine.get_region
34
+
35
+ next unless is_valid.call(options)
36
+ unless options.file && File.exist?(options.file)
37
+ say("<%= color('--file was not provided or does not exist', RED) %>!")
38
+ next
39
+ end
40
+
41
+ next unless agree("<%= color('WARNING!!! This will overwrite existing parameters for #{options.application} #{options.environment} in #{options.region}. Continue?', RED) %>")
42
+
43
+ engine = Hekate::Engine.new(options.region, options.environment, options.application)
44
+ engine.import options.file
45
+ end
46
+ end
47
+
48
+ command :add do |c|
49
+ c.syntax = 'hekate add --region us-west-2 --environment development --application mycoolapp --key somekey --value somevalue'
50
+ c.description = 'adds a new environment secret and value'
51
+ default_options.call c
52
+ c.option '--key STRING', String, 'The environment name of the secret to store'
53
+ c.option '--value STRING', String, 'The environment value of the secret to store'
54
+ c.action do |_args, options|
55
+ options.default \
56
+ environment: :development,
57
+ region: Hekate::Engine.get_region
58
+
59
+ puts 0
60
+ next unless is_valid.call(options)
61
+ unless options.key && options.value
62
+ say("<%= color('--key and --value are required', RED) %>!")
63
+ next
64
+ end
65
+
66
+ puts 1
67
+ engine = Hekate::Engine.new(options.region, options.environment, options.application)
68
+ engine.add_parameter options.key, options.value
69
+ end
70
+ end
71
+
72
+ command :delete do |c|
73
+ c.syntax = 'hekate delete --region us-west-2 --environment development --application mycoolapp --key somekey'
74
+ c.description = 'deletes an environment secret'
75
+ default_options.call c
76
+ c.option '--key STRING', String, 'The environment name of the secret to delete'
77
+ c.action do |_args, options|
78
+ options.default \
79
+ environment: :development,
80
+ region: Hekate::Engine.get_region
81
+
82
+ next unless is_valid.call(options)
83
+ unless options.key
84
+ say("<%= color('--key is required', RED) %>!")
85
+ next
86
+ end
87
+
88
+ engine = Hekate::Engine.new(options.region, options.environment, options.application)
89
+ engine.delete_parameter options.key
90
+ end
91
+ end
92
+
93
+ command :get do |c|
94
+ c.syntax = 'hekate get --region us-west-2 --environment development --application mycoolapp --key somekey'
95
+ c.description = 'retrieves an unencrypted environment secret'
96
+ default_options.call c
97
+ c.option '--key STRING', String, 'The environment name of the secret to delete'
98
+ c.action do |_args, options|
99
+ options.default \
100
+ environment: :development,
101
+ region: Hekate::Engine.get_region
102
+
103
+ next unless is_valid.call(options)
104
+ unless options.key
105
+ say("<%= color('--key is required', RED) %>!")
106
+ next
107
+ end
108
+
109
+ engine = Hekate::Engine.new(options.region, options.environment, options.application)
110
+ say engine.get_parameter(options.key).to_json
111
+ end
112
+ end
113
+
114
+ command :export do |c|
115
+ c.syntax = 'hekate export --region us-west-2 --environment development --application mycoolapp --file .env'
116
+ c.description = 'exports Amazon SSM parameters to a .env formatted file'
117
+ default_options.call c
118
+ c.option '--file STRING', String, 'The dotenv formatted file to export to'
119
+ c.action do |_args, options|
120
+ options.default \
121
+ environment: :development,
122
+ region: Hekate::Engine.get_region
123
+
124
+ next unless is_valid.call(options)
125
+ next unless options.file
126
+ if File.exist? options.file
127
+ next unless agree("<%= color('File already exists. Overwrite?', RED) %>!")
128
+ end
129
+
130
+ engine = Hekate::Engine.new(options.region, options.environment, options.application)
131
+ engine.export options.file
132
+ end
133
+ end
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
data/hekate.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'hekate/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'hekate'
9
+ spec.version = Hekate::VERSION
10
+ spec.authors = ['jasonrisch']
11
+ spec.email = ['krimsonkla@yahoo.com']
12
+
13
+ spec.summary = 'A simple rails interface for hiding secrets in AWS EC2 Parameters'
14
+ spec.homepage = 'https://github.com/krimsonkla/hekate'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'bin'
21
+ spec.executables = ['hekate']
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'aws-sdk', '~> 2.9', '>= 2.9.0'
25
+ spec.add_runtime_dependency 'commander', '~> 4.4', '>= 4.4.0'
26
+ spec.add_runtime_dependency 'ec2-metadata', '~> 0.2', '>= 0.2.0'
27
+ spec.add_runtime_dependency 'railties', '~> 4.2', '>= 4.2.0'
28
+ spec.add_runtime_dependency 'rails', '~> 4'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.15'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ end
data/lib/hekate.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'rails'
2
+ require 'hekate/version'
3
+ require 'hekate/railtie'
4
+ require 'hekate/engine'
@@ -0,0 +1,170 @@
1
+ require 'aws-sdk'
2
+ require 'ec2_metadata'
3
+ require 'commander/user_interaction'
4
+
5
+ module Hekate
6
+ class Engine
7
+ def self.get_region
8
+ if ec2?
9
+ Ec2Metadata[:placement]['availability-zone'][0...-1]
10
+ else
11
+ ENV['AWS_REGION'] || 'us-west-2'
12
+ end
13
+ end
14
+
15
+ def initialize(region, environment, application)
16
+ @region = region
17
+ @environment = environment
18
+ @application = application
19
+ end
20
+
21
+ def load_environment
22
+ parameter_key = "#{@application}.#{@environment}."
23
+
24
+ parameters = get_app_env_parameters
25
+ parameters = parameters.map(&:name)
26
+
27
+ parameters.each_slice(10) do |slice|
28
+ result = ssm.get_app_env_parameters(
29
+ names: slice,
30
+ with_decryption: true
31
+ ).parameters
32
+
33
+ result.each do |parameter|
34
+ parameter_name = parameter.name.gsub(parameter_key, '')
35
+ ENV[parameter_name] = parameter.value
36
+ end
37
+ end
38
+ end
39
+
40
+ def import(env_file)
41
+ import_file = File.join(Dir.pwd, env_file)
42
+ raise("File does not exist #{import_file}") unless File.exist?(env_file)
43
+
44
+ lines = File.readlines(import_file)
45
+ progress = Commander::UI::ProgressBar.new(lines.length)
46
+ lines.each do |line|
47
+ progress.increment
48
+ next if line.start_with? '#'
49
+
50
+ key, value = line.split('=')
51
+
52
+ next if value.nil?
53
+ value = value.delete('"').delete("'").delete("\n")
54
+ next if value.empty?
55
+
56
+ add_parameter(key, value)
57
+ end
58
+ end
59
+
60
+ def add_parameter(key, value)
61
+ response = ssm.put_parameter(name: "#{@application}.#{@environment}.#{key}",
62
+ value: value,
63
+ type: 'SecureString',
64
+ key_id: kms_key.key_id,
65
+ overwrite: true)
66
+ end
67
+
68
+ def get_parameter(key)
69
+ parameter_key = "#{@application}.#{@environment}.#{key}"
70
+ ssm.get_parameters(
71
+ names: [parameter_key],
72
+ with_decryption: true
73
+ ).parameters.first["value"]
74
+ end
75
+
76
+ def delete_parameter(key)
77
+ ssm.delete_parameter(name: "#{@application}.#{@environment}.#{key}")
78
+ end
79
+
80
+ def export(env_file)
81
+ parameter_key = "#{@application}.#{@environment}."
82
+
83
+ parameters = get_app_env_parameters
84
+ parameters = parameters.map(&:name)
85
+
86
+ progress = Commander::UI::ProgressBar.new(parameters.length)
87
+ open(env_file, 'w') do |file|
88
+ parameters.each_slice(10) do |slice|
89
+ result = ssm.get_app_env_parameters(
90
+ names: slice,
91
+ with_decryption: true
92
+ ).parameters
93
+
94
+ result.each do |parameter|
95
+ progress.increment
96
+ parameter_name = parameter.name.gsub(parameter_key, '')
97
+ file.puts "#{parameter_name}=#{parameter.value}"
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ private
104
+
105
+ def kms
106
+ @kms ||= Aws::KMS::Client.new(region: @region)
107
+ end
108
+
109
+ def ssm
110
+ @ssm ||= Aws::SSM::Client.new(region: @region)
111
+ end
112
+
113
+ def kms_key
114
+ return @kms_key if @kms_key
115
+
116
+ alias_name = "alias/#{@application}_#{@environment}"
117
+
118
+ if kms_alias_exists? alias_name
119
+ key = kms.describe_key(key_id: alias_name).key_metadata
120
+ else
121
+ key = kms.create_key.key_metadata
122
+ kms.create_alias(
123
+ alias_name: alias_name,
124
+ target_key_id: key.key_id
125
+ )
126
+ end
127
+
128
+ key
129
+ end
130
+
131
+ def kms_alias_exists?(kms_alias)
132
+ aliases = kms.list_aliases.aliases.map(&:alias_name)
133
+ aliases.include? kms_alias
134
+ end
135
+
136
+ def get_app_env_parameters(parameters = [], next_token = nil)
137
+ query = {
138
+ filters: [
139
+ {
140
+ key: 'Name',
141
+ values: ["#{@application}.#{@environment}"]
142
+ }
143
+ ],
144
+ max_results: 50
145
+ }
146
+ query[:next_token] = next_token if next_token
147
+ response = ssm.describe_parameters(query)
148
+
149
+ parameters += response.parameters
150
+
151
+ parameters = get_app_env_parameters(parameters, response.next_token) if response.next_token
152
+
153
+ parameters
154
+ end
155
+
156
+ def self.ec2?
157
+ return false if Rails.env.development? || Rails.env.test?
158
+
159
+ http = Net::HTTP.new(Ec2Metadata::DEFAULT_HOST)
160
+ http.open_timeout = 1
161
+ http.read_timeout = 1
162
+ http.start do |http|
163
+ res = http.get('/')
164
+ res.code != '404'
165
+ end
166
+ rescue
167
+ false
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,11 @@
1
+ module Hekate
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load 'lib/tasks'
5
+ end
6
+
7
+ config.before_configuration do
8
+ Hekate::Engine.new(Engine.get_region, Rails.env.to_s, ENV["HEKATE_APPLICATION"]).load_environment
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Hekate
2
+ VERSION = '0.1.0.pre2'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hekate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre2
5
+ platform: ruby
6
+ authors:
7
+ - jasonrisch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.9'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.9.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.9'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.9.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: commander
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.4'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 4.4.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.4'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 4.4.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: ec2-metadata
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.2'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.2.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.2'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.2.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: railties
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '4.2'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 4.2.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 4.2.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: rails
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '4'
100
+ type: :runtime
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '4'
107
+ - !ruby/object:Gem::Dependency
108
+ name: bundler
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '1.15'
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '1.15'
121
+ - !ruby/object:Gem::Dependency
122
+ name: rake
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '10.0'
128
+ type: :development
129
+ prerelease: false
130
+ version_requirements: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '10.0'
135
+ - !ruby/object:Gem::Dependency
136
+ name: rspec
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '3.0'
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - "~>"
147
+ - !ruby/object:Gem::Version
148
+ version: '3.0'
149
+ description:
150
+ email:
151
+ - krimsonkla@yahoo.com
152
+ executables:
153
+ - hekate
154
+ extensions: []
155
+ extra_rdoc_files: []
156
+ files:
157
+ - ".gitignore"
158
+ - ".idea/vcs.xml"
159
+ - ".rspec"
160
+ - CODE_OF_CONDUCT.md
161
+ - Gemfile
162
+ - Gemfile.lock
163
+ - LICENSE.txt
164
+ - README.md
165
+ - Rakefile
166
+ - bin/console
167
+ - bin/hekate
168
+ - bin/setup
169
+ - hekate.gemspec
170
+ - lib/hekate.rb
171
+ - lib/hekate/engine.rb
172
+ - lib/hekate/railtie.rb
173
+ - lib/hekate/version.rb
174
+ homepage: https://github.com/krimsonkla/hekate
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">"
190
+ - !ruby/object:Gem::Version
191
+ version: 1.3.1
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.12
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: A simple rails interface for hiding secrets in AWS EC2 Parameters
198
+ test_files: []