403Webshell
Server IP : 172.67.158.161  /  Your IP : 3.12.34.253
Web Server : LiteSpeed
System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : giankuin ( 1871)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector//face.rb
require_relative '../../puppet/face'

class Puppet::Indirector::Face < Puppet::Face
  option "--terminus _" + _("TERMINUS") do
    summary _("The indirector terminus to use.")
    description <<-EOT
      Indirector faces expose indirected subsystems of Puppet. These
      subsystems are each able to retrieve and alter a specific type of data
      (with the familiar actions of `find`, `search`, `save`, and `destroy`)
      from an arbitrary number of pluggable backends. In Puppet parlance,
      these backends are called terminuses.

      Almost all indirected subsystems have a `rest` terminus that interacts
      with the puppet master's data. Most of them have additional terminuses
      for various local data models, which are in turn used by the indirected
      subsystem on the puppet master whenever it receives a remote request.

      The terminus for an action is often determined by context, but
      occasionally needs to be set explicitly. See the "Notes" section of this
      face's manpage for more details.
    EOT

    before_action do |action, args, options|
      set_terminus(options[:terminus])
    end

    after_action do |action, args, options|
      indirection.reset_terminus_class
    end
  end

  def self.indirections
    Puppet::Indirector::Indirection.instances.collect { |t| t.to_s }.sort
  end

  def self.terminus_classes(indirection)
    Puppet::Indirector::Terminus.terminus_classes(indirection.to_sym).collect { |t| t.to_s }.sort
  end

  def call_indirection_method(method, key, options)
    begin
      if method == :save
        # key is really the instance to save
        result = indirection.__send__(method, key, nil, options)
      else
        result = indirection.__send__(method, key, options)
      end
    rescue => detail
      message = _("Could not call '%{method}' on '%{indirection}': %{detail}") % { method: method, indirection: indirection_name, detail: detail }
      Puppet.log_exception(detail, message)
      raise RuntimeError, message, detail.backtrace
    end

    return result
  end

  option "--extra " + _("HASH") do
    summary _("Extra arguments to pass to the indirection request")
    description <<-EOT
      A terminus can take additional arguments to refine the operation, which
      are passed as an arbitrary hash to the back-end.  Anything passed as
      the extra value is just send direct to the back-end.
    EOT
    default_to do Hash.new end
  end

  action :destroy do
    summary _("Delete an object.")
    arguments _("<key>")
    when_invoked {|key, options| call_indirection_method :destroy, key, options[:extra] }
  end

  action :find do
    summary _("Retrieve an object by name.")
    arguments _("[<key>]")
    when_invoked do |*args|
      # Default the key to Puppet[:certname] if none is supplied
      if args.length == 1
        key = Puppet[:certname]
        options = args.last
      else
        key, options = *args
      end
      call_indirection_method :find, key, options[:extra]
    end
  end

  action :save do
    summary _("API only: create or overwrite an object.")
    arguments _("<key>")
    description <<-EOT
      API only: create or overwrite an object. As the Faces framework does not
      currently accept data from STDIN, save actions cannot currently be invoked
      from the command line.
    EOT
    when_invoked {|key, options| call_indirection_method :save, key, options[:extra] }
  end

  action :search do
    summary _("Search for an object or retrieve multiple objects.")
    arguments _("<query>")
    when_invoked {|key, options| call_indirection_method :search, key, options[:extra] }
  end

  # Print the configuration for the current terminus class
  action :info do
    summary _("Print the default terminus class for this face.")
    description <<-EOT
      Prints the default terminus class for this subcommand. Note that different
      run modes may have different default termini; when in doubt, specify the
      run mode with the '--run_mode' option.
    EOT

    when_invoked do |options|
      if indirection.terminus_class
        _("Run mode '%{mode}': %{terminus}") % { mode: Puppet.run_mode.name, terminus: indirection.terminus_class }
      else
        _("No default terminus class for run mode '%{mode}'") % { mode: Puppet.run_mode.name }
      end
    end
  end

  attr_accessor :from

  def indirection_name
    @indirection_name || name.to_sym
  end

  # Here's your opportunity to override the indirection name.  By default it
  # will be the same name as the face.
  def set_indirection_name(name)
    @indirection_name = name
  end

  # Return an indirection associated with a face, if one exists;
  # One usually does.
  def indirection
    unless @indirection
      @indirection = Puppet::Indirector::Indirection.instance(indirection_name)
      @indirection or raise _("Could not find terminus for %{indirection}") % { indirection: indirection_name }
    end
    @indirection
  end

  def set_terminus(from)
    begin
      indirection.terminus_class = from
    rescue => detail
      msg = _("Could not set '%{indirection}' terminus to '%{from}' (%{detail}); valid terminus types are %{types}") % { indirection: indirection.name, from: from, detail: detail, types: self.class.terminus_classes(indirection.name).join(", ") }
      raise detail, msg, detail.backtrace
    end
  end
end

Youez - 2016 - github.com/yon3zu
LinuXploit