chamber 2.12.5 → 2.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +101 -26
  5. data/lib/chamber.rb +82 -10
  6. data/lib/chamber/adapters/cloud/circle_ci.rb +85 -0
  7. data/lib/chamber/adapters/cloud/heroku.rb +74 -0
  8. data/lib/chamber/binary/circle_ci.rb +122 -0
  9. data/lib/chamber/binary/heroku.rb +45 -16
  10. data/lib/chamber/binary/runner.rb +42 -26
  11. data/lib/chamber/binary/travis.rb +5 -3
  12. data/lib/chamber/commands/base.rb +10 -16
  13. data/lib/chamber/commands/cloud/base.rb +35 -0
  14. data/lib/chamber/commands/{heroku → cloud}/clear.rb +6 -8
  15. data/lib/chamber/commands/cloud/compare.rb +26 -0
  16. data/lib/chamber/commands/cloud/pull.rb +29 -0
  17. data/lib/chamber/commands/cloud/push.rb +44 -0
  18. data/lib/chamber/commands/comparable.rb +2 -2
  19. data/lib/chamber/commands/compare.rb +6 -9
  20. data/lib/chamber/commands/initialize.rb +26 -22
  21. data/lib/chamber/commands/securable.rb +9 -9
  22. data/lib/chamber/commands/secure.rb +2 -2
  23. data/lib/chamber/commands/show.rb +8 -8
  24. data/lib/chamber/commands/sign.rb +2 -2
  25. data/lib/chamber/commands/verify.rb +2 -2
  26. data/lib/chamber/configuration.rb +8 -3
  27. data/lib/chamber/context_resolver.rb +8 -7
  28. data/lib/chamber/encryption_methods/ssl.rb +12 -12
  29. data/lib/chamber/file.rb +16 -14
  30. data/lib/chamber/file_set.rb +18 -8
  31. data/lib/chamber/files/signature.rb +16 -14
  32. data/lib/chamber/filters/decryption_filter.rb +17 -13
  33. data/lib/chamber/filters/encryption_filter.rb +8 -8
  34. data/lib/chamber/filters/environment_filter.rb +12 -14
  35. data/lib/chamber/filters/failed_decryption_filter.rb +6 -6
  36. data/lib/chamber/filters/insecure_filter.rb +3 -3
  37. data/lib/chamber/filters/namespace_filter.rb +5 -5
  38. data/lib/chamber/filters/secure_filter.rb +5 -5
  39. data/lib/chamber/filters/translate_secure_keys_filter.rb +5 -5
  40. data/lib/chamber/instance.rb +45 -21
  41. data/lib/chamber/key_pair.rb +7 -7
  42. data/lib/chamber/keys/base.rb +31 -49
  43. data/lib/chamber/keys/decryption.rb +5 -5
  44. data/lib/chamber/keys/encryption.rb +5 -5
  45. data/lib/chamber/namespace_set.rb +2 -4
  46. data/lib/chamber/settings.rb +73 -45
  47. data/lib/chamber/types/secured.rb +8 -10
  48. data/lib/chamber/version.rb +1 -1
  49. data/templates/settings.yml +2 -0
  50. metadata +46 -39
  51. metadata.gz.sig +0 -0
  52. data/lib/chamber/commands/heroku.rb +0 -31
  53. data/lib/chamber/commands/heroku/compare.rb +0 -33
  54. data/lib/chamber/commands/heroku/pull.rb +0 -30
  55. data/lib/chamber/commands/heroku/push.rb +0 -27
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'chamber/commands/cloud/base'
4
+ require 'chamber/commands/securable'
5
+ require 'chamber/keys/decryption'
6
+
7
+ module Chamber
8
+ module Commands
9
+ module Cloud
10
+ class Push < Chamber::Commands::Cloud::Base
11
+ include Chamber::Commands::Securable
12
+
13
+ attr_accessor :keys
14
+
15
+ def initialize(keys:, **args)
16
+ super(**args)
17
+
18
+ self.keys = keys
19
+ end
20
+
21
+ def call
22
+ environment_variables = if keys
23
+ Keys::Decryption
24
+ .new(rootpath: chamber.configuration.rootpath,
25
+ namespaces: chamber.configuration.namespaces)
26
+ .as_environment_variables
27
+ else
28
+ securable_environment_variables
29
+ end
30
+
31
+ environment_variables.each do |key, value|
32
+ if dry_run
33
+ shell.say_status 'push', key, :blue
34
+ else
35
+ shell.say_status 'push', key, :green
36
+
37
+ adapter.add_environment_variable(key, value)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -5,10 +5,10 @@ require 'tempfile'
5
5
  module Chamber
6
6
  module Commands
7
7
  module Comparable
8
- def initialize(options = {})
8
+ def initialize(keys_only:, **args)
9
9
  super
10
10
 
11
- self.keys_only = options[:keys_only]
11
+ self.keys_only = keys_only
12
12
  end
13
13
 
14
14
  def call
@@ -12,18 +12,15 @@ class Compare < Chamber::Commands::Base
12
12
  attr_accessor :first_settings_instance,
13
13
  :second_settings_instance
14
14
 
15
- def self.call(options = {})
16
- new(options).call
15
+ def self.call(**args)
16
+ new(**args).call
17
17
  end
18
18
 
19
- def initialize(options = {})
20
- super
19
+ def initialize(first:, second:, **args)
20
+ super(**args)
21
21
 
22
- first_settings_options = options.merge(namespaces: options[:first])
23
- self.first_settings_instance = Chamber::Instance.new(first_settings_options)
24
-
25
- second_settings_options = options.merge(namespaces: options[:second])
26
- self.second_settings_instance = Chamber::Instance.new(second_settings_options)
22
+ self.first_settings_instance = Chamber::Instance.new(args.merge(namespaces: first))
23
+ self.second_settings_instance = Chamber::Instance.new(args.merge(namespaces: second))
27
24
  end
28
25
 
29
26
  protected
@@ -11,23 +11,23 @@ require 'chamber/commands/base'
11
11
  module Chamber
12
12
  module Commands
13
13
  class Initialize < Chamber::Commands::Base
14
- def self.call(options = {})
15
- new(options).call
14
+ def self.call(**args)
15
+ new(**args).call
16
16
  end
17
17
 
18
18
  attr_accessor :basepath,
19
19
  :namespaces,
20
20
  :signature
21
21
 
22
- def initialize(options = {})
23
- super
22
+ def initialize(signature:, namespaces: [], **args)
23
+ super(**args)
24
24
 
25
25
  self.basepath = Chamber.configuration.basepath
26
- self.namespaces = options.fetch(:namespaces, [])
27
- self.signature = options.fetch(:signature)
26
+ self.namespaces = namespaces
27
+ self.signature = signature
28
28
  end
29
29
 
30
- # rubocop:disable Metrics/LineLength, Metrics/MethodLength, Metrics/AbcSize
30
+ # rubocop:disable Layout/LineLength, Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
31
31
  def call
32
32
  key_pairs = namespaces.map do |namespace|
33
33
  Chamber::KeyPair.new(namespace: namespace,
@@ -78,21 +78,25 @@ class Initialize < Chamber::Commands::Base
78
78
  shell.say 'Your signature keys, which will be used for verification, are located at:'
79
79
  shell.say ''
80
80
  shell.say ' * Public Key: '
81
- shell.say signature_key_pair.
82
- public_key_filepath.
83
- relative_path_from(Pathname.pwd), :yellow
81
+ shell.say signature_key_pair
82
+ .public_key_filepath
83
+ .relative_path_from(Pathname.pwd),
84
+ :yellow
84
85
  shell.say ' * Private Key: '
85
- shell.say signature_key_pair.
86
- unencrypted_private_key_filepath.
87
- relative_path_from(Pathname.pwd), :yellow
86
+ shell.say signature_key_pair
87
+ .unencrypted_private_key_filepath
88
+ .relative_path_from(Pathname.pwd),
89
+ :yellow
88
90
  shell.say ' * Encrypted Private Key: '
89
- shell.say signature_key_pair.
90
- encrypted_private_key_filepath.
91
- relative_path_from(Pathname.pwd), :yellow
91
+ shell.say signature_key_pair
92
+ .encrypted_private_key_filepath
93
+ .relative_path_from(Pathname.pwd),
94
+ :yellow
92
95
  shell.say ' * Encrypted Passphrase: '
93
- shell.say signature_key_pair.
94
- encrypted_private_key_passphrase_filepath.
95
- relative_path_from(Pathname.pwd), :yellow
96
+ shell.say signature_key_pair
97
+ .encrypted_private_key_passphrase_filepath
98
+ .relative_path_from(Pathname.pwd),
99
+ :yellow
96
100
 
97
101
  shell.say ''
98
102
  shell.say 'The signature private keys should be thought of separately from the other'
@@ -153,7 +157,7 @@ class Initialize < Chamber::Commands::Base
153
157
  shell.say '--------------------------------------------------------------------------------'
154
158
  shell.say ''
155
159
  end
156
- # rubocop:enable Metrics/LineLength, Metrics/MethodLength, Metrics/AbcSize
160
+ # rubocop:enable Layout/LineLength, Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
157
161
 
158
162
  protected
159
163
 
@@ -178,7 +182,7 @@ class Initialize < Chamber::Commands::Base
178
182
  end
179
183
 
180
184
  def append_to_gitignore
181
- ::FileUtils.touch gitignore_filepath
185
+ ::FileUtils.touch(gitignore_filepath)
182
186
 
183
187
  gitignore_contents = ::File.read(gitignore_filepath)
184
188
 
@@ -206,7 +210,7 @@ class Initialize < Chamber::Commands::Base
206
210
 
207
211
  def gem_path
208
212
  @gem_path ||= Pathname.new(
209
- ::File.expand_path('../../../..', __FILE__),
213
+ ::File.expand_path('../../..', __dir__),
210
214
  )
211
215
  end
212
216
 
@@ -6,15 +6,15 @@ require 'chamber/instance'
6
6
  module Chamber
7
7
  module Commands
8
8
  module Securable
9
- def initialize(options = {})
10
- super
11
-
12
- ignored_settings_options = options.
13
- merge(files: ignored_settings_filepaths).
14
- reject { |k, _v| k == 'basepath' }
15
- self.ignored_settings_instance = Chamber::Instance.new(ignored_settings_options)
16
- self.current_settings_instance = Chamber::Instance.new(options)
17
- self.only_sensitive = options[:only_sensitive]
9
+ def initialize(only_sensitive: nil, **args)
10
+ super(**args)
11
+
12
+ ignored_settings_options = args
13
+ .merge(files: ignored_settings_filepaths)
14
+ .reject { |k, _v| k == 'basepath' }
15
+ self.ignored_settings_instance = Chamber::Instance.new(**ignored_settings_options)
16
+ self.current_settings_instance = Chamber::Instance.new(**args)
17
+ self.only_sensitive = only_sensitive
18
18
  end
19
19
 
20
20
  protected
@@ -8,8 +8,8 @@ module Commands
8
8
  class Secure < Chamber::Commands::Base
9
9
  include Chamber::Commands::Securable
10
10
 
11
- def initialize(options = {})
12
- super(options.merge(namespaces: ['*']))
11
+ def initialize(**args)
12
+ super(**args.merge(namespaces: ['*']))
13
13
  end
14
14
 
15
15
  def call
@@ -9,21 +9,21 @@ class Show < Chamber::Commands::Base
9
9
  attr_accessor :as_env,
10
10
  :only_sensitive
11
11
 
12
- def initialize(options = {})
13
- super
12
+ def initialize(as_env: nil, only_sensitive: nil, **args)
13
+ super(**args)
14
14
 
15
- self.as_env = options[:as_env]
16
- self.only_sensitive = options[:only_sensitive]
15
+ self.as_env = as_env
16
+ self.only_sensitive = only_sensitive
17
17
  end
18
18
 
19
19
  def call
20
20
  if as_env
21
21
  settings.to_s(pair_separator: "\n")
22
22
  else
23
- PP.
24
- pp(settings.to_hash, StringIO.new, 60).
25
- string.
26
- chomp
23
+ PP
24
+ .pp(settings.to_hash, StringIO.new, 60)
25
+ .string
26
+ .chomp
27
27
  end
28
28
  end
29
29
 
@@ -5,8 +5,8 @@ require 'chamber/commands/base'
5
5
  module Chamber
6
6
  module Commands
7
7
  class Sign < Chamber::Commands::Base
8
- def initialize(options = {})
9
- super(options.merge(namespaces: ['*']))
8
+ def initialize(**args)
9
+ super(**args.merge(namespaces: ['*']))
10
10
  end
11
11
 
12
12
  def call
@@ -5,8 +5,8 @@ require 'chamber/commands/base'
5
5
  module Chamber
6
6
  module Commands
7
7
  class Verify < Chamber::Commands::Base
8
- def initialize(options = {})
9
- super(options.merge(namespaces: ['*']))
8
+ def initialize(**args)
9
+ super(**args.merge(namespaces: ['*']))
10
10
  end
11
11
 
12
12
  def call
@@ -8,16 +8,20 @@ class Configuration
8
8
  :decryption_keys,
9
9
  :encryption_keys,
10
10
  :files,
11
- :namespaces
11
+ :namespaces,
12
+ :rootpath,
13
+ :signature_name
12
14
 
13
- def initialize(options = {})
14
- options = ContextResolver.resolve(options)
15
+ def initialize(**args)
16
+ options = ContextResolver.resolve(**args)
15
17
 
16
18
  self.basepath = options.fetch(:basepath)
17
19
  self.namespaces = options.fetch(:namespaces)
18
20
  self.decryption_keys = options.fetch(:decryption_keys)
19
21
  self.encryption_keys = options.fetch(:encryption_keys)
20
22
  self.files = options.fetch(:files)
23
+ self.rootpath = options.fetch(:rootpath)
24
+ self.signature_name = options.fetch(:signature_name)
21
25
  end
22
26
 
23
27
  def to_hash
@@ -27,6 +31,7 @@ class Configuration
27
31
  encryption_keys: encryption_keys,
28
32
  files: files,
29
33
  namespaces: namespaces,
34
+ signature_name: signature_name,
30
35
  }
31
36
  end
32
37
  end
@@ -3,7 +3,6 @@
3
3
  require 'pathname'
4
4
  require 'socket'
5
5
 
6
- require 'chamber/core_ext/hash'
7
6
  require 'chamber/keys/decryption'
8
7
  require 'chamber/keys/encryption'
9
8
 
@@ -11,11 +10,11 @@ module Chamber
11
10
  class ContextResolver
12
11
  attr_accessor :options
13
12
 
14
- def initialize(options = {})
15
- self.options = options.transform_keys(&:to_sym)
13
+ def initialize(**args)
14
+ self.options = args
16
15
  end
17
16
 
18
- # rubocop:disable Metrics/AbcSize, Metrics/LineLength
17
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Layout/LineLength
19
18
  def resolve
20
19
  options[:rootpath] ||= Pathname.pwd
21
20
  options[:rootpath] = Pathname.new(options[:rootpath])
@@ -43,12 +42,14 @@ class ContextResolver
43
42
  options[:basepath] + 'settings',
44
43
  ]
45
44
 
45
+ options[:signature_name] = options[:signature_name]
46
+
46
47
  options
47
48
  end
48
- # rubocop:enable Metrics/AbcSize, Metrics/LineLength
49
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Layout/LineLength
49
50
 
50
- def self.resolve(options = {})
51
- new(options).resolve
51
+ def self.resolve(**args)
52
+ new(**args).resolve
52
53
  end
53
54
 
54
55
  protected
@@ -5,7 +5,7 @@ require 'base64'
5
5
  module Chamber
6
6
  module EncryptionMethods
7
7
  class Ssl
8
- BASE64_STRING_PATTERN = %r{[A-Za-z0-9\+\/#]*\={0,2}}.freeze
8
+ BASE64_STRING_PATTERN = %r{[A-Za-z0-9+/#]*={0,2}}.freeze
9
9
  LARGE_DATA_STRING_PATTERN = /
10
10
  \A
11
11
  (#{BASE64_STRING_PATTERN})
@@ -16,12 +16,12 @@ class Ssl
16
16
  \z
17
17
  /x.freeze
18
18
 
19
- def self.encrypt(_key, value, encryption_keys)
20
- value = YAML.dump(value)
21
- cipher = OpenSSL::Cipher.new('AES-128-CBC')
19
+ def self.encrypt(_key, value, encryption_keys) # rubocop:disable Metrics/AbcSize
20
+ value = YAML.dump(value)
21
+ cipher = OpenSSL::Cipher.new('AES-128-CBC')
22
22
  cipher.encrypt
23
23
  symmetric_key = cipher.random_key
24
- iv = cipher.random_iv
24
+ iv = cipher.random_iv
25
25
 
26
26
  # encrypt all data with this key and iv
27
27
  encrypted_data = cipher.update(value) + cipher.final
@@ -35,24 +35,24 @@ class Ssl
35
35
  Base64.strict_encode64(encrypted_data)
36
36
  end
37
37
 
38
- def self.decrypt(key, value, decryption_keys)
38
+ def self.decrypt(key, value, decryption_keys) # rubocop:disable Metrics/AbcSize
39
39
  if decryption_keys.nil?
40
40
  value
41
41
  else
42
- key, iv, decoded_string = value.
43
- match(LARGE_DATA_STRING_PATTERN).
44
- captures.
45
- map do |part|
42
+ key, iv, decoded_string = value
43
+ .match(LARGE_DATA_STRING_PATTERN)
44
+ .captures
45
+ .map do |part|
46
46
  Base64.strict_decode64(part)
47
47
  end
48
- key = decryption_keys.private_decrypt(key)
48
+ key = decryption_keys.private_decrypt(key)
49
49
 
50
50
  cipher_dec = OpenSSL::Cipher.new('AES-128-CBC')
51
51
 
52
52
  cipher_dec.decrypt
53
53
 
54
54
  cipher_dec.key = key
55
- cipher_dec.iv = iv
55
+ cipher_dec.iv = iv
56
56
 
57
57
  begin
58
58
  unencrypted_value = cipher_dec.update(decoded_string) + cipher_dec.final
@@ -13,7 +13,8 @@ module Chamber
13
13
  class File < Pathname
14
14
  attr_accessor :namespaces,
15
15
  :decryption_keys,
16
- :encryption_keys
16
+ :encryption_keys,
17
+ :signature_name
17
18
 
18
19
  ###
19
20
  # Internal: Creates a settings file representing a path to a file on the
@@ -42,12 +43,13 @@ class File < Pathname
42
43
  # Chamber::File.new path: '/tmp/settings.yml'
43
44
  # # => <Chamber::File>
44
45
  #
45
- def initialize(options = {})
46
- self.namespaces = options[:namespaces] || {}
47
- self.decryption_keys = options[:decryption_keys] || {}
48
- self.encryption_keys = options[:encryption_keys] || {}
46
+ def initialize(path:, namespaces: {}, decryption_keys: {}, encryption_keys: {}, signature_name: nil)
47
+ self.namespaces = namespaces
48
+ self.decryption_keys = decryption_keys
49
+ self.encryption_keys = encryption_keys
50
+ self.signature_name = signature_name
49
51
 
50
- super options.fetch(:path)
52
+ super path
51
53
  end
52
54
 
53
55
  ###
@@ -76,7 +78,7 @@ class File < Pathname
76
78
  encryption_keys: encryption_keys)
77
79
  end
78
80
 
79
- # rubocop:disable Metrics/LineLength
81
+ # rubocop:disable Layout/LineLength, Metrics/AbcSize
80
82
  def secure
81
83
  insecure_settings = to_settings.insecure.to_flattened_name_hash
82
84
  secure_settings = to_settings.insecure.secure.to_flattened_name_hash
@@ -88,14 +90,14 @@ class File < Pathname
88
90
  escaped_name = Regexp.escape(name_pieces.last)
89
91
  escaped_value = Regexp.escape(value)
90
92
 
91
- file_contents.
92
- sub!(
93
+ file_contents
94
+ .sub!(
93
95
  /^(\s*)#{secure_prefix_pattern}#{escaped_name}(\s*):(\s*)['"]?#{escaped_value}['"]?$/,
94
96
  "\\1#{secure_prefix}#{name_pieces.last}\\2:\\3#{secure_value}",
95
97
  )
96
98
 
97
- file_contents.
98
- sub!(
99
+ file_contents
100
+ .sub!(
99
101
  /^(\s*)#{secure_prefix_pattern}#{escaped_name}(\s*):(\s*)\|((?:\n\1\s{2}.*)+)/,
100
102
  "\\1#{secure_prefix}#{name_pieces.last}\\2:\\3#{secure_value}",
101
103
  )
@@ -103,7 +105,7 @@ class File < Pathname
103
105
 
104
106
  write(file_contents)
105
107
  end
106
- # rubocop:enable Metrics/LineLength
108
+ # rubocop:enable Layout/LineLength, Metrics/AbcSize
107
109
 
108
110
  def sign
109
111
  signature_key_contents = decryption_keys[:signature]
@@ -111,7 +113,7 @@ class File < Pathname
111
113
  fail ArgumentError, 'You asked to sign your settings files but no signature key was found. Run `chamber init --signature` to generate one.' \
112
114
  unless signature_key_contents
113
115
 
114
- signature = Files::Signature.new(to_s, read, signature_key_contents)
116
+ signature = Files::Signature.new(to_s, read, signature_key_contents, signature_name)
115
117
 
116
118
  signature.write
117
119
  end
@@ -122,7 +124,7 @@ class File < Pathname
122
124
  fail ArgumentError, 'You asked to verify your settings files but no signature key was found. Run `chamber init --signature` to generate one.' \
123
125
  unless signature_key_contents
124
126
 
125
- signature = Files::Signature.new(to_s, read, signature_key_contents)
127
+ signature = Files::Signature.new(to_s, read, signature_key_contents, signature_name)
126
128
 
127
129
  signature.verify
128
130
  end