Class: Puppet::Indirector::Terminus
- Extended by:
- Util::Docs, Util::InstanceLoader
- Defined in:
- lib/puppet/indirector/terminus.rb
Overview
A simple class that can function as the base class for indirected types.
Direct Known Subclasses
Code, DirectFileServer, Exec, FileServer, GenericHttp, Hiera, JSON, Memory, Msgpack, None, Plain, REST, StoreConfigs, Yaml
Constant Summary
Constants included from Util
Util::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Constants included from Util::Docs
Class Attribute Summary collapse
-
.abstract_terminus ⇒ Object
readonly
Returns the value of attribute abstract_terminus.
-
.indirection ⇒ Object
Returns the value of attribute indirection.
-
.name ⇒ Object
Returns the value of attribute name.
-
.terminus_type ⇒ Object
Returns the value of attribute terminus_type.
Attributes included from Util::Docs
Class Method Summary collapse
-
.abstract_terminus? ⇒ Boolean
Are we an abstract terminus type, rather than an instance with an associated indirection?.
-
.const2name(const) ⇒ Object
Convert a constant to a short name.
- .indirection_name ⇒ Object
-
.inherited(subclass) ⇒ Object
Register our subclass with the appropriate indirection.
-
.mark_as_abstract_terminus ⇒ Object
Mark that this instance is abstract.
- .model ⇒ Object
-
.name2const(name) ⇒ Object
Convert a short name to a constant.
-
.register_terminus_class(klass) ⇒ Object
Register a class, probably autoloaded.
-
.terminus_class(indirection_name, terminus_type) ⇒ Object
Return a terminus by name, using the autoloader.
-
.terminus_classes(indirection_name) ⇒ Object
Return all terminus classes for a given indirection.
Instance Method Summary collapse
- #allow_remote_requests? ⇒ Boolean
- #indirection ⇒ Object
-
#initialize ⇒ Terminus
constructor
A new instance of Terminus.
- #model ⇒ Object
- #name ⇒ Object
- #require_environment? ⇒ Boolean
- #terminus_type ⇒ Object
- #validate(request) ⇒ Object
- #validate_key(request) ⇒ Object
- #validate_model(request) ⇒ Object
Methods included from Util::InstanceLoader
instance_hash, instance_load, instance_loader, instance_loading?, loaded_instance, loaded_instances
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from Util::Docs
desc, dochook, doctable, markdown_definitionlist, markdown_header, nodoc?, pad, scrub
Constructor Details
Class Attribute Details
.abstract_terminus ⇒ Object (readonly)
Returns the value of attribute abstract_terminus.
16 17 18 |
# File 'lib/puppet/indirector/terminus.rb', line 16 def abstract_terminus @abstract_terminus end |
.indirection ⇒ Object
Returns the value of attribute indirection.
16 17 18 |
# File 'lib/puppet/indirector/terminus.rb', line 16 def indirection @indirection end |
.name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'lib/puppet/indirector/terminus.rb', line 15 def name @name end |
.terminus_type ⇒ Object
Returns the value of attribute terminus_type.
15 16 17 |
# File 'lib/puppet/indirector/terminus.rb', line 15 def terminus_type @terminus_type end |
Class Method Details
.abstract_terminus? ⇒ Boolean
Are we an abstract terminus type, rather than an instance with an associated indirection?
20 21 22 |
# File 'lib/puppet/indirector/terminus.rb', line 20 def abstract_terminus? abstract_terminus end |
.const2name(const) ⇒ Object
Convert a constant to a short name.
25 26 27 |
# File 'lib/puppet/indirector/terminus.rb', line 25 def const2name(const) const.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_#{i.downcase}" }.intern end |
.indirection_name ⇒ Object
43 44 45 |
# File 'lib/puppet/indirector/terminus.rb', line 43 def indirection_name @indirection.name end |
.inherited(subclass) ⇒ Object
Register our subclass with the appropriate indirection. This follows the convention that our terminus is named after the indirection.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 |
# File 'lib/puppet/indirector/terminus.rb', line 50 def inherited(subclass) longname = subclass.to_s if longname =~ /#<Class/ raise Puppet::DevError, _("Terminus subclasses must have associated constants") end names = longname.split("::") # Convert everything to a lower-case symbol, converting camelcase to underscore word separation. name = names.pop.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_#{i.downcase}" }.intern subclass.name = name # Short-circuit the abstract types, which are those that directly subclass # the Terminus class. if self == Puppet::Indirector::Terminus subclass.mark_as_abstract_terminus return end # Set the terminus type to be the name of the abstract terminus type. # Yay, class/instance confusion. subclass.terminus_type = self.name # This subclass is specifically associated with an indirection. raise("Invalid name #{longname}") unless names.length > 0 processed_name = names.pop.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_#{i.downcase}" } if processed_name.empty? raise Puppet::DevError, _("Could not discern indirection model from class constant") end # This will throw an exception if the indirection instance cannot be found. # Do this last, because it also registers the terminus type with the indirection, # which needs the above information. subclass.indirection = processed_name.intern # And add this instance to the instance hash. Puppet::Indirector::Terminus.register_terminus_class(subclass) end |
.mark_as_abstract_terminus ⇒ Object
Mark that this instance is abstract.
91 92 93 |
# File 'lib/puppet/indirector/terminus.rb', line 91 def mark_as_abstract_terminus @abstract_terminus = true end |
.model ⇒ Object
95 96 97 |
# File 'lib/puppet/indirector/terminus.rb', line 95 def model indirection.model end |
.name2const(name) ⇒ Object
Convert a short name to a constant.
100 101 102 |
# File 'lib/puppet/indirector/terminus.rb', line 100 def name2const(name) name.to_s.capitalize.sub(/_(.)/) { |i| $1.upcase } end |
.register_terminus_class(klass) ⇒ Object
Register a class, probably autoloaded.
105 106 107 108 |
# File 'lib/puppet/indirector/terminus.rb', line 105 def register_terminus_class(klass) setup_instance_loading klass.indirection_name instance_hash(klass.indirection_name)[klass.name] = klass end |
.terminus_class(indirection_name, terminus_type) ⇒ Object
Return a terminus by name, using the autoloader.
111 112 113 114 |
# File 'lib/puppet/indirector/terminus.rb', line 111 def terminus_class(indirection_name, terminus_type) setup_instance_loading indirection_name loaded_instance(indirection_name, terminus_type) end |
.terminus_classes(indirection_name) ⇒ Object
Return all terminus classes for a given indirection.
117 118 119 120 121 122 |
# File 'lib/puppet/indirector/terminus.rb', line 117 def terminus_classes(indirection_name) setup_instance_loading indirection_name instance_loader(indirection_name).files_to_load(Puppet.lookup(:current_environment)).map do |file| File.basename(file).chomp(".rb").intern end end |
Instance Method Details
#allow_remote_requests? ⇒ Boolean
151 152 153 |
# File 'lib/puppet/indirector/terminus.rb', line 151 def allow_remote_requests? true end |
#indirection ⇒ Object
131 132 133 |
# File 'lib/puppet/indirector/terminus.rb', line 131 def indirection self.class.indirection end |
#model ⇒ Object
139 140 141 |
# File 'lib/puppet/indirector/terminus.rb', line 139 def model self.class.model end |
#name ⇒ Object
143 144 145 |
# File 'lib/puppet/indirector/terminus.rb', line 143 def name self.class.name end |
#require_environment? ⇒ Boolean
147 148 149 |
# File 'lib/puppet/indirector/terminus.rb', line 147 def require_environment? true end |
#terminus_type ⇒ Object
155 156 157 |
# File 'lib/puppet/indirector/terminus.rb', line 155 def terminus_type self.class.terminus_type end |
#validate(request) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/puppet/indirector/terminus.rb', line 159 def validate(request) if request.instance validate_model(request) validate_key(request) end end |
#validate_key(request) ⇒ Object
166 167 168 169 170 |
# File 'lib/puppet/indirector/terminus.rb', line 166 def validate_key(request) unless request.key == request.instance.name raise Puppet::Indirector::ValidationError, _("Instance name %{name} does not match requested key %{key}") % { name: request.instance.name.inspect, key: request.key.inspect } end end |
#validate_model(request) ⇒ Object
172 173 174 175 176 |
# File 'lib/puppet/indirector/terminus.rb', line 172 def validate_model(request) unless model === request.instance raise Puppet::Indirector::ValidationError, _("Invalid instance type %{klass}, expected %{model_type}") % { klass: request.instance.class.inspect, model_type: model.inspect } end end |