diff --git a/lib/puppet/face/catalog.rb b/lib/puppet/face/catalog.rb index 13351540a..9bcaa19c6 100644 --- a/lib/puppet/face/catalog.rb +++ b/lib/puppet/face/catalog.rb @@ -1,116 +1,130 @@ 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' - 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 - in 'dot' format (for easy graph viewing with OmniGraffle or Graphviz) - with '--render-as dot'. + This subcommand deals with catalogs, which are compiled per-node artifacts + generated from a set of Puppet manifests. By default, it interacts with the + compiling subsystem and compiles a catalog using the default manifest and + `certname`, but you can change the source of the catalog with the + `--terminus` option. You can also choose to print any catalog in 'dot' + format (for easy graph viewing with OmniGraffle or Graphviz) with + '--render-as dot'. + EOT + short_description <<-'EOT' + This subcommand deals with catalogs, which are compiled per-node artifacts + generated from a set of Puppet manifests. By default, it interacts with the + compiling subsystem and compiles a catalog using the default manifest and + `certname`; use the `--terminus` option to change the source of the catalog. EOT - get_action(:destroy).summary "Invalid for this face." - get_action(:search).summary "Query format unknown; potentially invalid for this face." + get_action(:destroy).summary "Invalid for this subcommand." + get_action(:search).summary "Invalid for this subcommand." + find = get_action(:find) + find.summary "Retrieve the catalog for a node." + find.arguments "" + find.returns <<-'EOT' + A serialized catalog. When used from the Ruby API, returns a + Puppet::Resource::Catalog object. + EOT action(:apply) do - summary "Apply a Puppet::Resource::Catalog object." + summary "Find and apply a catalog." 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. + the source of the catalog can be managed with the `--terminus` option. EOT returns <<-'EOT' - A Puppet::Transaction::Report object. + Nothing. When used from the Ruby API, returns a Puppet::Transaction::Report + object. EOT examples <<-'EOT' Apply the locally cached catalog: $ puppet catalog apply --terminus yaml Retrieve a catalog from the master and apply it, in one step: $ puppet catalog apply --terminus rest From `secret_agent.rb` (API example): # ... 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 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 + Retrieves a catalog from the puppet master and saves it to the local yaml + cache. This action always contacts the puppet master and will ignore alternate termini. + + The saved catalog can be used in any subsequent catalog action by specifying + '--terminus yaml' for that action. EOT 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 + When used from the Ruby API, this action has a side effect of leaving + Puppet::Resource::Catalog.indirection.terminus_class set to yaml. The terminus must be explicitly re-set for subsequent catalog actions. EOT examples <<-'EOT' Retrieve and store a catalog: $ puppet catalog download From `secret_agent.rb` (API example): 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 d86963e75..de2ca803b 100644 --- a/lib/puppet/face/catalog/select.rb +++ b/lib/puppet/face/catalog/select.rb @@ -1,49 +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" + summary "Retrieve a catalog and filter it for resources of a given type." 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]). + A list of resource references ("Type[title]"). When used from the API, + returns an array of Puppet::Resource objects excised from a catalog. EOT description <<-'EOT' - Retrieves a catalog for the specified host and returns an array of - resources of the given type. + Retrieves a catalog for the specified host, then searches it for all + resources of the requested type. EOT 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 cab8817e3..cb0f61e3b 100644 --- a/lib/puppet/face/certificate.rb +++ b/lib/puppet/face/certificate.rb @@ -1,111 +1,114 @@ 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" + summary "Provide access to the CA for certificate management." description <<-'EOT' - This face interacts with a local or remote Puppet certificate + This subcommand 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, and its "generate" action submits a CSR rather than creating a signed certificate. EOT option "--ca-location LOCATION" do - summary "The certificate authority to query" + summary "The certificate authority to query (local or remote)." description <<-'EOT' Whether to act on the local certificate authority or one provided by a remote puppet master. Allowed values are 'local' and 'remote.' + + This option is required. 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." + summary "Generate a new certificate signing request." arguments "" returns "Nothing." description <<-'EOT' Generates and submits a certificate signing request (CSR) for the specified host. This CSR will then have to be signed by a user with the proper authorization on the certificate authority. 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." returns <<-'EOT' - An array of CSR object #inspect strings. This output is currently messy, - but does contain the names of nodes requesting certificates. + An array of #inspect output from CSR objects. This output is + currently messy, but does contain the names of nodes requesting + certificates. This action returns #inspect strings even when used + from the Ruby API. 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." arguments "" returns <<-'EOT' - A string that appears to be an x509 certificate, but is actually - not. Retrieve certificates using the `find` action. + A string that appears to be (but isn't) an x509 certificate. 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.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'). + 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.summary "Delete a certificate." destroy.arguments "" destroy.returns "Nothing." destroy.description <<-'EOT' - Deletes a certificate. This action currently only works with a local CA. + Deletes a certificate. This action currently only works on the local CA. EOT - get_action(:search).summary "Invalid for this face." - get_action(:save).summary "Invalid for this face." + get_action(:search).summary "Invalid for this subcommand." + get_action(:save).summary "Invalid for this subcommand." end diff --git a/lib/puppet/face/certificate_request.rb b/lib/puppet/face/certificate_request.rb index 29cf7dc78..12694ba21 100644 --- a/lib/puppet/face/certificate_request.rb +++ b/lib/puppet/face/certificate_request.rb @@ -1,45 +1,46 @@ 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' - Retrieves and submits certificate signing requests (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. + This subcommand retrieves and submits certificate signing requests (CSRs). EOT # Per-action doc overrides - get_action(:destroy).summary "Invalid for this face." + get_action(:destroy).summary "Invalid for this subcommand." 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'). + A single certificate request. When used from the Ruby API, returns a + Puppet::SSL::CertificateRequest object. + + RENDERING ISSUES: 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 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'). + A list of certificate requests; be sure to to render this as a string + ('--render-as s'). When used from the Ruby API, returns an array of + Puppet::SSL::CertificateRequest objects. 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: + Retrieve all CSRs from the local CA (similar to 'puppet cert list'): $ puppet certificate_request search x --terminus ca EOT - get_action(:save).summary "Submit a certificate signing request." + get_action(:save).summary "API only: 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 0525a601f..12ba1f73f 100644 --- a/lib/puppet/face/certificate_revocation_list.rb +++ b/lib/puppet/face/certificate_revocation_list.rb @@ -1,39 +1,39 @@ 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' - 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. + This subcommand is primarily for retrieving the certificate revocation + list from the CA. EOT 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'). + A certificate revocation list. When used from the Ruby API: returns an + OpenSSL::X509::CRL object. + + RENDERING ISSUES: this should usually be rendered 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. + Deletes the certificate revocation list. This cannot be done over REST, but + it is possible to delete the locally cached copy or (if run from the CA) the + CA's own copy of the CRL. EOT - get_action(:search).summary "Invalid for this face." - get_action(:save).summary "Invalid for this face." + get_action(:search).summary "Invalid for this subcommand." + get_action(:save).summary "Invalid for this subcommand." end diff --git a/lib/puppet/face/config.rb b/lib/puppet/face/config.rb index 6e5bff071..3fce0ed70 100644 --- a/lib/puppet/face/config.rb +++ b/lib/puppet/face/config.rb @@ -1,47 +1,45 @@ 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's configuration options." action(:print) do - summary "Examine Puppet's current configuration options." - arguments "(all |