Class: Puppet::Indirector::CertificateStatus::File

Inherits:
Puppet::Indirector::Code show all
Defined in:
lib/vendor/puppet/indirector/certificate_status/file.rb

Constant Summary

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary

Attributes included from Util::Docs

#doc, #nodoc

Instance Method Summary collapse

Methods inherited from Terminus

abstract_terminus?, const2name, #indirection, indirection_name, inherited, #initialize, mark_as_abstract_terminus, #model, model, #name, name2const, register_terminus_class, terminus_class, terminus_classes, #terminus_type

Methods included from Util::InstanceLoader

#instance_docs, #instance_hash, #instance_load, #instance_loader, #instance_loading?, #loaded_instance, #loaded_instances

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Constructor Details

This class inherits a constructor from Puppet::Indirector::Terminus

Instance Method Details

#caObject

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/vendor/puppet/indirector/certificate_status/file.rb', line 10

def ca
  raise ArgumentError, "This process is not configured as a certificate authority" unless Puppet::SSL::CertificateAuthority.ca?
  Puppet::SSL::CertificateAuthority.new
end

#destroy(request) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vendor/puppet/indirector/certificate_status/file.rb', line 15

def destroy(request)
  deleted = []
  [
    Puppet::SSL::Certificate,
    Puppet::SSL::CertificateRequest,
    Puppet::SSL::Key,
  ].collect do |part|
    if part.indirection.destroy(request.key)
      deleted << "#{part}"
    end
  end

  return "Nothing was deleted" if deleted.empty?
  "Deleted for #{request.key}: #{deleted.join(", ")}"
end

#find(request) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/vendor/puppet/indirector/certificate_status/file.rb', line 72

def find(request)
  ssl_host = Puppet::SSL::Host.new(request.key)
  public_key = Puppet::SSL::Certificate.indirection.find(request.key)

  if ssl_host.certificate_request || public_key
    ssl_host
  else
    nil
  end
end

#save(request) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vendor/puppet/indirector/certificate_status/file.rb', line 31

def save(request)
  if request.instance.desired_state == "signed"
    certificate_request = Puppet::SSL::CertificateRequest.indirection.find(request.key)
    raise Puppet::Error, "Cannot sign for host #{request.key} without a certificate request" unless certificate_request
    ca.sign(request.key)
  elsif request.instance.desired_state == "revoked"
    certificate = Puppet::SSL::Certificate.indirection.find(request.key)
    raise Puppet::Error, "Cannot revoke host #{request.key} because has it doesn't have a signed certificate" unless certificate
    ca.revoke(request.key)
  else
    raise Puppet::Error, "State #{request.instance.desired_state} invalid; Must specify desired state of 'signed' or 'revoked' for host #{request.key}"
  end

end

#search(request) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vendor/puppet/indirector/certificate_status/file.rb', line 46

def search(request)
  # Support historic interface wherein users provide classes to filter
  # the search.  When used via the REST API, the arguments must be
  # a Symbol or an Array containing Symbol objects.
  klasses = case request.options[:for]
  when Class
    [request.options[:for]]
  when nil
    [
      Puppet::SSL::Certificate,
      Puppet::SSL::CertificateRequest,
      Puppet::SSL::Key,
    ]
  else
    [request.options[:for]].flatten.map do |klassname|
      indirection.class.model(klassname.to_sym)
    end
  end

  klasses.collect do |klass|
    klass.indirection.search(request.key, request.options)
  end.flatten.collect do |result|
    result.name
  end.uniq.collect &Puppet::SSL::Host.method(:new)
end