puppetserver-ca 1.9.5 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/lib/puppetserver/ca/action/list.rb +68 -14
- data/lib/puppetserver/ca/certificate_authority.rb +1 -1
- data/lib/puppetserver/ca/cli.rb +6 -1
- data/lib/puppetserver/ca/logger.rb +4 -0
- data/lib/puppetserver/ca/utils/http_client.rb +14 -5
- data/lib/puppetserver/ca/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7200d67071717855a415f5b10ea96e2d008eb9e758b6c1bfcf367d41be1355c4
|
4
|
+
data.tar.gz: 9b94632f35b636420a5bb80fe6e1878daefb77b4d113aed5122a116113e7ff20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82cca168aa2217dd81a68acb3acaabdaddcc06d494a783a04a27a03965110d0ca66fe5a3eee01e4d949073e4e8594d61a3203f83066e8e64b2e857344a723566
|
7
|
+
data.tar.gz: 95708d9c5f670001c8c3018cf9804fd189d44cb52bcee4e0e86665c4b8d5fd114ebb7480a6576fcffe81fd2289ba28b1fe2c61a8d610d0733b6d6f947df0f04a
|
data/README.md
CHANGED
@@ -55,6 +55,11 @@ To create a new keypair and certificate for a certname:
|
|
55
55
|
puppetserver ca generate --certname foo.example.com
|
56
56
|
```
|
57
57
|
|
58
|
+
To enable verbose mode:
|
59
|
+
```
|
60
|
+
puppetserver ca --verbose <action>
|
61
|
+
```
|
62
|
+
|
58
63
|
For more details, see the help output:
|
59
64
|
```
|
60
65
|
puppetserver ca --help
|
@@ -68,7 +73,7 @@ for more details.
|
|
68
73
|
## Development
|
69
74
|
|
70
75
|
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
71
|
-
run `rake spec` to run the tests. You can also run `bin/console` for an
|
76
|
+
run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an
|
72
77
|
interactive prompt that will allow you to experiment.
|
73
78
|
|
74
79
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
@@ -92,7 +97,7 @@ To test your changes on a VM:
|
|
92
97
|
1. To confirm that installation was successful, run `puppetserver ca --help`
|
93
98
|
|
94
99
|
### Releasing
|
95
|
-
To release a new version, run the [release pipeline](https://jenkins-
|
100
|
+
To release a new version, run the [release pipeline](https://jenkins-platform.delivery.puppetlabs.net/job/platform_puppetserver-ca_init-multijob_1.x/), which will bump the version, tag, build, and release the gem.
|
96
101
|
|
97
102
|
|
98
103
|
## Contributing & Support
|
@@ -30,6 +30,7 @@ Options:
|
|
30
30
|
BANNER
|
31
31
|
|
32
32
|
BODY = JSON.dump({desired_state: 'signed'})
|
33
|
+
VALID_FORMAT = ['text', 'json']
|
33
34
|
|
34
35
|
def initialize(logger)
|
35
36
|
@logger = logger
|
@@ -47,6 +48,9 @@ Options:
|
|
47
48
|
opts.on('--all', 'List all certificates') do |a|
|
48
49
|
parsed['all'] = true
|
49
50
|
end
|
51
|
+
opts.on('--format FORMAT', "Valid formats are: 'text' (default), 'json'") do |f|
|
52
|
+
parsed['format'] = f
|
53
|
+
end
|
50
54
|
opts.on('--certname NAME[,NAME]', Array, 'List the specified cert(s)') do |cert|
|
51
55
|
parsed['certname'] = cert
|
52
56
|
end
|
@@ -57,9 +61,15 @@ Options:
|
|
57
61
|
config = input['config']
|
58
62
|
certnames = input['certname'] || []
|
59
63
|
all = input['all']
|
64
|
+
output_format = input['format'] || "text"
|
65
|
+
|
66
|
+
unless VALID_FORMAT.include?(output_format)
|
67
|
+
Errors.handle_with_usage(@logger, ["Unknown format flag '#{output_format}'. Valid formats are '#{VALID_FORMAT.join("', '")}'."])
|
68
|
+
return 1
|
69
|
+
end
|
60
70
|
|
61
71
|
if all && certnames.any?
|
62
|
-
Errors.handle_with_usage(@logger, ['Cannot combine use of --all and --certname'])
|
72
|
+
Errors.handle_with_usage(@logger, ['Cannot combine use of --all and --certname.'])
|
63
73
|
return 1
|
64
74
|
end
|
65
75
|
|
@@ -71,24 +81,60 @@ Options:
|
|
71
81
|
puppet = Config::Puppet.parse(config)
|
72
82
|
return 1 if Errors.handle_with_usage(@logger, puppet.errors)
|
73
83
|
|
74
|
-
|
75
|
-
|
76
|
-
|
84
|
+
if certnames.any?
|
85
|
+
filter_names = lambda { |x| certnames.include?(x['name']) }
|
86
|
+
else
|
87
|
+
filter_names = lambda { |x| true }
|
88
|
+
end
|
77
89
|
|
78
90
|
all_certs = get_all_certs(puppet.settings).select { |cert| filter_names.call(cert) }
|
79
91
|
requested, signed, revoked = separate_certs(all_certs)
|
80
92
|
missing = certnames - all_certs.map { |cert| cert['name'] }
|
81
93
|
|
82
|
-
(all || certnames.any?)
|
83
|
-
|
84
|
-
|
94
|
+
if (all || certnames.any?)
|
95
|
+
output_certs_by_state(all, output_format, requested, signed, revoked, missing)
|
96
|
+
else
|
97
|
+
output_certs_by_state(all, output_format, requested)
|
98
|
+
end
|
99
|
+
|
100
|
+
return missing.any? ? 1 : 0
|
101
|
+
end
|
85
102
|
|
86
|
-
|
87
|
-
|
88
|
-
|
103
|
+
def output_certs_by_state(all, output_format, requested, signed = [], revoked = [], missing = [])
|
104
|
+
if output_format == 'json'
|
105
|
+
output_certs_json_format(all, requested, signed, revoked, missing)
|
106
|
+
else
|
107
|
+
output_certs_text_format(requested, signed, revoked, missing)
|
108
|
+
end
|
89
109
|
end
|
90
110
|
|
91
|
-
def
|
111
|
+
def output_certs_json_format(all, requested, signed, revoked, missing)
|
112
|
+
grouped_cert = {}
|
113
|
+
|
114
|
+
if all
|
115
|
+
grouped_cert = { "requested" => requested,
|
116
|
+
"signed" => signed,
|
117
|
+
"revoked" => revoked }.to_json
|
118
|
+
@logger.inform(grouped_cert)
|
119
|
+
else
|
120
|
+
grouped_cert["requested"] = requested unless requested.empty?
|
121
|
+
grouped_cert["signed"] = signed unless signed.empty?
|
122
|
+
grouped_cert["revoked"] = revoked unless revoked.empty?
|
123
|
+
grouped_cert["missing"] = missing unless missing.empty?
|
124
|
+
|
125
|
+
# If neither the '--all' flag or the '--certname' flag was passed in
|
126
|
+
# and the requested cert array is empty, we output a JSON object
|
127
|
+
# with an empty 'requested' key. Otherwise, we display
|
128
|
+
# any of the classes that are currently in grouped_cert
|
129
|
+
if grouped_cert.empty?
|
130
|
+
@logger.inform({ "requested" => requested }.to_json)
|
131
|
+
else
|
132
|
+
@logger.inform(grouped_cert.to_json)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def output_certs_text_format(requested, signed, revoked, missing)
|
92
138
|
if revoked.empty? && signed.empty? && requested.empty? && missing.empty?
|
93
139
|
@logger.inform "No certificates to list"
|
94
140
|
return
|
@@ -165,7 +211,12 @@ Options:
|
|
165
211
|
|
166
212
|
def get_all_certs(settings)
|
167
213
|
result = Puppetserver::Ca::CertificateAuthority.new(@logger, settings).get_certificate_statuses
|
168
|
-
|
214
|
+
|
215
|
+
if result
|
216
|
+
return JSON.parse(result.body)
|
217
|
+
else
|
218
|
+
return []
|
219
|
+
end
|
169
220
|
end
|
170
221
|
|
171
222
|
def parse(args)
|
@@ -176,8 +227,11 @@ Options:
|
|
176
227
|
|
177
228
|
errors_were_handled = Errors.handle_with_usage(@logger, errors, parser.help)
|
178
229
|
|
179
|
-
|
180
|
-
|
230
|
+
if errors_were_handled
|
231
|
+
exit_code = 1
|
232
|
+
else
|
233
|
+
exit_code = nil
|
234
|
+
end
|
181
235
|
return results, exit_code
|
182
236
|
end
|
183
237
|
end
|
data/lib/puppetserver/ca/cli.rb
CHANGED
@@ -64,8 +64,10 @@ BANNER
|
|
64
64
|
|
65
65
|
|
66
66
|
def self.run(cli_args = ARGV, out = STDOUT, err = STDERR)
|
67
|
-
logger = Puppetserver::Ca::Logger.new(:info, out, err)
|
68
67
|
parser, general_options, unparsed = parse_general_inputs(cli_args)
|
68
|
+
level = general_options.delete('verbose') ? :debug : :info
|
69
|
+
|
70
|
+
logger = Puppetserver::Ca::Logger.new(level, out, err)
|
69
71
|
|
70
72
|
if general_options['version']
|
71
73
|
logger.inform Puppetserver::Ca::VERSION
|
@@ -121,6 +123,9 @@ BANNER
|
|
121
123
|
opts.on('--version', 'Display the version') do |v|
|
122
124
|
parsed['version'] = true
|
123
125
|
end
|
126
|
+
opts.on('--verbose', 'Display low-level information') do |verbose|
|
127
|
+
parsed['verbose'] = true
|
128
|
+
end
|
124
129
|
|
125
130
|
opts.separator ACTION_OPTIONS
|
126
131
|
opts.separator "\nSee `puppetserver ca <action> --help` for detailed info"
|
@@ -19,7 +19,8 @@ module Puppetserver
|
|
19
19
|
|
20
20
|
# Not all connections require a client cert to be present.
|
21
21
|
# For example, when querying the status endpoint.
|
22
|
-
def initialize(settings, with_client_cert: true)
|
22
|
+
def initialize(logger, settings, with_client_cert: true)
|
23
|
+
@logger = logger
|
23
24
|
@store = make_store(settings[:localcacert],
|
24
25
|
settings[:certificate_revocation],
|
25
26
|
settings[:hostcrl])
|
@@ -50,7 +51,7 @@ module Puppetserver
|
|
50
51
|
# The Connection object should have HTTP verbs defined on it that take
|
51
52
|
# a body (and optional overrides). Returns whatever the block given returned.
|
52
53
|
def with_connection(url, &block)
|
53
|
-
request = ->(conn) { block.call(Connection.new(conn, url)) }
|
54
|
+
request = ->(conn) { block.call(Connection.new(conn, url, @logger)) }
|
54
55
|
|
55
56
|
begin
|
56
57
|
Net::HTTP.start(url.host, url.port,
|
@@ -85,29 +86,35 @@ module Puppetserver
|
|
85
86
|
# and defines methods named after HTTP verbs that are called on the
|
86
87
|
# saved connection, returning a Result.
|
87
88
|
class Connection
|
88
|
-
def initialize(net_http_connection, url_struct)
|
89
|
+
def initialize(net_http_connection, url_struct, logger)
|
89
90
|
@conn = net_http_connection
|
90
91
|
@url = url_struct
|
92
|
+
@logger = logger
|
91
93
|
end
|
92
94
|
|
93
95
|
def get(url_overide = nil, headers = {})
|
94
96
|
url = url_overide || @url
|
95
97
|
headers = DEFAULT_HEADERS.merge(headers)
|
96
98
|
|
99
|
+
@logger.debug("Making a GET request at #{url.full_url}")
|
100
|
+
|
97
101
|
request = Net::HTTP::Get.new(url.to_uri, headers)
|
98
102
|
result = @conn.request(request)
|
99
|
-
|
100
103
|
Result.new(result.code, result.body)
|
104
|
+
|
101
105
|
end
|
102
106
|
|
103
107
|
def put(body, url_override = nil, headers = {})
|
104
108
|
url = url_override || @url
|
105
109
|
headers = DEFAULT_HEADERS.merge(headers)
|
106
110
|
|
111
|
+
@logger.debug("Making a PUT request at #{url.full_url}")
|
112
|
+
|
107
113
|
request = Net::HTTP::Put.new(url.to_uri, headers)
|
108
114
|
request.body = body
|
109
115
|
result = @conn.request(request)
|
110
116
|
|
117
|
+
|
111
118
|
Result.new(result.code, result.body)
|
112
119
|
end
|
113
120
|
|
@@ -115,6 +122,8 @@ module Puppetserver
|
|
115
122
|
url = url_override || @url
|
116
123
|
headers = DEFAULT_HEADERS.merge(headers)
|
117
124
|
|
125
|
+
@logger.debug("Making a DELETE request at #{url.full_url}")
|
126
|
+
|
118
127
|
result = @conn.request(Net::HTTP::Delete.new(url.to_uri, headers))
|
119
128
|
|
120
129
|
Result.new(result.code, result.body)
|
@@ -171,7 +180,7 @@ module Puppetserver
|
|
171
180
|
# we commonly won't have one, don't require one for creating the connection.
|
172
181
|
# Additionally, we want to ensure the server is stopped before migrating the CA dir to
|
173
182
|
# avoid issues with writing to the CA dir and moving it.
|
174
|
-
self.new(settings, with_client_cert: false).with_connection(status_url) do |conn|
|
183
|
+
self.new(logger, settings, with_client_cert: false).with_connection(status_url) do |conn|
|
175
184
|
result = conn.get
|
176
185
|
if result.body == "running"
|
177
186
|
logger.err "Puppetserver service is running. Please stop it before attempting to run this command."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetserver-ca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: facter
|