diff --git a/lib/puppet/face/catalog.rb b/lib/puppet/face/catalog.rb index 4624313bc..c7501ff37 100644 --- a/lib/puppet/face/catalog.rb +++ b/lib/puppet/face/catalog.rb @@ -1,108 +1,127 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:catalog, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Compile, save, view, and convert catalogs." - description <<-EOT + description <<-'EOT' This face primarily interacts with the compiling subsystem. By default, it compiles a catalog using the default manifest and the hostname from `certname`, but you can choose to retrieve a catalog from the server by - specifying `--terminus rest`. You can also choose to print any catalog + specifying '--terminus rest'. You can also choose to print any catalog in 'dot' format (for easy graph viewing with OmniGraffle or Graphviz) with '--render-as dot'. EOT - notes <<-EOT - This is an indirector face, which exposes find, search, save, and - destroy actions for an indirected subsystem of Puppet. Valid terminuses + notes <<-'EOT' + This is an indirector face, which exposes `find`, `search`, `save`, and + `destroy` actions for an indirected subsystem of Puppet. Valid termini for this face include: * `active_record` * `compiler` * `queue` * `rest` * `yaml` EOT + get_action(:destroy).summary "Invalid for this face." + get_action(:search).summary "Query format unknown; potentially invalid for this face." + action(:apply) do - summary "Apply a Puppet::Resource::Catalog object" - description <<-EOT - Applies a catalog object retrieved with the `download` action. This - action cannot consume a serialized catalog, and is not intended for - command-line use." + summary "Apply a Puppet::Resource::Catalog object." + description <<-'EOT' + Finds and applies a catalog. This action takes no arguments, but + the source of the catalog can be managed with the --terminus option. EOT - notes <<-EOT - This action returns a Puppet::Transaction::Report object. + returns <<-'EOT' + A Puppet::Transaction::Report object. EOT - examples <<-EOT - From `secret_agent.rb`: + examples <<-'EOT' + Apply the locally cached catalog: - Puppet::Face[:plugin, '0.0.1'].download + $ puppet catalog apply --terminus yaml + + Retrieve a catalog from the master and apply it, in one step: + + $ puppet catalog apply --terminus rest - facts = Puppet::Face[:facts, '0.0.1'].find(certname) - catalog = Puppet::Face[:catalog, '0.0.1'].download(certname, facts) - report = Puppet::Face[:catalog, '0.0.1'].apply(catalog) + From `secret_agent.rb` (API example): - Puppet::Face[:report, '0.0.1'].submit(report) + # ... + Puppet::Face[:catalog, '0.0.1'].download + # (Termini are singletons; catalog.download has a side effect of + # setting the catalog terminus to yaml) + report = Puppet::Face[:catalog, '0.0.1'].apply + # ... EOT when_invoked do |options| catalog = Puppet::Face[:catalog, "0.0.1"].find(Puppet[:certname]) or raise "Could not find catalog for #{Puppet[:certname]}" catalog = catalog.to_ral report = Puppet::Transaction::Report.new("apply") report.configuration_version = catalog.version Puppet::Util::Log.newdestination(report) begin benchmark(:notice, "Finished catalog run") do catalog.apply(:report => report) end rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Failed to apply catalog: #{detail}" end report.finalize_report report end end action(:download) do - summary "Download this node's catalog from the puppet master server" - description <<-EOT - Retrieves a catalog from the puppet master. Unlike the `find` action, - `download` submits facts to the master as part of the request. This - action is not intended for command-line use. + summary "Download this node's catalog from the puppet master server." + description <<-'EOT' + Retrieves a catalog from the puppet master and saves it to the + local yaml cache. The saved catalog can be used in subsequent + catalog actions by specifying '--terminus rest'. + + This action always contacts the puppet master and will ignore + alternate termini. EOT - notes "This action returns a Puppet::Resource::Catalog object." - examples <<-EOT - From `secret_agent.rb`: + returns "Nothing." + notes <<-'EOT' + As termini are singletons, this action has a side effect of + exporting Puppet::Resource::Catalog.indirection.terminus_class = + yaml to the calling context when used with the Ruby Faces API. The + terminus must be explicitly re-set for subsequent catalog actions. + EOT + examples <<-'EOT' + Retrieve and store a catalog: - Puppet::Face[:plugin, '0.0.1'].download + $ puppet catalog download - facts = Puppet::Face[:facts, '0.0.1'].find(certname) - catalog = Puppet::Face[:catalog, '0.0.1'].download(certname, facts) - report = Puppet::Face[:catalog, '0.0.1'].apply(catalog) + From `secret_agent.rb` (API example): - Puppet::Face[:report, '0.0.1'].submit(report) + Puppet::Face[:plugin, '0.0.1'].download + Puppet::Face[:facts, '0.0.1'].upload + Puppet::Face[:catalog, '0.0.1'].download + # ... EOT when_invoked do |options| Puppet::Resource::Catalog.indirection.terminus_class = :rest Puppet::Resource::Catalog.indirection.cache_class = nil catalog = nil retrieval_duration = thinmark do catalog = Puppet::Face[:catalog, '0.0.1'].find(Puppet[:certname]) end catalog.retrieval_duration = retrieval_duration catalog.write_class_file Puppet::Resource::Catalog.indirection.terminus_class = :yaml Puppet::Face[:catalog, "0.0.1"].save(catalog) Puppet.notice "Saved catalog for #{Puppet[:certname]} to yaml" nil end end end diff --git a/lib/puppet/face/catalog/select.rb b/lib/puppet/face/catalog/select.rb index a6c97a627..d86963e75 100644 --- a/lib/puppet/face/catalog/select.rb +++ b/lib/puppet/face/catalog/select.rb @@ -1,42 +1,49 @@ # Select and show a list of resources of a given type. Puppet::Face.define(:catalog, '0.0.1') do action :select do summary "Select and show a list of resources of a given type" - description <<-EOT + arguments " " + returns <<-'EOT' + An array of resource objects excised from a catalog. When used at + the command line, returns a list of resource references (Type[title]). + EOT + description <<-'EOT' Retrieves a catalog for the specified host and returns an array of - resources of the given type. This action is not intended for - command-line use. + resources of the given type. EOT - notes <<-NOTES - The type name for this action must be given in its capitalized form. - That is, calling `catalog select mynode file` will return an empty - array, whereas calling it with 'File' will return a list of the node's - file resources. - + notes <<-'NOTES' By default, this action will retrieve a catalog from Puppet's compiler subsystem; you must call the action with `--terminus rest` if you wish to retrieve a catalog from the puppet master. + + FORMATTING ISSUES: This action cannot currently render useful yaml; + instead, it returns an entire catalog. Use json instead. NOTES + examples <<-'EOT' + Ask the puppet master for a list of managed file resources for a node: + + $ puppet catalog select --terminus rest somenode.magpie.lan file + EOT when_invoked do |host, type, options| # REVISIT: Eventually, type should have a default value that triggers # the non-specific behaviour. For now, though, this will do. # --daniel 2011-05-03 catalog = Puppet::Resource::Catalog.indirection.find(host) if type == '*' catalog.resources else type = type.downcase catalog.resources.reject { |res| res.type.downcase != type } end end when_rendering :console do |value| if value.nil? then "no matching resources found" else value.map {|x| x.to_s }.join("\n") end end end end diff --git a/lib/puppet/face/certificate.rb b/lib/puppet/face/certificate.rb index 859946623..d77525ba8 100644 --- a/lib/puppet/face/certificate.rb +++ b/lib/puppet/face/certificate.rb @@ -1,76 +1,120 @@ require 'puppet/indirector/face' require 'puppet/ssl/host' Puppet::Indirector::Face.define(:certificate, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Provide access to the CA for certificate management" - description <<-EOT + description <<-'EOT' This face interacts with a local or remote Puppet certificate - authority. Currently, its behavior is not a full superset of puppet - cert; specifically, it is unable to mimic puppet cert's "clean" option, + authority. Currently, its behavior is not a full superset of `puppet + cert`; specifically, it is unable to mimic puppet cert's "clean" option, and its "generate" action submits a CSR rather than creating a signed certificate. EOT - notes <<-EOT - This is an indirector face, which exposes find, search, save, and - destroy actions for an indirected subsystem of Puppet. Valid terminuses + notes <<-'EOT' + This is an indirector face, which exposes `find`, `search`, `save`, and + `destroy` actions for an indirected subsystem of Puppet. Valid termini for this face include: * `ca` * `file` * `rest` EOT option "--ca-location LOCATION" do summary "The certificate authority to query" - description <<-EOT + description <<-'EOT' Whether to act on the local certificate authority or one provided by a remote puppet master. Allowed values are 'local' and 'remote.' EOT before_action do |action, args, options| Puppet::SSL::Host.ca_location = options[:ca_location].to_sym end end action :generate do - summary "Generate a new certificate signing request for HOST" - description <<-EOT + summary "Generate a new certificate signing request for HOST." + arguments "" + returns "Nothing." + description <<-'EOT' Generates and submits a certificate signing request (CSR) for the - provided host identifier. This CSR will then have to be signed by a user + specified host. This CSR will then have to be signed by a user with the proper authorization on the certificate authority. - Puppet agent handles CSR submission automatically. This action is + Puppet agent usually handles CSR submission automatically. This action is primarily useful for requesting certificates for individual users and external applications. EOT + examples <<-'EOT' + Request a certificate for "somenode" from the site's CA: + + $ puppet certificate generate somenode.puppetlabs.lan --ca-location remote + EOT when_invoked do |name, options| host = Puppet::SSL::Host.new(name) host.generate_certificate_request host.certificate_request.class.indirection.save(host.certificate_request) end end action :list do - summary "List all certificate signing requests" + summary "List all certificate signing requests." + returns <<-'EOT' + An array of CSR object #inspect strings. This output is currently messy, + but does contain the names of nodes requesting certificates. + EOT when_invoked do |options| Puppet::SSL::Host.indirection.search("*", { :for => :certificate_request, }).map { |h| h.inspect } end end action :sign do - summary "Sign a certificate signing request for HOST" + summary "Sign a certificate signing request for HOST." + arguments "" + returns <<-'EOT' + A string that appears to be an x509 certificate, but is actually + not. Retrieve certificates using the `find` action. + EOT + examples <<-'EOT' + Sign somenode.puppetlabs.lan's certificate: + + $ puppet certificate sign somenode.puppetlabs.lan --ca-location remote + EOT when_invoked do |name, options| host = Puppet::SSL::Host.new(name) host.desired_state = 'signed' Puppet::SSL::Host.indirection.save(host) end end + + # Indirector action doc overrides + find = get_action(:find) + find.summary "Retrieve a certificate" + find.arguments "" + find.returns <<-'EOT' + An x509 SSL certificate. You will usually want to render this as a + string ('--render-as s'). + + Note that this action has a side effect of caching a copy of the + certificate in Puppet's `ssldir`. + EOT + + destroy = get_action(:destroy) + destroy.summary "Delete a local certificate." + destroy.arguments "" + destroy.returns "Nothing." + destroy.description <<-'EOT' + Deletes a certificate. This action currently only works with a local CA. + EOT + + get_action(:search).summary "Invalid for this face." + get_action(:save).summary "Invalid for this face." end diff --git a/lib/puppet/face/certificate_request.rb b/lib/puppet/face/certificate_request.rb index cc6021517..de52b7fb7 100644 --- a/lib/puppet/face/certificate_request.rb +++ b/lib/puppet/face/certificate_request.rb @@ -1,32 +1,54 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:certificate_request, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Manage certificate requests." - description <<-EOT + description <<-'EOT' Retrieves and submits certificate signing requests (CSRs). Invoke - `search` with an unread key to retrieve all outstanding CSRs, invoke + `search` with a dummy key to retrieve all outstanding CSRs, invoke `find` with a node certificate name to retrieve a specific request, and invoke `save` to submit a CSR. EOT - notes <<-EOT - This is an indirector face, which exposes find, search, save, and - destroy actions for an indirected subsystem of Puppet. Valid terminuses + notes <<-'EOT' + This is an indirector face, which exposes `find`, `search`, `save`, and + `destroy` actions for an indirected subsystem of Puppet. Valid termini for this face include: * `ca` * `file` * `rest` EOT - examples <<-EOT - Retrieve all CSRs from the local CA: - puppet certificate_request search no_key --terminus ca + # Per-action doc overrides + get_action(:destroy).summary "Invalid for this face." + get_action(:find).summary "Retrieve a single CSR." + get_action(:find).arguments "" + get_action(:find).returns <<-'EOT' + A single certificate request. In most cases, you will want to render + this as a string ('--render-as s'). + EOT + get_action(:find).examples <<-'EOT' Retrieve a single CSR from the puppet master's CA: - puppet certificate_request find mynode.puppetlabs.lan --terminus rest + $ puppet certificate_request find somenode.puppetlabs.lan --terminus rest + EOT + + get_action(:search).summary "Retrieve all outstanding CSRs." + get_action(:search).arguments "" + get_action(:search).returns <<-'EOT' + An array of certificate request objects. In most cases, you will + want to render this as a string ('--render-as s'). EOT + get_action(:search).notes "This action always returns all CSRs, but requires a dummy search key." + get_action(:search).examples <<-'EOT' + Retrieve all CSRs from the local CA: + + $ puppet certificate_request search x --terminus ca + EOT + + get_action(:save).summary "Submit a certificate signing request." + get_action(:save).arguments "" end diff --git a/lib/puppet/face/certificate_revocation_list.rb b/lib/puppet/face/certificate_revocation_list.rb index 2722b20f2..db00ea3ca 100644 --- a/lib/puppet/face/certificate_revocation_list.rb +++ b/lib/puppet/face/certificate_revocation_list.rb @@ -1,30 +1,48 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:certificate_revocation_list, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Manage the list of revoked certificates." - description <<-EOT + description <<-'EOT' This face is primarily for retrieving the certificate revocation list from the CA. Although it exposes search/save/destroy methods, they shouldn't be used under normal circumstances. EOT - notes <<-EOT - Although the find action must be given an argument, this argument is - never read, and can contain the descriptive text of your choice. - - This is an indirector face, which exposes find, search, save, and - destroy actions for an indirected subsystem of Puppet. Valid terminuses + notes <<-'EOT' + This is an indirector face, which exposes `find`, `search`, `save`, and + `destroy` actions for an indirected subsystem of Puppet. Valid termini for this face include: * `ca` * `file` * `rest` EOT - examples <<-EXAMPLES - Retrieve the CRL: - puppet certificate_revocation_list find crl + get_action(:find).summary "Retrieve the certificate revocation list." + get_action(:find).arguments "" + get_action(:find).returns <<-'EOT' + A certificate revocation list. You will usually want to render this + as a string ('--render-as s'). + EOT + get_action(:find).examples <<-'EXAMPLES' + Retrieve a copy of the puppet master's CRL: + + $ puppet certificate_revocation_list find crl --terminus rest EXAMPLES + + get_action(:destroy).summary "Delete the certificate revocation list." + get_action(:destroy).arguments "" + get_action(:destroy).returns "Nothing." + get_action(:destroy).description <<-'EOT' + Deletes the certificate revocation list. This cannot be done over + REST, but it is possible to both delete the locally cached copy of + the CA's CRL and delete the CA's own copy (if running on the CA + machine and invoked with '--terminus ca'). Needless to say, don't do + this unless you know what you're up to. + EOT + + get_action(:search).summary "Invalid for this face." + get_action(:save).summary "Invalid for this face." end diff --git a/lib/puppet/face/config.rb b/lib/puppet/face/config.rb index 9ca41085e..6e5bff071 100644 --- a/lib/puppet/face/config.rb +++ b/lib/puppet/face/config.rb @@ -1,48 +1,47 @@ require 'puppet/face' Puppet::Face.define(:config, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" - summary "Interact with Puppet configuration options" + summary "Interact with Puppet's configuration options." action(:print) do - summary "Examine Puppet's current configuration options" - description <<-EOT + summary "Examine Puppet's current configuration options." + arguments "(all |