diff --git a/lib/puppet/face/catalog.rb b/lib/puppet/face/catalog.rb index e596a55e5..346f2e1dd 100644 --- a/lib/puppet/face/catalog.rb +++ b/lib/puppet/face/catalog.rb @@ -1,130 +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 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 subcommand." - get_action(:search).summary "Invalid for this subcommand." + deactivate_action(:destroy) + deactivate_action(:search) 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 "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. EOT returns <<-'EOT' 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 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 report.environment = Puppet[:environment] Puppet::Util::Log.newdestination(report) begin benchmark(:notice, "Finished catalog run") do catalog.apply(:report => report) end rescue => detail Puppet.log_exception(detail, "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. 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' 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 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/certificate.rb b/lib/puppet/face/certificate.rb index 7c93e5062..8319eff11 100644 --- a/lib/puppet/face/certificate.rb +++ b/lib/puppet/face/certificate.rb @@ -1,160 +1,159 @@ 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 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 required summary "Which certificate authority to use (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| unless [:remote, :local, :only].include? options[:ca_location].to_sym raise ArgumentError, "Valid values for ca-location are 'remote', 'local', 'only'." end Puppet::SSL::Host.ca_location = options[:ca_location].to_sym end end action :generate do 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 # Duplicate the option here explicitly to distinguish if it was passed arg # us vs. set in the config file. option "--dns-alt-names NAMES" do summary "Additional DNS names to add to the certificate request" description Puppet.settings.setting(:dns_alt_names).desc end when_invoked do |name, options| host = Puppet::SSL::Host.new(name) # We have a weird case where we have --dns_alt_names from Puppet, but # this option is --dns-alt-names. Until we can get rid of --dns-alt-names # or do a global tr('-', '_'), we have to support both. # In supporting both, we'll use Puppet[:dns_alt_names] if specified on # command line. We'll use options[:dns_alt_names] if specified on # command line. If both specified, we'll fail. # jeffweiss 17 april 2012 global_setting_from_cli = Puppet.settings.set_by_cli?(:dns_alt_names) == true raise ArgumentError, "Can't specify both --dns_alt_names and --dns-alt-names" if options[:dns_alt_names] and global_setting_from_cli options[:dns_alt_names] = Puppet[:dns_alt_names] if global_setting_from_cli # If dns_alt_names are specified via the command line, we will always add # them. Otherwise, they will default to the config file setting iff this # cert is for the host we're running on. host.generate_certificate_request(:dns_alt_names => options[:dns_alt_names]) end end action :list do summary "List all certificate signing requests." returns <<-EOT 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 (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 option("--[no-]allow-dns-alt-names") do summary "Whether or not to accept DNS alt names in the certificate request" end when_invoked do |name, options| host = Puppet::SSL::Host.new(name) if Puppet::SSL::Host.ca_location == :remote if options[:allow_dns_alt_names] raise ArgumentError, "--allow-dns-alt-names may not be specified with a remote CA" end host.desired_state = 'signed' Puppet::SSL::Host.indirection.save(host) else # We have to do this case manually because we need to specify # allow_dns_alt_names. unless ca = Puppet::SSL::CertificateAuthority.instance raise ArgumentError, "This process is not configured as a certificate authority" end ca.sign(name, options[:allow_dns_alt_names]) end end end # Indirector action doc overrides find = get_action(:find) find.summary "Retrieve a certificate." find.arguments "" find.render_as = :s find.returns <<-EOT An x509 SSL certificate. 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 certificate." destroy.arguments "" destroy.returns "Nothing." destroy.description <<-EOT Deletes a certificate. This action currently only works on the local CA. EOT - get_action(:search).summary "Invalid for this subcommand." - get_action(:save).summary "Invalid for this subcommand." - get_action(:save).description "Invalid for this subcommand." + deactivate_action(:search) + deactivate_action(:save) end diff --git a/lib/puppet/face/certificate_request.rb b/lib/puppet/face/certificate_request.rb index cf342d51a..aa29195fc 100644 --- a/lib/puppet/face/certificate_request.rb +++ b/lib/puppet/face/certificate_request.rb @@ -1,53 +1,52 @@ 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 This subcommand retrieves and submits certificate signing requests (CSRs). EOT - # Per-action doc overrides - get_action(:destroy).summary "Invalid for this subcommand." + deactivate_action(:destroy) find = get_action(:find) find.summary "Retrieve a single CSR." find.arguments "" find.render_as = :s find.returns <<-EOT A single certificate request. When used from the Ruby API, returns a Puppet::SSL::CertificateRequest object. EOT find.examples <<-EOT Retrieve a single CSR from the puppet master's CA: $ puppet certificate_request find somenode.puppetlabs.lan --terminus rest EOT search = get_action(:search) search.summary "Retrieve all outstanding CSRs." search.arguments "" search.render_as = :s search.returns <<-EOT A list of certificate requests. When used from the Ruby API, returns an array of Puppet::SSL::CertificateRequest objects. EOT search.short_description <<-EOT Retrieves all outstanding certificate signing requests. Due to a known bug, this action requires a dummy search key, the content of which is irrelevant. EOT search.notes <<-EOT Although this action always returns all CSRs, it requires a dummy search key; this is a known bug. EOT search.examples <<-EOT Retrieve all CSRs from the local CA (similar to 'puppet cert list'): $ puppet certificate_request search x --terminus ca EOT 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 022323b29..a004a0db2 100644 --- a/lib/puppet/face/certificate_revocation_list.rb +++ b/lib/puppet/face/certificate_revocation_list.rb @@ -1,58 +1,57 @@ 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 subcommand is primarily for retrieving the certificate revocation list from the CA. EOT find = get_action(:find) find.summary "Retrieve the certificate revocation list." find.arguments "" find.render_as = :s find.returns <<-EOT The certificate revocation list. When used from the Ruby API: returns an OpenSSL::X509::CRL object. EOT find.short_description <<-EOT Retrieves the certificate revocation list. Due to a known bug, this action requires a dummy argument, the content of which is irrelevant. EOT find.notes <<-EOT Although this action always returns the CRL from the specified terminus, it requires a dummy argument; this is a known bug. EOT find.examples <<-EXAMPLES Retrieve a copy of the puppet master's CRL: $ puppet certificate_revocation_list find crl --terminus rest EXAMPLES destroy = get_action(:destroy) destroy.summary "Delete the certificate revocation list." destroy.arguments "" destroy.returns "Nothing." destroy.description <<-EOT Deletes the certificate revocation list. This cannot be done over REST, but it is possible to delete the locally cached copy or the local CA's copy of the CRL. EOT destroy.short_description <<-EOT Deletes the certificate revocation list. This cannot be done over REST, but it is possible to delete the locally cached copy or the local CA's copy of the CRL. Due to a known bug, this action requires a dummy argument, the content of which is irrelevant. EOT destroy.notes <<-EOT Although this action always deletes the CRL from the specified terminus, it requires a dummy argument; this is a known bug. EOT - get_action(:search).summary "Invalid for this subcommand." - get_action(:save).summary "Invalid for this subcommand." - get_action(:save).description "Invalid for this subcommand." + deactivate_action(:search) + deactivate_action(:save) end diff --git a/lib/puppet/face/facts.rb b/lib/puppet/face/facts.rb index bd440349a..b35026d47 100644 --- a/lib/puppet/face/facts.rb +++ b/lib/puppet/face/facts.rb @@ -1,37 +1,37 @@ require 'puppet/indirector/face' require 'puppet/node/facts' Puppet::Indirector::Face.define(:facts, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Retrieve and store facts." description <<-'EOT' This subcommand manages facts, which are collections of normalized system information used by Puppet. It can read facts directly from the local system (with the default `facter` terminus). EOT find = get_action(:find) find.summary "Retrieve a node's facts." find.arguments "" find.returns <<-'EOT' A hash containing some metadata and (under the "values" key) the set of facts for the requested node. When used from the Ruby API: A Puppet::Node::Facts object. RENDERING ISSUES: Facts cannot currently be rendered as a string; use yaml or json. EOT find.notes <<-'EOT' When using the `facter` terminus, the host argument is ignored. EOT find.examples <<-'EOT' Get facts from the local system: $ puppet facts find x EOT - get_action(:destroy).summary "Invalid for this subcommand." - get_action(:search).summary "Invalid for this subcommand." + deactivate_action(:destroy) + deactivate_action(:search) end diff --git a/lib/puppet/face/file.rb b/lib/puppet/face/file.rb index f63350e3b..25f7e3e63 100644 --- a/lib/puppet/face/file.rb +++ b/lib/puppet/face/file.rb @@ -1,47 +1,47 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:file, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Retrieve and store files in a filebucket" description <<-'EOT' This subcommand interacts with objects stored in a local or remote filebucket. File objects are accessed by their MD5 sum; see the examples for the relevant syntax. EOT notes <<-'EOT' To retrieve the unmunged contents of a file, you must call find with --render-as s. Rendering as yaml will return a hash of metadata about the file, including its contents. This subcommand does not interact with the `clientbucketdir` (the default local filebucket for puppet agent); it interacts with the primary "master"-type filebucket located in the `bucketdir`. If you wish to interact with puppet agent's default filebucket, you'll need to set the <--bucketdir> option appropriately when invoking actions. EOT file = get_action(:find) file.summary "Retrieve a file from the filebucket." file.arguments "md5/" file.returns <<-'EOT' The file object with the specified checksum. RENDERING ISSUES: Rendering as a string returns the contents of the file object; rendering as yaml returns a hash of metadata about said file, including but not limited to its contents. Rendering as json is currently broken, and returns a hash containing only the contents of the file. EOT file.examples <<-'EOT' Retrieve the contents of a file: $ puppet file find md5/9aedba7f413c97dc65895b1cd9421f2c --render-as s EOT - get_action(:search).summary "Invalid for this subcommand." - get_action(:destroy).summary "Invalid for this subcommand." + deactivate_action(:search) + deactivate_action(:destroy) set_indirection_name :file_bucket_file end diff --git a/lib/puppet/face/node.rb b/lib/puppet/face/node.rb index d9c1522ac..33ee90036 100644 --- a/lib/puppet/face/node.rb +++ b/lib/puppet/face/node.rb @@ -1,43 +1,42 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:node, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "View and manage node definitions." description <<-'EOT' This subcommand interacts with node objects, which are used by Puppet to build a catalog. A node object consists of the node's facts, environment, node parameters (exposed in the parser as top-scope variables), and classes. EOT - get_action(:destroy).summary "Invalid for this subcommand." - get_action(:search).summary "Invalid for this subcommand." - get_action(:save).summary "Invalid for this subcommand." - get_action(:save).description "Invalid for this subcommand." + deactivate_action(:destroy) + deactivate_action(:search) + deactivate_action(:save) find = get_action(:find) find.summary "Retrieve a node object." find.arguments "" find.returns <<-'EOT' A hash containing the node's `classes`, `environment`, `expiration`, `name`, `parameters` (its facts, combined with any ENC-set parameters), and `time`. When used from the Ruby API: a Puppet::Node object. RENDERING ISSUES: Rendering as string and json are currently broken; node objects can only be rendered as yaml. EOT find.examples <<-'EOT' Retrieve an "empty" (no classes, no ENC-imposed parameters, and an environment of "production") node: $ puppet node find somenode.puppetlabs.lan --terminus plain --render-as yaml Retrieve a node using the puppet master's configured ENC: $ puppet node find somenode.puppetlabs.lan --terminus exec --run_mode master --render-as yaml Retrieve the same node from the puppet master: $ puppet node find somenode.puppetlabs.lan --terminus rest --render-as yaml EOT end diff --git a/lib/puppet/face/report.rb b/lib/puppet/face/report.rb index c5ff1a4a9..f66a0740c 100644 --- a/lib/puppet/face/report.rb +++ b/lib/puppet/face/report.rb @@ -1,54 +1,54 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:report, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Create, display, and submit reports." - get_action(:find).summary "Invalid for this face." - get_action(:search).summary "Invalid for this face." - get_action(:destroy).summary "Invalid for this face." save = get_action(:save) save.summary "API only: submit a report." save.arguments "" save.returns "Nothing." save.examples <<-'EOT' From the implementation of `puppet report submit` (API example): begin Puppet::Transaction::Report.indirection.terminus_class = :rest Puppet::Face[:report, "0.0.1"].save(report) Puppet.notice "Uploaded report for #{report.name}" rescue => detail Puppet.log_exception(detail, "Could not send report: #{detail}") end EOT action(:submit) do summary "API only: submit a report with error handling." description <<-'EOT' API only: Submits a report to the puppet master. This action is essentially a shortcut and wrapper for the `save` action with the `rest` terminus, and provides additional details in the event of a failure. EOT arguments "" examples <<-'EOT' API example: # ... report = Puppet::Face[:catalog, '0.0.1'].apply Puppet::Face[:report, '0.0.1'].submit(report) return report EOT when_invoked do |report, options| begin Puppet::Transaction::Report.indirection.terminus_class = :rest Puppet::Face[:report, "0.0.1"].save(report) Puppet.notice "Uploaded report for #{report.name}" rescue => detail Puppet.log_exception(detail, "Could not send report: #{detail}") end end end + deactivate_action(:find) + deactivate_action(:search) + deactivate_action(:destroy) end diff --git a/lib/puppet/face/resource.rb b/lib/puppet/face/resource.rb index 99e9bec95..b1a81d086 100644 --- a/lib/puppet/face/resource.rb +++ b/lib/puppet/face/resource.rb @@ -1,53 +1,53 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:resource, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "API only: interact directly with resources via the RAL." description <<-'EOT' API only: this face provides a Ruby API with functionality similar to the puppet resource subcommand. EOT - get_action(:destroy).summary "Invalid for this subcommand." + deactivate_action(:destroy) search = get_action(:search) search.summary "API only: get all resources of a single type." search.arguments "" search.returns "An array of Puppet::Resource objects." search.examples <<-'EOT' Get a list of all user resources (API example): all_users = Puppet::Face[:resource, '0.0.1'].search("user") EOT find = get_action(:find) find.summary "API only: get a single resource." find.arguments "/" find.returns "A Puppet::Resource object." find.examples <<-'EOT' Print information about a user on this system (API example): puts Puppet::Face[:resource, '0.0.1'].find("user/luke").to_pson EOT save = get_action(:save) save.summary "API only: create a new resource." save.description <<-EOT API only: creates a new resource. EOT save.arguments "<resource_object>" save.returns "The same resource object passed as an argument." save.examples <<-'EOT' Create a new file resource (API example): my_resource = Puppet::Resource.new( :file, "/tmp/demonstration", :parameters => {:ensure => :present, :content => "some\nthing\n"} ) Puppet::Face[:resource, '0.0.1'].save(my_resource) EOT end diff --git a/lib/puppet/face/resource_type.rb b/lib/puppet/face/resource_type.rb index 3cd28daa3..723609a80 100644 --- a/lib/puppet/face/resource_type.rb +++ b/lib/puppet/face/resource_type.rb @@ -1,81 +1,79 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:resource_type, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "View classes, defined resource types, and nodes from all manifests." description <<-'EOT' This subcommand reads information about the resource collections (classes, nodes, and defined types) available in Puppet's site manifest and modules. It will eventually be extended to examine native resource types. EOT notes <<-'EOT' The `find` and `search` actions return similar hashes of resource collection info. These hashes will include the following four keys: * `file` (a string) * `name` (a string) * `type` (<hostclass>, <definition>, or <node>) * `line` (an integer) They may optionally include the following keys: * `parent` (<name_of_resource_collection>) * `arguments` (a hash of parameters and default values) * `doc` (a string) EOT - # Action documentation overrides: - get_action(:save).summary = "Invalid for this subcommand." - get_action(:save).description "Invalid for this subcommand." - get_action(:destroy).summary = "Invalid for this subcommand." + deactivate_action(:save) + deactivate_action(:destroy) find = get_action(:find) find.summary "Retrieve info about a resource collection." find.arguments "<collection_name>" find.returns <<-'EOT' A hash of info about the requested resource collection. When used from the Ruby API: returns a Puppet::Resource::Type object. RENDERING ISSUES: yaml and string output for this indirection are currently unusable; use json instead. EOT find.notes <<-'EOT' If two resource collections share the same name (e.g. you have both a node and a class named "default"), `find` will only return one of them. This can be worked around by using `search` instead. EOT find.examples <<-'EOT' Retrieve info about a specific locally-defined class: $ puppet resource_type find ntp::disabled Retrieve info from the puppet master about a specific class: $ puppet resource_type find ntp --terminus rest EOT search = get_action(:search) search.summary "Search for collections matching a regular expression." search.arguments "<regular_expression>" search.returns <<-'EOT' An array of hashes of resource collection info. When used from the Ruby API: returns an array of Puppet::Resource::Type objects. RENDERING ISSUES: yaml and string output for this indirection are currently unusable; use json instead. EOT search.examples <<-'EOT' Retrieve all classes, nodes, and defined types: $ puppet resource_type search '.*' Search for classes related to Nagios: $ puppet resource_type search nagios EOT end diff --git a/lib/puppet/face/status.rb b/lib/puppet/face/status.rb index ffc44a396..3003dc484 100644 --- a/lib/puppet/face/status.rb +++ b/lib/puppet/face/status.rb @@ -1,53 +1,52 @@ require 'puppet/indirector/face' Puppet::Indirector::Face.define(:status, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "View puppet server status." - get_action(:destroy).summary "Invalid for this subcommand." - get_action(:save).summary "Invalid for this subcommand." - get_action(:save).description "Invalid for this subcommand." - get_action(:search).summary "Invalid for this subcommand." + deactivate_action(:destroy) + deactivate_action(:save) + deactivate_action(:search) find = get_action(:find) find.default = true find.summary "Check status of puppet master server." find.arguments "<dummy_text>" find.returns <<-'EOT' A "true" response or a low-level connection error. When used from the Ruby API: returns a Puppet::Status object. EOT find.description <<-'EOT' Checks whether a Puppet server is properly receiving and processing HTTP requests. This action is only useful when used with '--terminus rest'; when invoked with the `local` terminus, `find` will always return true. Over REST, this action will query the configured puppet master by default. To query other servers, including puppet agent nodes started with the <--listen> option, you can set the global <--server> and <--masterport> options on the command line; note that agent nodes listen on port 8139. EOT find.short_description <<-EOT Checks whether a Puppet server is properly receiving and processing HTTP requests. Due to a known bug, this action requires a dummy argument, the content of which is irrelevant. This action is only useful when used with '--terminus rest', and will always return true when invoked locally. EOT find.notes <<-'EOT' This action requires that the server's `auth.conf` file allow find access to the `status` REST terminus. Puppet agent does not use this facility, and it is turned off by default. See <http://docs.puppetlabs.com/guides/rest_auth_conf.html> for more details. Although this action always returns an unnamed status object, it requires a dummy argument. This is a known bug. EOT find.examples <<-'EOT' Check the status of the configured puppet master: $ puppet status find x --terminus rest EOT end diff --git a/lib/puppet/interface/action_manager.rb b/lib/puppet/interface/action_manager.rb index e74e821b5..d5107f470 100644 --- a/lib/puppet/interface/action_manager.rb +++ b/lib/puppet/interface/action_manager.rb @@ -1,89 +1,97 @@ # This class is not actually public API, but the method # {Puppet::Interface::ActionManager#action action} is public when used # as part of the Faces DSL (i.e. from within a # {Puppet::Interface.define define} block). # @api public module Puppet::Interface::ActionManager # Declare that this app can take a specific action, and provide # the code to do so. # Defines a new action. This takes a block to build the action using # the methods on {Puppet::Interface::ActionBuilder}. # @param name [Symbol] The name that will be used to invoke the # action # @overload action(name, {|| block}) # @return [void] # @api public # @dsl Faces def action(name, &block) @actions ||= {} Puppet.warning "Redefining action #{name} for #{self}" if action?(name) action = Puppet::Interface::ActionBuilder.build(self, name, &block) # REVISIT: (#18042) doesn't this mean we can't redefine the default action? -- josh if action.default and current = get_default_action raise "Actions #{current.name} and #{name} cannot both be default" end @actions[action.name] = action end # Returns the list of available actions for this face. # @return [Array<Symbol>] The names of the actions for this face # @api private def actions @actions ||= {} result = @actions.keys if self.is_a?(Class) and superclass.respond_to?(:actions) result += superclass.actions elsif self.class.respond_to?(:actions) result += self.class.actions end # We need to uniq the result, because we duplicate actions when they are # fetched to ensure that they have the correct bindings; they shadow the # parent, and uniq implements that. --daniel 2011-06-01 - result.uniq.sort + (result - @deactivated_actions.to_a).uniq.sort end # Retrieves a named action # @param name [Symbol] The name of the action # @return [Puppet::Interface::Action] The action object # @api private def get_action(name) @actions ||= {} result = @actions[name.to_sym] if result.nil? if self.is_a?(Class) and superclass.respond_to?(:get_action) found = superclass.get_action(name) elsif self.class.respond_to?(:get_action) found = self.class.get_action(name) end if found then # This is not the nicest way to make action equivalent to the Ruby # Method object, rather than UnboundMethod, but it will do for now, # and we only have to make this change in *one* place. --daniel 2011-04-12 result = @actions[name.to_sym] = found.__dup_and_rebind_to(self) end end return result end # Retrieves the default action for the face # @return [Puppet::Interface::Action] # @api private def get_default_action default = actions.map {|x| get_action(x) }.select {|x| x.default } if default.length > 1 raise "The actions #{default.map(&:name).join(", ")} cannot all be default" end default.first end + # Deactivate a named action + # @return [Puppet::Interface::Action] + # @api public + def deactivate_action(name) + @deactivated_actions ||= Set.new + @deactivated_actions.add name.to_sym + end + # @api private def action?(name) actions.include?(name.to_sym) end end diff --git a/spec/unit/face/file_spec.rb b/spec/unit/face/file_spec.rb index ad51a2600..cef1141ff 100755 --- a/spec/unit/face/file_spec.rb +++ b/spec/unit/face/file_spec.rb @@ -1,12 +1,10 @@ #! /usr/bin/env ruby require 'spec_helper' require 'puppet/face' describe Puppet::Face[:file, '0.0.1'] do - it_should_behave_like "an indirector face" - - [:download, :store].each do |action| + [:download, :store, :find, :info, :save].each do |action| it { should be_action action } it { should respond_to action } end end