Class: Puppetserver::Ca::Action::Clean
- Inherits:
-
Object
- Object
- Puppetserver::Ca::Action::Clean
- Includes:
- Utils
- Defined in:
- lib/puppetserver/ca/action/clean.rb
Constant Summary collapse
- CERTNAME_BLOCKLIST =
%w{--all --config}
- SUMMARY =
'Revoke cert(s) and remove related files from CA'
- BANNER =
<<-BANNER Usage: puppetserver ca clean [--help] puppetserver ca clean [--config] --certname NAME[,NAME] Description: Given one or more valid certnames, instructs the CA to revoke certificates matching the given certnames if they exist, and then remove files pertaining to them (keys, cert, and certificate request) over HTTPS using the local agent's PKI Options: BANNER
Class Method Summary collapse
Instance Method Summary collapse
- #clean_certs(certnames, settings) ⇒ Object
-
#initialize(logger) ⇒ Clean
constructor
A new instance of Clean.
- #parse(args) ⇒ Object
- #run(args) ⇒ Object
Constructor Details
#initialize(logger) ⇒ Clean
Returns a new instance of Clean.
51 52 53 |
# File 'lib/puppetserver/ca/action/clean.rb', line 51 def initialize(logger) @logger = logger end |
Class Method Details
.parser(parsed = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/puppetserver/ca/action/clean.rb', line 34 def self.parser(parsed = {}) parsed['certnames'] = [] OptionParser.new do |o| o. = BANNER o.on('--certname NAME[,NAME]', Array, 'One or more comma separated certnames') do |certs| parsed['certnames'] += certs end o.on('--config CONF', 'Custom path to puppet.conf') do |conf| parsed['config'] = conf end o.on('--help', 'Display this command-specific help output') do |help| parsed['help'] = true end end end |
Instance Method Details
#clean_certs(certnames, settings) ⇒ Object
102 103 104 105 |
# File 'lib/puppetserver/ca/action/clean.rb', line 102 def clean_certs(certnames, settings) ca = Puppetserver::Ca::CertificateAuthority.new(@logger, settings) ca.clean_certs(certnames) end |
#parse(args) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/puppetserver/ca/action/clean.rb', line 55 def parse(args) results = {} parser = self.class.parser(results) errors = CliParsing.parse_with_errors(parser, args) results['certnames'].each do |certname| if CERTNAME_BLOCKLIST.include?(certname) errors << " Cannot manage cert named `#{certname}` from " + "the CLI, if needed use the HTTP API directly" end end if results['certnames'].empty? errors << ' At least one certname is required to clean' end errors_were_handled = Errors.handle_with_usage(@logger, errors, parser.help) exit_code = errors_were_handled ? 1 : nil return results, exit_code end |
#run(args) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/puppetserver/ca/action/clean.rb', line 79 def run(args) certnames = args['certnames'] config = args['config'] if config errors = FileSystem.validate_file_paths(config) return 1 if Errors.handle_with_usage(@logger, errors) end puppet = Config::Puppet.parse(config, @logger) return 1 if Errors.handle_with_usage(@logger, puppet.errors) result = clean_certs(certnames, puppet.settings) case result when :success return 0 when :invalid return 24 when :not_found, :error return 1 end end |