hekate 0.1.0.pre8 → 0.1.0.pre9
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 +4 -4
- data/Gemfile.lock +57 -43
- data/README.md +19 -2
- data/bin/hekate +90 -59
- data/hekate.gemspec +3 -1
- data/lib/hekate/engine.rb +60 -48
- data/lib/hekate/railtie.rb +1 -1
- data/lib/hekate/version.rb +1 -1
- metadata +34 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ecc23bf834a320527d52253567b5291e95dc903
|
4
|
+
data.tar.gz: 4b31403aa6ac2ebe82dad15767c099e45beba3ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d63501a13ae8d87009f369a79bc2cad45af83c3d1d659a76c6e85d9a63688e31f66435de730a0907e59ee4c7c34ea4092360614db38457b954681249ddc0f017
|
7
|
+
data.tar.gz: 209fcaabaa904a32945d66b73d51115bbd7ac3c8b6679d0231397dfe64f2a434cc7f4e264603174d6c1bef2bb4bc1337fb06bca6ad9608e634e86ad102a8cfbd
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hekate (0.1.0.
|
4
|
+
hekate (0.1.0.pre9)
|
5
5
|
aws-sdk (~> 2.9, >= 2.9.0)
|
6
6
|
commander (~> 4.4, >= 4.4.0)
|
7
7
|
ec2-metadata (~> 0.2, >= 0.2.0)
|
@@ -11,85 +11,91 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
actionmailer (4.2.
|
15
|
-
actionpack (= 4.2.
|
16
|
-
actionview (= 4.2.
|
17
|
-
activejob (= 4.2.
|
14
|
+
actionmailer (4.2.9)
|
15
|
+
actionpack (= 4.2.9)
|
16
|
+
actionview (= 4.2.9)
|
17
|
+
activejob (= 4.2.9)
|
18
18
|
mail (~> 2.5, >= 2.5.4)
|
19
19
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
20
|
-
actionpack (4.2.
|
21
|
-
actionview (= 4.2.
|
22
|
-
activesupport (= 4.2.
|
20
|
+
actionpack (4.2.9)
|
21
|
+
actionview (= 4.2.9)
|
22
|
+
activesupport (= 4.2.9)
|
23
23
|
rack (~> 1.6)
|
24
24
|
rack-test (~> 0.6.2)
|
25
25
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
26
26
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
-
actionview (4.2.
|
28
|
-
activesupport (= 4.2.
|
27
|
+
actionview (4.2.9)
|
28
|
+
activesupport (= 4.2.9)
|
29
29
|
builder (~> 3.1)
|
30
30
|
erubis (~> 2.7.0)
|
31
31
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
32
32
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
-
activejob (4.2.
|
34
|
-
activesupport (= 4.2.
|
33
|
+
activejob (4.2.9)
|
34
|
+
activesupport (= 4.2.9)
|
35
35
|
globalid (>= 0.3.0)
|
36
|
-
activemodel (4.2.
|
37
|
-
activesupport (= 4.2.
|
36
|
+
activemodel (4.2.9)
|
37
|
+
activesupport (= 4.2.9)
|
38
38
|
builder (~> 3.1)
|
39
|
-
activerecord (4.2.
|
40
|
-
activemodel (= 4.2.
|
41
|
-
activesupport (= 4.2.
|
39
|
+
activerecord (4.2.9)
|
40
|
+
activemodel (= 4.2.9)
|
41
|
+
activesupport (= 4.2.9)
|
42
42
|
arel (~> 6.0)
|
43
|
-
activesupport (4.2.
|
43
|
+
activesupport (4.2.9)
|
44
44
|
i18n (~> 0.7)
|
45
45
|
minitest (~> 5.1)
|
46
46
|
thread_safe (~> 0.3, >= 0.3.4)
|
47
47
|
tzinfo (~> 1.1)
|
48
|
+
addressable (2.5.1)
|
49
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
48
50
|
arel (6.0.4)
|
49
|
-
aws-sdk (2.
|
50
|
-
aws-sdk-resources (= 2.
|
51
|
-
aws-sdk-core (2.
|
51
|
+
aws-sdk (2.10.21)
|
52
|
+
aws-sdk-resources (= 2.10.21)
|
53
|
+
aws-sdk-core (2.10.21)
|
52
54
|
aws-sigv4 (~> 1.0)
|
53
55
|
jmespath (~> 1.0)
|
54
|
-
aws-sdk-resources (2.
|
55
|
-
aws-sdk-core (= 2.
|
56
|
-
aws-sigv4 (1.0.
|
56
|
+
aws-sdk-resources (2.10.21)
|
57
|
+
aws-sdk-core (= 2.10.21)
|
58
|
+
aws-sigv4 (1.0.1)
|
57
59
|
builder (3.2.3)
|
58
60
|
commander (4.4.3)
|
59
61
|
highline (~> 1.7.2)
|
60
62
|
concurrent-ruby (1.0.5)
|
63
|
+
crack (0.4.3)
|
64
|
+
safe_yaml (~> 1.0.0)
|
61
65
|
diff-lcs (1.3)
|
62
66
|
ec2-metadata (0.2.2)
|
63
67
|
erubis (2.7.0)
|
64
68
|
globalid (0.4.0)
|
65
69
|
activesupport (>= 4.2.0)
|
70
|
+
hashdiff (0.3.4)
|
66
71
|
highline (1.7.8)
|
67
|
-
i18n (0.8.
|
72
|
+
i18n (0.8.6)
|
68
73
|
jmespath (1.3.1)
|
69
74
|
loofah (2.0.3)
|
70
75
|
nokogiri (>= 1.5.9)
|
71
|
-
mail (2.6.
|
76
|
+
mail (2.6.6)
|
72
77
|
mime-types (>= 1.16, < 4)
|
73
78
|
mime-types (3.1)
|
74
79
|
mime-types-data (~> 3.2015)
|
75
80
|
mime-types-data (3.2016.0521)
|
76
|
-
mini_portile2 (2.
|
77
|
-
minitest (5.10.
|
78
|
-
nokogiri (1.
|
79
|
-
mini_portile2 (~> 2.
|
81
|
+
mini_portile2 (2.2.0)
|
82
|
+
minitest (5.10.3)
|
83
|
+
nokogiri (1.8.0)
|
84
|
+
mini_portile2 (~> 2.2.0)
|
85
|
+
public_suffix (2.0.5)
|
80
86
|
rack (1.6.8)
|
81
87
|
rack-test (0.6.3)
|
82
88
|
rack (>= 1.0)
|
83
|
-
rails (4.2.
|
84
|
-
actionmailer (= 4.2.
|
85
|
-
actionpack (= 4.2.
|
86
|
-
actionview (= 4.2.
|
87
|
-
activejob (= 4.2.
|
88
|
-
activemodel (= 4.2.
|
89
|
-
activerecord (= 4.2.
|
90
|
-
activesupport (= 4.2.
|
89
|
+
rails (4.2.9)
|
90
|
+
actionmailer (= 4.2.9)
|
91
|
+
actionpack (= 4.2.9)
|
92
|
+
actionview (= 4.2.9)
|
93
|
+
activejob (= 4.2.9)
|
94
|
+
activemodel (= 4.2.9)
|
95
|
+
activerecord (= 4.2.9)
|
96
|
+
activesupport (= 4.2.9)
|
91
97
|
bundler (>= 1.3.0, < 2.0)
|
92
|
-
railties (= 4.2.
|
98
|
+
railties (= 4.2.9)
|
93
99
|
sprockets-rails
|
94
100
|
rails-deprecated_sanitizer (1.0.3)
|
95
101
|
activesupport (>= 4.2.0.alpha)
|
@@ -99,9 +105,9 @@ GEM
|
|
99
105
|
rails-deprecated_sanitizer (>= 1.0.1)
|
100
106
|
rails-html-sanitizer (1.0.3)
|
101
107
|
loofah (~> 2.0)
|
102
|
-
railties (4.2.
|
103
|
-
actionpack (= 4.2.
|
104
|
-
activesupport (= 4.2.
|
108
|
+
railties (4.2.9)
|
109
|
+
actionpack (= 4.2.9)
|
110
|
+
activesupport (= 4.2.9)
|
105
111
|
rake (>= 0.8.7)
|
106
112
|
thor (>= 0.18.1, < 2.0)
|
107
113
|
rake (10.4.2)
|
@@ -118,6 +124,7 @@ GEM
|
|
118
124
|
diff-lcs (>= 1.2.0, < 2.0)
|
119
125
|
rspec-support (~> 3.5.0)
|
120
126
|
rspec-support (3.5.0)
|
127
|
+
safe_yaml (1.0.4)
|
121
128
|
sprockets (3.7.1)
|
122
129
|
concurrent-ruby (~> 1.0)
|
123
130
|
rack (> 1, < 3)
|
@@ -129,6 +136,11 @@ GEM
|
|
129
136
|
thread_safe (0.3.6)
|
130
137
|
tzinfo (1.2.3)
|
131
138
|
thread_safe (~> 0.1)
|
139
|
+
vcr (3.0.3)
|
140
|
+
webmock (3.0.1)
|
141
|
+
addressable (>= 2.3.6)
|
142
|
+
crack (>= 0.3.2)
|
143
|
+
hashdiff
|
132
144
|
|
133
145
|
PLATFORMS
|
134
146
|
ruby
|
@@ -138,6 +150,8 @@ DEPENDENCIES
|
|
138
150
|
hekate!
|
139
151
|
rake (~> 10.0)
|
140
152
|
rspec (~> 3.0)
|
153
|
+
vcr
|
154
|
+
webmock
|
141
155
|
|
142
156
|
BUNDLED WITH
|
143
|
-
1.15.
|
157
|
+
1.15.3
|
data/README.md
CHANGED
@@ -17,13 +17,30 @@ And then execute:
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
19
|
$ gem install hekate
|
20
|
+
|
21
|
+
Add the following to application.rb
|
22
|
+
|
23
|
+
require "hekate"
|
24
|
+
Hekate::Engine.application = "yourapplicationname"
|
20
25
|
|
21
|
-
When included in a rails application Hekate will read credentials directly from AWS SMS Parameter store based on the RAILS_ENV,
|
26
|
+
When included in a rails application Hekate will read credentials directly from AWS SMS Parameter store based on the RAILS_ENV, AWS_REGION environment variables and store them as local ENV variables and the configured Hekate::Engine.application value
|
27
|
+
|
28
|
+
SSM parameters are loaded in much the same fashion as with the dotenv gem. Root items are loaded first, then overloaded with more specific settings. When stored in SSM parameter names are stored as "application.environment.key"
|
29
|
+
|
30
|
+
When given the following keys
|
31
|
+
|
32
|
+
myapp.root.SOMEKEY = basevalue
|
33
|
+
myapp.staging.somekey = stagingvalue
|
34
|
+
|
35
|
+
The resulting process only environment settings would be
|
36
|
+
|
37
|
+
ENV["SOMEKEY"] = stagingvalue
|
38
|
+
|
22
39
|
|
23
40
|
## Usage
|
24
41
|
Hekate requires AWS authentication and assumes credentials are provided to the executing system via one of the available amazon authentication methods. It does not ever accept credentials via command line.
|
25
42
|
|
26
|
-
It is recommended that you use 2 different roles in IAM similar to the following
|
43
|
+
It is recommended that you use 2 different roles in IAM similar to the following to provide read/write access to ssm parameters and iam encryption keys
|
27
44
|
|
28
45
|
#### Hekate User - read only parameter access
|
29
46
|
```json
|
data/bin/hekate
CHANGED
@@ -9,37 +9,48 @@ program :name, 'Hekate'
|
|
9
9
|
program :version, Hekate::VERSION
|
10
10
|
program :description, 'Gem for encrypting and storing rails application secrets as Amazon SSM parameters'
|
11
11
|
|
12
|
-
|
13
|
-
config
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
class CommandProcessor
|
13
|
+
def self.add_default_options(config)
|
14
|
+
config.option '--application STRING', String, 'The application name for which the imported secrets will be used'
|
15
|
+
config.option '--environment STRING', String, 'The rails environment for which the imported secrets will be used. Defaults to development'
|
16
|
+
config.option '--region STRING', String, 'The aws region to import into. Defaults to ENV["AWS_REGION"] || "us-west-2"'
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def self.add_default_values(options)
|
20
|
+
region = Hekate::Engine.get_region
|
21
|
+
options.default \
|
22
|
+
environment: 'development',
|
23
|
+
region: region
|
24
|
+
end
|
21
25
|
|
22
|
-
|
26
|
+
def self.valid?(options)
|
27
|
+
say("<%= color('--application is required', RED) %>!") unless options.application
|
28
|
+
say("<%= color('--environment is required', RED) %>!") unless options.environment
|
29
|
+
|
30
|
+
options.application && options.environment && yield
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
34
|
command :import do |c|
|
26
35
|
c.syntax = 'hekate import --region us-west-2 --environment development --application mycoolapp --file .env'
|
27
36
|
c.description = 'imports a .env formatted file into Amazon SSM'
|
28
|
-
|
37
|
+
CommandProcessor.add_default_options c
|
29
38
|
c.option '--file STRING', String, 'The dotenv formatted file to import'
|
30
39
|
c.action do |_args, options|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
CommandProcessor.add_default_values options
|
41
|
+
|
42
|
+
next unless CommandProcessor.valid?(options) do
|
43
|
+
unless options.file && File.exist?(options.file)
|
44
|
+
say("<%= color('--file was not provided or does not exist', RED) %>!")
|
45
|
+
next(false)
|
46
|
+
end
|
47
|
+
|
48
|
+
unless agree("<%= color('WARNING!!! This will overwrite existing parameters for #{options.application} #{options.environment} in #{options.region}. Continue?', RED) %>")
|
49
|
+
say("<%= color('ABORTED', RED) %>!")
|
50
|
+
next(false)
|
51
|
+
end
|
39
52
|
end
|
40
53
|
|
41
|
-
next unless agree("<%= color('WARNING!!! This will overwrite existing parameters for #{options.application} #{options.environment} in #{options.region}. Continue?', RED) %>")
|
42
|
-
|
43
54
|
engine = Hekate::Engine.new(options.region, options.environment, options.application)
|
44
55
|
engine.import options.file
|
45
56
|
end
|
@@ -48,83 +59,103 @@ end
|
|
48
59
|
command :put do |c|
|
49
60
|
c.syntax = 'hekate put --region us-west-2 --environment development --application mycoolapp --key somekey --value somevalue'
|
50
61
|
c.description = 'adds a new environment secret and value'
|
51
|
-
|
62
|
+
CommandProcessor.add_default_options c
|
52
63
|
c.option '--key STRING', String, 'The environment name of the secret to store'
|
53
64
|
c.option '--value STRING', String, 'The environment value of the secret to store'
|
54
65
|
c.action do |_args, options|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
next
|
66
|
+
CommandProcessor.add_default_values options
|
67
|
+
|
68
|
+
next unless CommandProcessor.valid?(options) do
|
69
|
+
unless options.key && options.value
|
70
|
+
say("<%= color('--key and --value are required', RED) %>!")
|
71
|
+
next(false)
|
72
|
+
end
|
63
73
|
end
|
64
|
-
|
74
|
+
|
65
75
|
engine = Hekate::Engine.new(options.region, options.environment, options.application)
|
66
|
-
engine.
|
76
|
+
engine.put options.key, options.value
|
67
77
|
end
|
68
78
|
end
|
69
79
|
|
70
80
|
command :delete do |c|
|
71
81
|
c.syntax = 'hekate delete --region us-west-2 --environment development --application mycoolapp --key somekey'
|
72
82
|
c.description = 'deletes an environment secret'
|
73
|
-
|
83
|
+
CommandProcessor.add_default_options c
|
74
84
|
c.option '--key STRING', String, 'The environment name of the secret to delete'
|
75
85
|
c.action do |_args, options|
|
76
|
-
|
77
|
-
environment: :development,
|
78
|
-
region: Hekate::Engine.get_region
|
86
|
+
CommandProcessor.add_default_values options
|
79
87
|
|
80
|
-
next unless
|
81
|
-
|
82
|
-
|
83
|
-
|
88
|
+
next unless CommandProcessor.valid?(options) do
|
89
|
+
unless options.key
|
90
|
+
say("<%= color('--key is required', RED) %>!")
|
91
|
+
next(false)
|
92
|
+
end
|
84
93
|
end
|
85
94
|
|
86
95
|
engine = Hekate::Engine.new(options.region, options.environment, options.application)
|
87
|
-
engine.
|
96
|
+
engine.delete options.key
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
command :delete do |c|
|
101
|
+
c.syntax = 'hekate delete_all --region us-west-2 --environment development --application mycoolapp'
|
102
|
+
c.description = 'deletes all secrets for the give environment'
|
103
|
+
CommandProcessor.add_default_options c
|
104
|
+
c.action do |_args, options|
|
105
|
+
CommandProcessor.add_default_values options
|
106
|
+
|
107
|
+
next unless CommandProcessor.valid?(options) do
|
108
|
+
unless agree("<%= color('WARNING!!! This will delete all existing parameters for #{options.application} #{options.environment} in #{options.region}. Continue?', RED) %>")
|
109
|
+
say("<%= color('ABORTED', RED) %>!")
|
110
|
+
next(false)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
engine = Hekate::Engine.new(options.region, options.environment, options.application)
|
115
|
+
engine.delete_all
|
88
116
|
end
|
89
117
|
end
|
90
118
|
|
91
119
|
command :get do |c|
|
92
120
|
c.syntax = 'hekate get --region us-west-2 --environment development --application mycoolapp --key somekey'
|
93
121
|
c.description = 'retrieves an unencrypted environment secret'
|
94
|
-
|
122
|
+
CommandProcessor.add_default_options c
|
95
123
|
c.option '--key STRING', String, 'The environment name of the secret to delete'
|
96
124
|
c.action do |_args, options|
|
97
|
-
|
98
|
-
environment: :development,
|
99
|
-
region: Hekate::Engine.get_region
|
125
|
+
CommandProcessor.add_default_values options
|
100
126
|
|
101
|
-
next unless
|
102
|
-
|
103
|
-
|
104
|
-
|
127
|
+
next unless CommandProcessor.valid?(options) do
|
128
|
+
unless options.key
|
129
|
+
say("<%= color('--key is required', RED) %>!")
|
130
|
+
next(false)
|
131
|
+
end
|
105
132
|
end
|
106
133
|
|
107
134
|
engine = Hekate::Engine.new(options.region, options.environment, options.application)
|
108
|
-
puts engine.
|
135
|
+
puts engine.get(options.key)
|
109
136
|
end
|
110
137
|
end
|
111
138
|
|
112
139
|
command :export do |c|
|
113
140
|
c.syntax = 'hekate export --region us-west-2 --environment development --application mycoolapp --file .env'
|
114
141
|
c.description = 'exports Amazon SSM parameters to a .env formatted file'
|
115
|
-
|
142
|
+
CommandProcessor.add_default_options c
|
116
143
|
c.option '--file STRING', String, 'The dotenv formatted file to export to'
|
117
144
|
c.action do |_args, options|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
145
|
+
CommandProcessor.add_default_values options
|
146
|
+
|
147
|
+
next unless CommandProcessor.valid?(options) do
|
148
|
+
unless options.file
|
149
|
+
say("<%= color('--file is required', RED) %>!")
|
150
|
+
next(false)
|
151
|
+
end
|
152
|
+
if File.exist? options.file
|
153
|
+
unless agree("<%= color('File already exists. Overwrite?', RED) %>!")
|
154
|
+
say("<%= color('ABORTED', RED) %>!")
|
155
|
+
next(false)
|
156
|
+
end
|
157
|
+
end
|
126
158
|
end
|
127
|
-
|
128
159
|
engine = Hekate::Engine.new(options.region, options.environment, options.application)
|
129
160
|
engine.export options.file
|
130
161
|
end
|
data/hekate.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = ['hekate']
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_runtime_dependency 'aws-sdk', '2.9', '2.9.0'
|
24
|
+
spec.add_runtime_dependency 'aws-sdk', '~> 2.9', '>= 2.9.0'
|
25
25
|
spec.add_runtime_dependency 'commander', '~> 4.4', '>= 4.4.0'
|
26
26
|
spec.add_runtime_dependency 'ec2-metadata', '~> 0.2', '>= 0.2.0'
|
27
27
|
spec.add_runtime_dependency 'railties', '~> 4.2', '>= 4.2.0'
|
@@ -30,4 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
31
31
|
spec.add_development_dependency 'rake', '~> 10.0'
|
32
32
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
|
+
spec.add_development_dependency 'webmock'
|
34
|
+
spec.add_development_dependency 'vcr'
|
33
35
|
end
|
data/lib/hekate/engine.rb
CHANGED
@@ -4,6 +4,10 @@ require 'commander/user_interaction'
|
|
4
4
|
|
5
5
|
module Hekate
|
6
6
|
class Engine
|
7
|
+
class << self
|
8
|
+
attr_accessor :application
|
9
|
+
end
|
10
|
+
|
7
11
|
def self.get_region
|
8
12
|
if ec2?
|
9
13
|
Ec2Metadata[:placement]['availability-zone'][0...-1]
|
@@ -11,34 +15,43 @@ module Hekate
|
|
11
15
|
ENV['AWS_REGION'] || 'us-east-1'
|
12
16
|
end
|
13
17
|
end
|
18
|
+
|
19
|
+
def self.ec2?
|
20
|
+
Ec2Metadata[:instance_id]
|
21
|
+
true
|
22
|
+
rescue
|
23
|
+
false
|
24
|
+
end
|
14
25
|
|
15
|
-
def initialize(region, environment, application)
|
26
|
+
def initialize(region, environment, application = nil)
|
16
27
|
@region = region
|
17
|
-
@environment = environment
|
18
|
-
|
28
|
+
@environment = environment || Rails.env
|
29
|
+
Hekate::Engine.application = application
|
19
30
|
end
|
20
31
|
|
21
32
|
def load_environment
|
22
|
-
|
33
|
+
['root', @environment].each do |env|
|
34
|
+
parameter_key = "#{Hekate::Engine.application}.#{env}."
|
23
35
|
|
24
|
-
|
25
|
-
|
36
|
+
parameters = get_app_env_parameters(env)
|
37
|
+
parameters = parameters.map(&:name)
|
26
38
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
parameters.each_slice(10) do |slice|
|
40
|
+
result = ssm.get_parameters(
|
41
|
+
names: slice,
|
42
|
+
with_decryption: true
|
43
|
+
).parameters
|
44
|
+
|
45
|
+
result.each do |parameter|
|
46
|
+
parameter_name = parameter.name.gsub(parameter_key, '')
|
47
|
+
ENV[parameter_name] = parameter.value
|
48
|
+
end
|
36
49
|
end
|
37
50
|
end
|
38
51
|
end
|
39
52
|
|
40
53
|
def import(env_file)
|
41
|
-
import_file = File.
|
54
|
+
import_file = File.expand_path(env_file)
|
42
55
|
raise("File does not exist #{import_file}") unless File.exist?(env_file)
|
43
56
|
|
44
57
|
lines = File.readlines(import_file)
|
@@ -53,20 +66,20 @@ module Hekate
|
|
53
66
|
value = value.delete('"').delete("'").delete("\n")
|
54
67
|
next if value.empty?
|
55
68
|
|
56
|
-
|
69
|
+
put(key, value)
|
57
70
|
end
|
58
71
|
end
|
59
72
|
|
60
|
-
def
|
61
|
-
ssm.put_parameter(name: "#{
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
def put(key, value)
|
74
|
+
ssm.put_parameter(name: "#{Hekate::Engine.application}.#{@environment}.#{key}",
|
75
|
+
value: value,
|
76
|
+
type: 'SecureString',
|
77
|
+
key_id: kms_key.key_id,
|
78
|
+
overwrite: true)
|
66
79
|
end
|
67
80
|
|
68
|
-
def
|
69
|
-
parameter_key = "#{
|
81
|
+
def get(key)
|
82
|
+
parameter_key = "#{Hekate::Engine.application}.#{@environment}.#{key}"
|
70
83
|
parameters = ssm.get_parameters(
|
71
84
|
names: [parameter_key],
|
72
85
|
with_decryption: true
|
@@ -75,18 +88,30 @@ module Hekate
|
|
75
88
|
if parameters.to_a.empty?
|
76
89
|
puts "Could not find parameter #{parameter_key}"
|
77
90
|
else
|
78
|
-
|
91
|
+
parameters.first['value']
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def delete_all
|
96
|
+
parameters = get_app_env_parameters(@environment)
|
97
|
+
parameters = parameters.map(&:name)
|
98
|
+
progress = Commander::UI::ProgressBar.new(parameters.length)
|
99
|
+
parameters.each_slice(10) do |slice|
|
100
|
+
slice.each do |parameter|
|
101
|
+
progress.increment
|
102
|
+
ssm.delete_parameter(name: parameter)
|
103
|
+
end
|
79
104
|
end
|
80
105
|
end
|
81
106
|
|
82
|
-
def
|
83
|
-
ssm.delete_parameter(name: "#{
|
107
|
+
def delete(key)
|
108
|
+
ssm.delete_parameter(name: "#{Hekate::Engine.application}.#{@environment}.#{key}")
|
84
109
|
end
|
85
110
|
|
86
111
|
def export(env_file)
|
87
|
-
parameter_key = "#{
|
112
|
+
parameter_key = "#{Hekate::Engine.application}.#{@environment}."
|
88
113
|
|
89
|
-
parameters = get_app_env_parameters
|
114
|
+
parameters = get_app_env_parameters(@environment)
|
90
115
|
parameters = parameters.map(&:name)
|
91
116
|
|
92
117
|
progress = Commander::UI::ProgressBar.new(parameters.length)
|
@@ -119,7 +144,7 @@ module Hekate
|
|
119
144
|
def kms_key
|
120
145
|
return @kms_key if @kms_key
|
121
146
|
|
122
|
-
alias_name = "alias/#{
|
147
|
+
alias_name = "alias/#{Hekate::Engine.application}_#{@environment}"
|
123
148
|
|
124
149
|
if kms_alias_exists? alias_name
|
125
150
|
key = kms.describe_key(key_id: alias_name).key_metadata
|
@@ -139,12 +164,12 @@ module Hekate
|
|
139
164
|
aliases.include? kms_alias
|
140
165
|
end
|
141
166
|
|
142
|
-
def get_app_env_parameters(parameters = [], next_token = nil)
|
167
|
+
def get_app_env_parameters(env, parameters = [], next_token = nil)
|
143
168
|
query = {
|
144
169
|
filters: [
|
145
170
|
{
|
146
171
|
key: 'Name',
|
147
|
-
values: ["#{
|
172
|
+
values: ["#{Hekate::Engine.application}.#{env}"]
|
148
173
|
}
|
149
174
|
],
|
150
175
|
max_results: 50
|
@@ -154,23 +179,10 @@ module Hekate
|
|
154
179
|
|
155
180
|
parameters += response.parameters
|
156
181
|
|
157
|
-
parameters = get_app_env_parameters(parameters, response.next_token) if response.next_token
|
182
|
+
parameters = get_app_env_parameters(env, parameters, response.next_token) if response.next_token
|
158
183
|
|
159
184
|
parameters
|
160
185
|
end
|
161
|
-
|
162
|
-
def self.ec2?
|
163
|
-
return false if Rails.env.development? || Rails.env.test?
|
164
|
-
|
165
|
-
http = Net::HTTP.new(Ec2Metadata::DEFAULT_HOST)
|
166
|
-
http.open_timeout = 1
|
167
|
-
http.read_timeout = 1
|
168
|
-
http.start do |http|
|
169
|
-
res = http.get('/')
|
170
|
-
res.code != '404'
|
171
|
-
end
|
172
|
-
rescue
|
173
|
-
false
|
174
|
-
end
|
186
|
+
|
175
187
|
end
|
176
188
|
end
|
data/lib/hekate/railtie.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Hekate
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
config.before_configuration do
|
4
|
-
Hekate::Engine.new(Engine.get_region, Rails.env.to_s, ENV[
|
4
|
+
Hekate::Engine.new(Engine.get_region, Rails.env.to_s, ENV['HEKATE_APPLICATION']).load_environment
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
data/lib/hekate/version.rb
CHANGED
metadata
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hekate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.pre9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasonrisch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.9'
|
20
|
-
- -
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 2.9.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '2.9'
|
30
|
-
- -
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 2.9.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
@@ -146,6 +146,34 @@ dependencies:
|
|
146
146
|
- - "~>"
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '3.0'
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: webmock
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
type: :development
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
- !ruby/object:Gem::Dependency
|
164
|
+
name: vcr
|
165
|
+
requirement: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
type: :development
|
171
|
+
prerelease: false
|
172
|
+
version_requirements: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
149
177
|
description:
|
150
178
|
email:
|
151
179
|
- krimsonkla@yahoo.com
|