Class: Puppet::Indirector::Request
- Includes:
- Util::PsychSupport, Util::Warnings
- Defined in:
- lib/puppet/indirector/request.rb
Overview
This class encapsulates all of the information you need to make an Indirection call, and as a result also handles REST calls. It’s somewhat analogous to an HTTP Request object, except tuned for our Indirector.
Constant Summary collapse
- OPTION_ATTRIBUTES =
trusted_information is specifically left out because we can’t serialize it and keep it “trusted”
[:ip, :node, :authenticated, :ignore_terminus, :ignore_cache, :ignore_cache_save, :instance, :environment]
Instance Attribute Summary collapse
-
#authenticated ⇒ Object
Returns the value of attribute authenticated.
-
#ignore_cache ⇒ Object
Returns the value of attribute ignore_cache.
-
#ignore_cache_save ⇒ Object
Returns the value of attribute ignore_cache_save.
-
#ignore_terminus ⇒ Object
Returns the value of attribute ignore_terminus.
-
#indirection_name ⇒ Object
Returns the value of attribute indirection_name.
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#key ⇒ Object
Returns the value of attribute key.
-
#method ⇒ Object
Returns the value of attribute method.
-
#node ⇒ Object
Returns the value of attribute node.
-
#options ⇒ Object
Returns the value of attribute options.
-
#port ⇒ Object
Returns the value of attribute port.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#server ⇒ Object
Returns the value of attribute server.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#authenticated? ⇒ Boolean
Is this an authenticated request?.
- #description ⇒ Object
- #environment ⇒ Object
- #environment=(env) ⇒ Object
-
#ignore_cache? ⇒ Boolean
LAK:NOTE This is a messy interface to the cache, and it’s only used by the Configurer class.
- #ignore_cache_save? ⇒ Boolean
- #ignore_terminus? ⇒ Boolean
-
#indirection ⇒ Object
Look up the indirection based on the name provided.
-
#initialize(indirection_name, method, key, instance, options = {}) ⇒ Request
constructor
A new instance of Request.
- #initialize_from_hash(hash) ⇒ Object
- #model ⇒ Object
-
#plural? ⇒ Boolean
Are we trying to interact with multiple resources, or just one?.
- #remote? ⇒ Boolean
- #to_data_hash ⇒ Object
- #to_hash ⇒ Object
Methods included from Util::Warnings
clear_warnings, debug_once, maybe_log, notice_once, warnonce
Methods included from Util::PsychSupport
Constructor Details
#initialize(indirection_name, method, key, instance, options = {}) ⇒ Request
Returns a new instance of Request.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppet/indirector/request.rb', line 64 def initialize(indirection_name, method, key, instance, = {}) @instance = instance ||= {} self.indirection_name = indirection_name self.method = method = .each_with_object({}) { |ary, hash| hash[ary[0].to_sym] = ary[1]; } set_attributes() @options = if key # If the request key is a URI, then we need to treat it specially, # because it rewrites the key. We could otherwise strip server/port/etc # info out in the REST class, but it seemed bad design for the REST # class to rewrite the key. if key.to_s =~ %r{^\w+:/} and !Puppet::Util.absolute_path?(key.to_s) # it's a URI set_uri_key(key) else @key = key end end @key = @instance.name if !@key and @instance end |
Instance Attribute Details
#authenticated ⇒ Object
Returns the value of attribute authenticated.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def authenticated @authenticated end |
#ignore_cache ⇒ Object
Returns the value of attribute ignore_cache.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def ignore_cache @ignore_cache end |
#ignore_cache_save ⇒ Object
Returns the value of attribute ignore_cache_save.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def ignore_cache_save @ignore_cache_save end |
#ignore_terminus ⇒ Object
Returns the value of attribute ignore_terminus.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def ignore_terminus @ignore_terminus end |
#indirection_name ⇒ Object
Returns the value of attribute indirection_name.
20 21 22 |
# File 'lib/puppet/indirector/request.rb', line 20 def indirection_name @indirection_name end |
#instance ⇒ Object
Returns the value of attribute instance.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def instance @instance end |
#ip ⇒ Object
Returns the value of attribute ip.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def ip @ip end |
#key ⇒ Object
Returns the value of attribute key.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def key @key end |
#method ⇒ Object
Returns the value of attribute method.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def method @method end |
#node ⇒ Object
Returns the value of attribute node.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def node @node end |
#options ⇒ Object
Returns the value of attribute options.
16 17 18 |
# File 'lib/puppet/indirector/request.rb', line 16 def @options end |
#port ⇒ Object
Returns the value of attribute port.
18 19 20 |
# File 'lib/puppet/indirector/request.rb', line 18 def port @port end |
#protocol ⇒ Object
Returns the value of attribute protocol.
18 19 20 |
# File 'lib/puppet/indirector/request.rb', line 18 def protocol @protocol end |
#server ⇒ Object
Returns the value of attribute server.
18 19 20 |
# File 'lib/puppet/indirector/request.rb', line 18 def server @server end |
#uri ⇒ Object
Returns the value of attribute uri.
18 19 20 |
# File 'lib/puppet/indirector/request.rb', line 18 def uri @uri end |
Instance Method Details
#authenticated? ⇒ Boolean
Is this an authenticated request?
27 28 29 30 |
# File 'lib/puppet/indirector/request.rb', line 27 def authenticated? # Double negative, so we just get true or false !!authenticated end |
#description ⇒ Object
142 143 144 |
# File 'lib/puppet/indirector/request.rb', line 142 def description uri || "/#{indirection_name}/#{key}" end |
#environment ⇒ Object
32 33 34 35 36 |
# File 'lib/puppet/indirector/request.rb', line 32 def environment # If environment has not been set directly, we should use the application's # current environment @environment ||= Puppet.lookup(:current_environment) end |
#environment=(env) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/puppet/indirector/request.rb', line 38 def environment=(env) @environment = if env.is_a?(Puppet::Node::Environment) env else Puppet.lookup(:environments).get!(env) end end |
#ignore_cache? ⇒ Boolean
LAK:NOTE This is a messy interface to the cache, and it’s only used by the Configurer class. I decided it was better to implement it now and refactor later, when we have a better design, than to spend another month coming up with a design now that might not be any better.
52 53 54 |
# File 'lib/puppet/indirector/request.rb', line 52 def ignore_cache? ignore_cache end |
#ignore_cache_save? ⇒ Boolean
56 57 58 |
# File 'lib/puppet/indirector/request.rb', line 56 def ignore_cache_save? ignore_cache_save end |
#ignore_terminus? ⇒ Boolean
60 61 62 |
# File 'lib/puppet/indirector/request.rb', line 60 def ignore_terminus? ignore_terminus end |
#indirection ⇒ Object
Look up the indirection based on the name provided.
94 95 96 |
# File 'lib/puppet/indirector/request.rb', line 94 def indirection Puppet::Indirector::Indirection.instance(indirection_name) end |
#initialize_from_hash(hash) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/puppet/indirector/request.rb', line 114 def initialize_from_hash(hash) @indirection_name = hash['indirection_name'].to_sym @method = hash['method'].to_sym @key = hash['key'] @instance = hash['instance'] @options = hash['options'] end |
#model ⇒ Object
102 103 104 105 106 107 |
# File 'lib/puppet/indirector/request.rb', line 102 def model ind = indirection raise ArgumentError, _("Could not find indirection '%{indirection}'") % { indirection: indirection_name } unless ind ind.model end |
#plural? ⇒ Boolean
Are we trying to interact with multiple resources, or just one?
110 111 112 |
# File 'lib/puppet/indirector/request.rb', line 110 def plural? method == :search end |
#remote? ⇒ Boolean
146 147 148 |
# File 'lib/puppet/indirector/request.rb', line 146 def remote? node or ip end |
#to_data_hash ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/puppet/indirector/request.rb', line 122 def to_data_hash { 'indirection_name' => @indirection_name.to_s, 'method' => @method.to_s, 'key' => @key, 'instance' => @instance, 'options' => @options } end |
#to_hash ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/puppet/indirector/request.rb', line 130 def to_hash result = .dup OPTION_ATTRIBUTES.each do |attribute| value = send(attribute) if value result[attribute] = value end end result end |