hekate 0.1.0.pre8 → 0.1.0.pre9

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
  SHA1:
3
- metadata.gz: 5f5ec549d18060e26d0733d73bd1c1a702b0819d
4
- data.tar.gz: edf310a045d52503e739515e5bc2d09461b694c6
3
+ metadata.gz: 5ecc23bf834a320527d52253567b5291e95dc903
4
+ data.tar.gz: 4b31403aa6ac2ebe82dad15767c099e45beba3ee
5
5
  SHA512:
6
- metadata.gz: e61c6472fb58bcd78a0be083b06894ddf2621a7779a2f1b526654437cf5d49942f3f983a571c6713081c8822ba0f614c7485f512d758126f32f6f89d1e59e3bd
7
- data.tar.gz: a9f0734319afec557554d7712c1801b4a2347d8f94466e6617f3ae341664fc3610de8c15c3fbc534a5b10b473c7ac71beae4ab4db88581c1938b78dc52bc5879
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.pre7)
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.8)
15
- actionpack (= 4.2.8)
16
- actionview (= 4.2.8)
17
- activejob (= 4.2.8)
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.8)
21
- actionview (= 4.2.8)
22
- activesupport (= 4.2.8)
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.8)
28
- activesupport (= 4.2.8)
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.8)
34
- activesupport (= 4.2.8)
33
+ activejob (4.2.9)
34
+ activesupport (= 4.2.9)
35
35
  globalid (>= 0.3.0)
36
- activemodel (4.2.8)
37
- activesupport (= 4.2.8)
36
+ activemodel (4.2.9)
37
+ activesupport (= 4.2.9)
38
38
  builder (~> 3.1)
39
- activerecord (4.2.8)
40
- activemodel (= 4.2.8)
41
- activesupport (= 4.2.8)
39
+ activerecord (4.2.9)
40
+ activemodel (= 4.2.9)
41
+ activesupport (= 4.2.9)
42
42
  arel (~> 6.0)
43
- activesupport (4.2.8)
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.9.15)
50
- aws-sdk-resources (= 2.9.15)
51
- aws-sdk-core (2.9.15)
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.9.15)
55
- aws-sdk-core (= 2.9.15)
56
- aws-sigv4 (1.0.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.4)
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.5)
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.1.0)
77
- minitest (5.10.2)
78
- nokogiri (1.7.1)
79
- mini_portile2 (~> 2.1.0)
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.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)
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.8)
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.8)
103
- actionpack (= 4.2.8)
104
- activesupport (= 4.2.8)
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.1
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, HEKATE_APPLICATION and AWS_REGION environment variables and store them as local ENV variables available to the rails applicaiton.
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
- 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
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
- 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
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
- options.application && options.environment
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
- default_options.call c
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
- 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
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
- default_options.call c
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
- options.default \
56
- environment: :development,
57
- region: Hekate::Engine.get_region
58
-
59
- next unless is_valid.call(options)
60
- unless options.key && options.value
61
- say("<%= color('--key and --value are required', RED) %>!")
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.add_parameter options.key, options.value
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
- default_options.call c
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
- options.default \
77
- environment: :development,
78
- region: Hekate::Engine.get_region
86
+ CommandProcessor.add_default_values options
79
87
 
80
- next unless is_valid.call(options)
81
- unless options.key
82
- say("<%= color('--key is required', RED) %>!")
83
- next
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.delete_parameter options.key
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
- default_options.call c
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
- options.default \
98
- environment: :development,
99
- region: Hekate::Engine.get_region
125
+ CommandProcessor.add_default_values options
100
126
 
101
- next unless is_valid.call(options)
102
- unless options.key
103
- say("<%= color('--key is required', RED) %>!")
104
- next
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.get_parameter(options.key)
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
- default_options.call c
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
- options.default \
119
- environment: :development,
120
- region: Hekate::Engine.get_region
121
-
122
- next unless is_valid.call(options)
123
- next unless options.file
124
- if File.exist? options.file
125
- next unless agree("<%= color('File already exists. Overwrite?', RED) %>!")
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
- @application = application
28
+ @environment = environment || Rails.env
29
+ Hekate::Engine.application = application
19
30
  end
20
31
 
21
32
  def load_environment
22
- parameter_key = "#{@application}.#{@environment}."
33
+ ['root', @environment].each do |env|
34
+ parameter_key = "#{Hekate::Engine.application}.#{env}."
23
35
 
24
- parameters = get_app_env_parameters
25
- parameters = parameters.map(&:name)
36
+ parameters = get_app_env_parameters(env)
37
+ parameters = parameters.map(&:name)
26
38
 
27
- parameters.each_slice(10) do |slice|
28
- result = ssm.get_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
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.join(Dir.pwd, env_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
- add_parameter(key, value)
69
+ put(key, value)
57
70
  end
58
71
  end
59
72
 
60
- def add_parameter(key, value)
61
- ssm.put_parameter(name: "#{@application}.#{@environment}.#{key}",
62
- value: value,
63
- type: 'SecureString',
64
- key_id: kms_key.key_id,
65
- overwrite: true)
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 get_parameter(key)
69
- parameter_key = "#{@application}.#{@environment}.#{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
- puts parameters.first["value"]
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 delete_parameter(key)
83
- ssm.delete_parameter(name: "#{@application}.#{@environment}.#{key}")
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 = "#{@application}.#{@environment}."
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/#{@application}_#{@environment}"
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: ["#{@application}.#{@environment}"]
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
@@ -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["HEKATE_APPLICATION"]).load_environment
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
@@ -1,3 +1,3 @@
1
1
  module Hekate
2
- VERSION = '0.1.0.pre8'.freeze
2
+ VERSION = '0.1.0.pre9'.freeze
3
3
  end
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.pre8
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-07-27 00:00:00.000000000 Z
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