From ebc642b2141cfed7d10a64ff0bb67a417f5f37be Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Thu, 19 May 2011 12:04:59 -0700 Subject: (#6962) Add "arguments" method to help API Since some actions take arguments and some do not, action synopses were incomplete and ambiguous. This commit adds a method for explicitly declaring what argument(s) an action takes, and places the arguments at the appropriate spot in the action's synopsis. By convention, individual arguments should be wrapped in angle brackets. --- lib/puppet/interface/action.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb index 3c377a49f..748888c2e 100644 --- a/lib/puppet/interface/action.rb +++ b/lib/puppet/interface/action.rb @@ -46,6 +46,7 @@ class Puppet::Interface::Action ######################################################################## # Documentation... attr_doc :returns + attr_doc :arguments def synopsis output = PrettyPrint.format do |s| s.text("puppet #{@face.name}") @@ -67,6 +68,7 @@ class Puppet::Interface::Action end end end + s.text(" #{arguments}") if arguments end end -- cgit From 069a6b8e645255530abf308cfeeed1d7650211db Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Mon, 23 May 2011 17:26:59 -0700 Subject: Maint: Add ellipsis to generated short_descriptions. Auto-generated short descriptions cut off at five lines with no indication that they are truncated. This commit adds ellipsis in brackets to indicate incompleteness. --- lib/puppet/interface/documentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/interface/documentation.rb b/lib/puppet/interface/documentation.rb index 48e9a8b1a..aedcc1c24 100644 --- a/lib/puppet/interface/documentation.rb +++ b/lib/puppet/interface/documentation.rb @@ -78,7 +78,7 @@ class Puppet::Interface return nil if @description.nil? lines = @description.split("\n") grab = [5, lines.index('') || 5].min - @short_description = lines[0, grab].join("\n") + @short_description = lines[0, grab].join("\n") + ' [...]' end @short_description end -- cgit From 331d8128288f8c7bb3645149ff452372c0866429 Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Wed, 18 May 2011 16:20:05 -0700 Subject: (#7561) Complete help text for all faces and actions Faces help output relies on input from the documentation methods in each of the faces to be documented. This commit calls those methods in each of our faces, with varying levels of detail depending on their complexity. --- lib/puppet/face/catalog.rb | 83 ++++++++++++++++---------- lib/puppet/face/catalog/select.rb | 25 +++++--- lib/puppet/face/certificate.rb | 70 ++++++++++++++++++---- lib/puppet/face/certificate_request.rb | 40 ++++++++++--- lib/puppet/face/certificate_revocation_list.rb | 38 ++++++++---- lib/puppet/face/config.rb | 37 ++++++------ lib/puppet/face/facts.rb | 67 ++++++++++++++++----- lib/puppet/face/file.rb | 45 ++++++++++++-- lib/puppet/face/file/download.rb | 18 ++++++ lib/puppet/face/file/store.rb | 9 +++ lib/puppet/face/help.rb | 11 +++- lib/puppet/face/help/action.erb | 40 +++---------- lib/puppet/face/key.rb | 18 +++--- lib/puppet/face/node.rb | 40 ++++++++++--- lib/puppet/face/parser.rb | 8 ++- lib/puppet/face/plugin.rb | 31 ++++++---- lib/puppet/face/report.rb | 40 +++++++++---- lib/puppet/face/resource.rb | 46 ++++++++++++-- lib/puppet/face/resource_type.rb | 71 ++++++++++++++++++++-- lib/puppet/face/secret_agent.rb | 40 +++++++++---- lib/puppet/face/status.rb | 53 ++++++++++------ lib/puppet/indirector/face.rb | 55 +++++++++-------- 22 files changed, 628 insertions(+), 257 deletions(-) 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 @@ -5,17 +5,17 @@ Puppet::Indirector::Face.define(:catalog, '0.0.1') do 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` @@ -25,26 +25,35 @@ Puppet::Indirector::Face.define(:catalog, '0.0.1') do * `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| @@ -71,23 +80,33 @@ Puppet::Indirector::Face.define(:catalog, '0.0.1') do 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 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 @@ -2,21 +2,28 @@ 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. 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 @@ -6,16 +6,16 @@ Puppet::Indirector::Face.define(:certificate, '0.0.1') do 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` @@ -25,7 +25,7 @@ Puppet::Indirector::Face.define(:certificate, '0.0.1') do 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 @@ -36,16 +36,23 @@ Puppet::Indirector::Face.define(:certificate, '0.0.1') do 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) @@ -55,7 +62,11 @@ Puppet::Indirector::Face.define(:certificate, '0.0.1') do 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("*", { @@ -65,7 +76,17 @@ Puppet::Indirector::Face.define(:certificate, '0.0.1') do 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) @@ -73,4 +94,27 @@ Puppet::Indirector::Face.define(:certificate, '0.0.1') do 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 @@ -5,28 +5,50 @@ Puppet::Indirector::Face.define(:certificate_request, '0.0.1') do 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 @@ -5,26 +5,44 @@ Puppet::Indirector::Face.define(:certificate_revocation_list, '0.0.1') do 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 @@ -4,38 +4,37 @@ 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 |