class Puppetserver::Ca::Action::Clean

Constants

CERTNAME_BLACKLIST
SUMMARY

Public Class Methods

new(logger) click to toggle source
# File lib/puppetserver/ca/action/clean.rb, line 51
def initialize(logger)
  @logger = logger
end
parser(parsed = {}) click to toggle source
# File lib/puppetserver/ca/action/clean.rb, line 34
def self.parser(parsed = {})
  parsed['certnames'] = []
  OptionParser.new do |o|
    o.banner = 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

Public Instance Methods

clean_certs(certnames, settings) click to toggle source
# 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) click to toggle source
# 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_BLACKLIST.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) click to toggle source
# 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)
  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