class Puppetserver::Ca::Action::Revoke

Constants

CERTNAME_BLACKLIST
SUMMARY

Public Class Methods

new(logger) click to toggle source
# File lib/puppetserver/ca/action/revoke.rb, line 47
def initialize(logger)
  @logger = logger
end
parser(parsed = {}) click to toggle source
# File lib/puppetserver/ca/action/revoke.rb, line 30
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', 'Displays this revoke specific help output') do |help|
      parsed['help'] = true
    end
  end
end

Public Instance Methods

parse(args) click to toggle source
# File lib/puppetserver/ca/action/revoke.rb, line 51
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 revoke'
  end

  errors_were_handled = Errors.handle_with_usage(@logger, errors, parser.help)

  # if there is an exit_code then Cli will return it early, so we only
  # return an exit_code if there's an error
  exit_code = errors_were_handled ? 1 : nil

  return results, exit_code
end
revoke_certs(certnames, settings) click to toggle source
# File lib/puppetserver/ca/action/revoke.rb, line 101
def revoke_certs(certnames, settings)
  ca = Puppetserver::Ca::CertificateAuthority.new(@logger, settings)
  ca.revoke_certs(certnames)
end
run(args) click to toggle source
# File lib/puppetserver/ca/action/revoke.rb, line 77
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 =  revoke_certs(certnames, puppet.settings)

  case result
  when :success
    return 0
  when :invalid
    return 24
  when :not_found, :error
    return 1
  end
end