certstash-cli 0.0.1

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: b6835f9bda029dd7202350e8e9b5553b3f49b02d
4
+ data.tar.gz: 4ca68328ee19f8b59bd8fff3cf5f2b4b4a8672fd
5
+ SHA512:
6
+ metadata.gz: c0d6c6880e2c94a33cc18bfc6ae0332617033c9092243073a259779e9f0d557533c2dcd9ef6bb7dd861a62e7ab3d67d6b9a77a65c0ddfc88ccdef5258627693d
7
+ data.tar.gz: 004b00ff825863c39462ee1d50cd0cdbfff77bb50d0a00d7d8586650ca5595d068ba0917be9afe1113758150d93329e2eae99641c909e48aa9c676d89fe0e559
data/README.rdoc ADDED
@@ -0,0 +1,38 @@
1
+ = certstash-cli
2
+
3
+ certstash-cli manages the creation, storage, and retrieval of SSL keys and CRTs.
4
+
5
+
6
+ = Running Tests
7
+
8
+ #### CLI commands
9
+
10
+ ##### Help
11
+ ```bash
12
+ $ bundle exec bin/certstash-cli gen_csr help
13
+ $ bundle exec bin/certstash-cli gen_pkey help
14
+ ```
15
+
16
+ ##### Examples
17
+ ```bash
18
+ $ bundle exec certstash-cli gen_pkey --vault_name=rwu1ee01-certificates --item_name=rewards-ui-ee.cdc.gci.com --admins=admin1,admin2,admin3 --query=name:rwu1ee01ngxlb*
19
+ $ bundle exec bin/certstash-cli gen_csr --vault_name=rwu1ee01-certificates --item_name=rewards-ui-ee.cdc.gci.com
20
+ ```
21
+
22
+ #### Integration tests
23
+ ```bash
24
+ $ bundle exec cucumber
25
+ ```
26
+ :include:certstash-cli.rdoc
27
+
28
+ #### Debugging
29
+
30
+ To see backtraces for CLI errors, you need only set an environment variable.
31
+ ```bash
32
+ $ env GLI_DEBUG=true bin/gli foo
33
+ ```
34
+
35
+ The same method works for other system test.
36
+ ```bash
37
+ $ env GLI_DEBUG=true bundle exec cucumber
38
+ ```
data/bin/certstash-cli ADDED
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'awesome_print'
4
+ require 'cert_stash'
5
+ require 'certstash-cli/certstash_cli_helper'
6
+ begin # XXX: Remove this begin/rescue before distributing your app
7
+ require 'certstash-cli'
8
+ rescue LoadError
9
+ STDERR.puts 'In development, you need to use \
10
+ `bundle exec bin/certstash-cli` to run your app'
11
+ STDERR.puts 'At install-time, RubyGems will make sure lib, etc. \
12
+ are in the load path'
13
+ STDERR.puts 'Feel free to remove this message from bin/certstash-cli now'
14
+ exit 64
15
+ end
16
+
17
+ include GLI::App
18
+
19
+ program_desc 'certstash-cli manages the creation, storage, and '\
20
+ 'retrieval of SSL keys and CRTs.'
21
+
22
+ version CertstashCli::VERSION
23
+
24
+ subcommand_option_handling :normal
25
+ arguments :strict
26
+
27
+ desc 'Be verbose'
28
+ switch [:v, :verbose]
29
+
30
+ # accepts are global
31
+
32
+ # accept arrays as parameters
33
+ accept Array do |value|
34
+ value.split(/,/).map(&:strip)
35
+ end
36
+
37
+ # accept hashes as parameters
38
+ accept(Hash) do |value|
39
+ result = {}
40
+ value.split(/,/).each do |pair|
41
+ k, v = pair.split(/:/)
42
+ result[k] = v
43
+ end
44
+ result
45
+ end
46
+
47
+ # GLOBAL CHEF CONFIG PARAM
48
+ # flag [:C, :chef_config, 'chef-config'],
49
+ # arg: 'chef-config',
50
+ # required: true,
51
+ # default_value: File.join(ENV['HOME'], '.chef/knife.rb'),
52
+ # arg_name: 'chef-config',
53
+ # type: String,
54
+ # desc: 'Path to your Chef knife.rb. Defaults to ~/.chef/knife.rb
55
+
56
+ # 1. Validate that the following options are present:
57
+ # a. --vault
58
+ # b. --item
59
+ # c. --admins
60
+ # d. --query
61
+ desc 'Generate a Private Key for a chef vault and item.'
62
+
63
+ command :gen_pkey do |c|
64
+ c.desc 'Generate Private Key'
65
+
66
+ # flags are defined in certstash_cli_helper
67
+ c = fetch_pkey_flags(c)
68
+
69
+ # c.switch [:d,:dry]
70
+ c.action do |_global_options, options, _args|
71
+ ######## REMOVE ME. For debugging purposes only ############
72
+ # output_command_args(global_options, options, args)
73
+
74
+ help_now!('vault name is required.') if options[:vault_name].nil?
75
+ help_now!('item name is required.') if options[:item_name].nil?
76
+ help_now!('admins is required.') if options[:admins].nil?
77
+ help_now!('query is required.') if options[:query].nil?
78
+
79
+ # Create an instance of CertStash::ChefVaultFile and populate the vault_name
80
+ # and item_name attributes in that instance
81
+
82
+ vault_file = CertStash::ChefVaultFile.new(
83
+ vault_name: options[:vault_name],
84
+ item_name: options[:item_name]
85
+ )
86
+
87
+ # Create an instance of CertStash::Command::StashRsaPrivateKey and populate
88
+ # the chef_vault_file attribute with the instance of ChefVaultFile
89
+
90
+ cmd = CertStash::Command::StashRsaPrivateKey.new(
91
+ file_name: options[:item_name],
92
+ bit_length: 2048,
93
+ chef_vault_file: vault_file
94
+ )
95
+
96
+ # Show the user what happened
97
+ $stderr.puts "Creating key for #{options[:item_name]} to vault "\
98
+ "#{options[:vault_name]}/#{options[:item_name]}"
99
+
100
+ # split the admins option string in to an array
101
+ # on the instance of StashRsaPrivateKey call execute,
102
+ # passing the 'admins' array and the 'query' option from the user
103
+ admins = options[:admins].split(',')
104
+ cmd.execute(query, admins)
105
+ end
106
+ end
107
+
108
+ desc 'Generate a secure certificate'
109
+ long_desc %(
110
+ Genrate a new secure certificate
111
+ )
112
+ command :gen_csr do |c|
113
+ # flags are defined in certstash_cli_helper
114
+ c = fetch_csr_flags(c)
115
+
116
+ c.action do |_global_options, options, _args|
117
+ puts 'gen_csr command ran'
118
+
119
+ ######## REMOVE ME. For debugging purposes only ############
120
+ # output_command_args(global_options, options, args)
121
+
122
+ help_now!('Vault name is required.') if options[:vault_name].nil?
123
+ help_now!('Item name is required.') if options[:item_name].nil?
124
+ help_now!('Common name is required.') if options[:common_name].empty?
125
+
126
+ # Create an instance of CertStash::ChefVaultFile and populate
127
+ # the vault_name and item_name attributes in that instance
128
+
129
+ vault_file = CertStash::ChefVaultFile.new(
130
+ vault_name: options[:vault_name],
131
+ item_name: options[:item_name]
132
+ )
133
+
134
+ # Create an instance of R509::Subject, passing the values of
135
+ # options.common_name, options.country, options.state, options.locale,
136
+ # options.organization, options.organizational_unit to the constructor as
137
+ # hash values to the corresponding symbolic keys: :CN, :C, :ST, :L, :O, :OU
138
+
139
+ subject = R509::Subject.new(
140
+ CN: options[:common_name],
141
+ C: options[:country],
142
+ ST: options[:state],
143
+ L: options[:locale],
144
+ O: options[:organization],
145
+ OU: options[:organizational_unit]
146
+ )
147
+
148
+ # Create an instance of CertStash::Command::GenerateCsr, and populate
149
+ # the following attributes:
150
+ # a. chef_vault_file with the CertStash::ChefVaultFile
151
+ # b. subject with the R509::Subject instance
152
+ # c. san_names with the value of the --san option from the user, if any
153
+
154
+ cmd = CertStash::Command::GenerateCsr.new(
155
+ chef_vault_file: vault_file,
156
+ subject: subject
157
+ )
158
+ cmd.san_names = options[:san].split(',') || []
159
+
160
+ # Call execute on the csr instance and send the output to std output (puts)
161
+ begin
162
+ csr = md.execute
163
+
164
+ puts "Creating CSR for #{options[:common_name]} \
165
+ at ./csrs/#{options[:common_name]}.csr"
166
+
167
+ File.open("./csrs/#{options[:common_name]}.csr", 'w+') do |f|
168
+ f.puts csr
169
+ end
170
+ rescue Exception => e
171
+ puts "Faild to create CSR for #{options[:common_name]} \
172
+ at ./csrs/#{options[:common_name]}.csr"
173
+ puts e.message
174
+ end
175
+ end
176
+ end
177
+
178
+ # pre do |global,command,options,args|
179
+ # puts 'Executing PRE hook....'
180
+ # # Pre logic here
181
+ # # Return true to proceed; false to abort and not call the
182
+ # # chosen command
183
+ # # Use skips_pre before a command to skip this block
184
+ # # on that command only
185
+ # true
186
+ # end
187
+ #
188
+ # on_error do |exception|
189
+ # # Error logic here
190
+ # # return false to skip default error handling
191
+ # true
192
+ # end
193
+
194
+ exit run(ARGV)
@@ -0,0 +1,5 @@
1
+ = certstash-cli
2
+
3
+ Generate this with
4
+ certstash-cli rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,4 @@
1
+ require 'certstash-cli/version.rb'
2
+
3
+ # Add requires for other files you add to your project here, so
4
+ # you just need to require this one file in your bin file
@@ -0,0 +1,77 @@
1
+ def output_command_args(global_options, options, args)
2
+ puts '*****************'
3
+ puts 'gen_pkey command ran'
4
+ puts 'args: '
5
+ ap args
6
+ puts 'options: '
7
+ ap options
8
+ puts 'global_options: '
9
+ ap global_options
10
+ puts '*****************'
11
+ end
12
+
13
+
14
+ # env GLI_DEBUG=true certstash-cli gen_csr :t rwu1ee01-certificates, --item_name=rewards-ui-ee.cdc.gci.com, --common_name=rewards-ui-st.cdc.gci.com, --country=US, --state=OR, --locale=en-US, --organization=GCI, --organizational_unit=CD
15
+ def fetch_csr_flags(command) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
16
+ command.desc 'Vault Name'
17
+ command.default_value nil
18
+ command.flag [:t, :vault_name]
19
+
20
+ command.desc 'Item Name'
21
+ command.default_value nil
22
+ command.flag [:i, :item_name]
23
+
24
+ command.desc 'Common Name'
25
+ command.default_value ''
26
+ command.flag [:cn, :common_name]
27
+
28
+ command.desc 'Country'
29
+ command.default_value 'US'
30
+ command.flag [:c, :country]
31
+
32
+ command.desc 'State'
33
+ command.default_value ''
34
+ command.flag [:s, :state]
35
+
36
+ command.desc 'Locale'
37
+ command.default_value 'en-US'
38
+ command.flag [:l, :locale]
39
+
40
+ command.desc 'Organization'
41
+ command.default_value ''
42
+ command.flag [:o, :organization]
43
+
44
+ command.desc 'Organizational Unit'
45
+ command.default_value ''
46
+ command.flag [:ou, :organizational_unit]
47
+
48
+ command.desc 'San Names'
49
+ command.default_value []
50
+ command.flag [:sn, :san], type: Array
51
+
52
+ command
53
+ end
54
+
55
+ def fetch_pkey_flags(command) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
56
+ command.desc 'Vault Name'
57
+ command.default_value nil
58
+ command.arg_name 'vault'
59
+ command.flag [:t, :vault_name]
60
+
61
+ command.desc 'Item Name'
62
+ command.default_value nil
63
+ command.arg_name 'item'
64
+ command.flag [:i, :item_name]
65
+
66
+ command.desc 'Admins'
67
+ command.default_value ''
68
+ command.arg_name 'admins'
69
+ command.flag [:a, :admins], type: Array
70
+
71
+ command.desc 'Query'
72
+ command.default_value nil
73
+ command.arg_name 'query'
74
+ command.flag [:q, :query]
75
+
76
+ command
77
+ end
@@ -0,0 +1,3 @@
1
+ module CertstashCli
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: certstash-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Danny McAlerney
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cert_stash
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cucumber
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: aruba
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: gli
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 2.14.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 2.14.0
139
+ description:
140
+ email: dmcalerney@gci.com
141
+ executables:
142
+ - certstash-cli
143
+ extensions: []
144
+ extra_rdoc_files:
145
+ - README.rdoc
146
+ - certstash-cli.rdoc
147
+ files:
148
+ - README.rdoc
149
+ - bin/certstash-cli
150
+ - certstash-cli.rdoc
151
+ - lib/certstash-cli.rb
152
+ - lib/certstash-cli/certstash_cli_helper.rb
153
+ - lib/certstash-cli/version.rb
154
+ homepage: http://source.gci.com/projects/CD/repos/cd-certstash-cli
155
+ licenses: []
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options:
159
+ - "--title"
160
+ - certstash-cli
161
+ - "--main"
162
+ - README.rdoc
163
+ - "-ri"
164
+ require_paths:
165
+ - lib
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.5
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: certstash-cli manages the creation, storage, and retrieval of SSL keys and
183
+ CRTs.
184
+ test_files: []