muchkeys 0.3.7 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ad2ab8e2bfa75fd797b36be39c1a8184ce7484e
4
- data.tar.gz: 3f21dc427fb84b6f2d7b23238e1200d5578620bc
3
+ metadata.gz: 93107ba506bcfe9a978c302c6da035e01adb775b
4
+ data.tar.gz: e868c16a3959356cf283f12c97db3ea29e09a6ab
5
5
  SHA512:
6
- metadata.gz: 64c72caa89877fb1e9b091efe521b45378fb7b5da1ae6133e4f976252b398d2a54e0a7afda1cbe6cf0c8f8b8215eab4e0ab84fc86e527185e22df6b8af9ee812
7
- data.tar.gz: 6456d2da5d388abc0b095af75dcd87237415659a6db16cbeaef92e5b33dbf246d61dcb28415631869e9996e87a8a36827da1d70554531b6959e5cb3c81509ea7
6
+ metadata.gz: 736c887f3c13d2b1061492a5dee846233ee13c5a5e87973e7914bd7828a4c467fece8cf15b8cfc6bcecdca6418bb67bc89182170ade846c288825355b0b71657
7
+ data.tar.gz: b93afaebd935a0a55c2008ff9d164dceca7c6ad71711a743dc93257a05a3e6dc289596918677ec0679de00a67c1b69e262c673af9797804b7472b397f2d184a6
@@ -0,0 +1 @@
1
+ 2.3.1
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in muchkeys.gemspec
4
4
  gemspec
5
+
6
+ gem 'pry-byebug'
@@ -2,5 +2,4 @@
2
2
 
3
3
  require "muchkeys"
4
4
 
5
- cli = MuchKeys::CLI.new ARGV
6
- cli.run
5
+ MuchKeys::CLI.start
@@ -4,7 +4,6 @@ require "muchkeys/configuration"
4
4
  require "muchkeys/secret"
5
5
  require "muchkeys/key_validator"
6
6
  require "muchkeys/cli"
7
- require "muchkeys/cli/validator"
8
7
 
9
8
  require "net/http"
10
9
 
@@ -1,144 +1,51 @@
1
- require "slop"
1
+ require 'thor'
2
2
 
3
3
  module MuchKeys
4
- class CLI
5
- attr_reader :mode
4
+ class CLI < Thor
5
+ include Thor::Actions
6
6
 
7
- def initialize(arguments)
8
- # I'd like to not be doing this kind of check
9
- # But this is tricky because we need to know
10
- # later if help was invoked so we don't execute run with blank options.
11
- @cli_should_exit = false
12
- parsed = parse_options(arguments)
13
- end
14
-
15
- def parse_options(arguments)
16
- @opts = Slop.parse arguments do |o|
17
- o.bool "-e", "--encrypt", "Encrypt keys from a file to put in consul."
18
- o.bool "-d", "--decrypt", "Decrypt keys from consul."
19
- o.bool "-p", "--plain", "Fetch plaintext key from consul."
7
+ map %w[--version -v] => :__version
20
8
 
21
- o.string "--consul_url", "Consul server http address", default: "http://localhost:8500"
22
- o.string "--private_key", "Location of your private key"
23
- o.string "--public_key", "Location of your public key"
9
+ class_option :consule_url, type: :string, default: 'http://localhost:8500'
24
10
 
25
- o.string "-f", "--file", "File to encrypt"
26
- o.string "-c", "--consul_key", "Consul key to decrypt"
27
-
28
- o.bool "-h", "--help", "Shows usage"
29
- o.bool "-v", "--version", "Prints the version number"
30
- end
11
+ desc "encrypt FILE", "encrypt keys from a file to put in consul"
12
+ method_option :public_key, type: :string, required: true
13
+ def encrypt(file)
14
+ say MuchKeysExecutor.encrypt(file, options[:public_key])
31
15
  end
32
16
 
33
- def set_primary_mode(options=@opts)
34
- MuchKeys::CLI::Validator.validate_primary_mode_option(options)
35
- @mode = select_primary_mode(options)
17
+ desc "decrypt KEY", "decrypt keys from consul"
18
+ method_option :public_key, type: :string, required: true
19
+ method_option :private_key, type: :string, required: true
20
+ def decrypt(consul_key)
21
+ say MuchKeysExecutor.decrypt(consul_key, options[:public_key], options[:private_key])
36
22
  end
37
23
 
38
- def configure_muchkeys(options=@opts)
39
- MuchKeys.configure do |config|
40
- config.consul_url = options[:consul_url]
41
- config.public_key = options[:public_key]
42
- config.private_key = options[:private_key]
43
- end
24
+ desc "fetch KEY", "fetch plaintext key from consul"
25
+ def fetch(consul_key)
26
+ say MuchKeysExecutor.fetch(consul_key)
44
27
  end
45
28
 
46
- # this guy figures out the appropriate action to take given CLI options
47
- def run
48
-
49
- check_for_early_exit_actions
50
- return if @cli_should_exit
51
-
52
- begin
53
- set_primary_mode
54
- rescue MuchKeys::CLIOptionsError => e
55
- puts e.message
56
- puts @opts
57
- end
58
-
59
- return if @cli_should_exit
60
-
61
- configure_muchkeys
62
-
63
- if @opts[:encrypt]
64
- options = { file: @opts[:file], public_key: @opts[:public_key] }
65
- validation = MuchKeys::CLI::Validator.validate_encrypt_options(options)
66
-
67
- if validation.valid?
68
- encrypt(@opts[:file], @opts[:public_key])
69
- else
70
- puts validation.errors
71
- return
72
- end
73
- elsif @opts[:decrypt]
74
- options = { consul_key: @opts[:consul_key], public_key: @opts[:public_key], private_key: @opts[:private_key] }
75
- validation = MuchKeys::CLI::Validator.validate_decrypt_options(options)
76
-
77
- if validation.valid?
78
- decrypt(@opts[:consul_key], @opts[:public_key], @opts[:private_key])
79
- else
80
- puts validation.errors
81
- return
82
- end
83
- elsif @opts[:plain]
84
- options = { consul_key: @opts[:consul_key] }
85
- validation = MuchKeys::CLI::Validator.validate_plain_options(options)
86
-
87
- if validation.valid?
88
- plain(@opts[:consul_key])
89
- else
90
- puts validation.errors
91
- return
92
- end
93
- end
94
-
29
+ desc "--version", "Print the version"
30
+ def __version
31
+ say MuchKeys::VERSION
95
32
  end
96
33
 
97
- def encrypt(file, public_key)
98
- string_to_encrypt = File.read(file)
99
- puts secret_adapter.encrypt_string(string_to_encrypt, public_key)
100
- end
101
-
102
- def decrypt(consul_key, public_key, private_key)
103
- puts MuchKeys.fetch_key(consul_key, public_key:public_key, private_key:private_key)
104
- end
105
-
106
- def plain(consul_key)
107
- puts MuchKeys.fetch_key(consul_key)
108
- end
109
-
110
- def print_version_number
111
- puts MuchKeys::VERSION
112
- @cli_should_exit = true
113
- end
34
+ module MuchKeysExecutor
35
+ extend self
114
36
 
115
- def print_help
116
- # this is how the slop gem prints help
117
- puts @opts
118
- @cli_should_exit = true
119
- end
120
-
121
-
122
- private
123
- def select_primary_mode(options)
124
- possible_primary_modes = { encrypt: options[:encrypt], decrypt: options[:decrypt], plain: options[:plain] }
125
- primary_mode = possible_primary_modes.select {|k,v| v == true } # validation has already happened, we can access modes safely
126
- primary_mode.keys.first
127
- end
128
-
129
- def secret_adapter
130
- MuchKeys::Secret
131
- end
37
+ def encrypt(file, public_key)
38
+ string_to_encrypt = File.read(file)
39
+ MuchKeys::Secret.encrypt_string(string_to_encrypt, public_key)
40
+ end
132
41
 
133
- def check_for_early_exit_actions
134
- if @opts[:help]
135
- print_help
42
+ def decrypt(consul_key, public_key, private_key)
43
+ MuchKeys.fetch_key(consul_key, public_key: public_key, private_key:private_key)
136
44
  end
137
45
 
138
- if @opts[:version]
139
- print_version_number
46
+ def fetch(consul_key)
47
+ MuchKeys.fetch_key(consul_key)
140
48
  end
141
49
  end
142
-
143
50
  end
144
51
  end
@@ -42,7 +42,6 @@ class MuchKeys::Secret
42
42
  OpenSSL::PKCS7.new(val).decrypt(key, cert)
43
43
  end
44
44
 
45
-
46
45
  private
47
46
 
48
47
  def read_ssl_key(file_name)
@@ -1,3 +1,3 @@
1
1
  module MuchKeys
2
- VERSION = "0.3.7"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -19,16 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- # slop 4 was a rewrite and it breaks a few gems:
23
- # guard / pry. This is sad for development but slop4 is better than slop3.
24
- spec.add_runtime_dependency "slop", "~> 4.2"
22
+ spec.add_runtime_dependency "thor"
25
23
 
26
24
  spec.add_development_dependency "bundler", "~> 1.10"
27
25
  spec.add_development_dependency "rake", "~> 10.0"
28
26
  spec.add_development_dependency "rspec", "~> 3.3"
29
27
  spec.add_development_dependency "webmock", "~> 1.20"
30
28
  spec.add_development_dependency "vcr", "~> 2.9"
31
-
32
- # slop 4 really, really needs this version of pry since they vendored it
33
- spec.add_development_dependency "pry", '=0.10.3'
29
+ spec.add_development_dependency "aruba", "~> 0.14.2"
34
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muchkeys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat O'Brien
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-09-12 00:00:00.000000000 Z
12
+ date: 2016-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: slop
15
+ name: thor
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4.2'
20
+ version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '4.2'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -96,19 +96,19 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '2.9'
98
98
  - !ruby/object:Gem::Dependency
99
- name: pry
99
+ name: aruba
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '='
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: 0.10.3
104
+ version: 0.14.2
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '='
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: 0.10.3
111
+ version: 0.14.2
112
112
  description: MuchKeys can handle app configuration and appsecrets
113
113
  email:
114
114
  - pobrien@goldstar.com
@@ -120,6 +120,7 @@ extra_rdoc_files: []
120
120
  files:
121
121
  - ".gitignore"
122
122
  - ".rspec"
123
+ - ".ruby-version"
123
124
  - ".travis.yml"
124
125
  - Gemfile
125
126
  - Guardfile
@@ -130,8 +131,6 @@ files:
130
131
  - exe/muchkeys
131
132
  - lib/muchkeys.rb
132
133
  - lib/muchkeys/cli.rb
133
- - lib/muchkeys/cli/validation.rb
134
- - lib/muchkeys/cli/validator.rb
135
134
  - lib/muchkeys/configuration.rb
136
135
  - lib/muchkeys/errors.rb
137
136
  - lib/muchkeys/key_validator.rb
@@ -158,9 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
157
  version: '0'
159
158
  requirements: []
160
159
  rubyforge_project:
161
- rubygems_version: 2.2.2
160
+ rubygems_version: 2.5.1
162
161
  signing_key:
163
162
  specification_version: 4
164
163
  summary: MuchKeys fetches keys from the ENV and then falls back to consul
165
164
  test_files: []
166
- has_rdoc:
@@ -1,17 +0,0 @@
1
- module MuchKeys
2
- class CLI
3
-
4
- class Validation
5
- attr_accessor :errors
6
-
7
- def initialize
8
- @errors = []
9
- end
10
-
11
- def valid?
12
- errors.length < 1
13
- end
14
- end
15
-
16
- end
17
- end
@@ -1,66 +0,0 @@
1
- require_relative "../errors"
2
- require_relative "./validation"
3
-
4
- class MuchKeys::CLI::Validator
5
-
6
- def self.validate_primary_mode_option(options)
7
- raise MuchKeys::CLIOptionsError, primary_mode_error_message unless options_has_one_mode?(options)
8
- end
9
-
10
- def self.validate_encrypt_options(options)
11
- validation = MuchKeys::CLI::Validation.new
12
- if !options[:file] || !options[:public_key]
13
- validation.errors << "--decrypt needs the --file and --public_key set."
14
- end
15
-
16
- validation
17
- end
18
-
19
- def self.validate_decrypt_options(options)
20
- validation = MuchKeys::CLI::Validation.new
21
- if options[:consul_key] && options[:public_key] && options[:private_key]
22
- validate_automatic_certificate(validation, options)
23
- else
24
- validation.errors << "--decrypt needs the --consul_key, --public_key and --private_key set."
25
- end
26
-
27
- validation
28
- end
29
-
30
- def self.validate_automatic_certificate(chained_validation, options)
31
- # i won't mutate chained_validation on principle
32
- validation = MuchKeys::CLI::Validation.new
33
- validation.errors = chained_validation.errors.dup
34
- key_name = options[:consul_key]
35
-
36
- if !secret_adapter.auto_certificates_exist_for_key?(key_name)
37
- certfile_expected = secret_adapter.certfile_name(key_name)
38
- validation.errors << "--decrypt needs the --public_key option passed or a PEM file needs to be at #{certfile_expected}." if !options[:public_key]
39
- validation.errors << "--decrypt needs the --private_key option passed or a PEM file needs to be at #{certfile_expected}." if !options[:private_key]
40
- end
41
-
42
- validation
43
- end
44
-
45
- def self.validate_plain_options(options)
46
- validation = MuchKeys::CLI::Validation.new
47
- if !options[:consul_key]
48
- validation.errors << "--plain needs the --consul_key option passed."
49
- end
50
-
51
- validation
52
- end
53
-
54
- def self.options_has_one_mode?(options)
55
- [ options[:encrypt], options[:decrypt], options[:plain] ].count(true) == 1
56
- end
57
-
58
- def self.primary_mode_error_message
59
- "You must pass only one and at least one of the following flags: --encrypt, --decrypt, or --plain"
60
- end
61
-
62
- def self.secret_adapter
63
- MuchKeys::Secret
64
- end
65
-
66
- end