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.
17 18 19 |
# File 'lib/puppet/indirector/terminus.rb', line 17 def abstract_terminus @abstract_terminus end |
.indirection ⇒ Object
Returns the value of attribute indirection.
17 18 19 |
# File 'lib/puppet/indirector/terminus.rb', line 17 def indirection @indirection end |
.name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/puppet/indirector/terminus.rb', line 16 def name @name end |
.terminus_type ⇒ Object
Returns the value of attribute terminus_type.
16 17 18 |
# File 'lib/puppet/indirector/terminus.rb', line 16 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?
21 22 23 |
# File 'lib/puppet/indirector/terminus.rb', line 21 def abstract_terminus? abstract_terminus end |
.const2name(const) ⇒ Object
Convert a constant to a short name.
26 27 28 |
# File 'lib/puppet/indirector/terminus.rb', line 26 def const2name(const) const.sub(/^[A-Z]/, &:downcase).gsub(/[A-Z]/) { |i| "_#{i.downcase}" }.intern end |
.indirection_name ⇒ Object
44 45 46 |
# File 'lib/puppet/indirector/terminus.rb', line 44 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.
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 89 90 91 |
# File 'lib/puppet/indirector/terminus.rb', line 51 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]/, &: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]/, &: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.
94 95 96 |
# File 'lib/puppet/indirector/terminus.rb', line 94 def mark_as_abstract_terminus @abstract_terminus = true end |
.model ⇒ Object
98 99 100 |
# File 'lib/puppet/indirector/terminus.rb', line 98 def model indirection.model end |
.name2const(name) ⇒ Object
Convert a short name to a constant.
103 104 105 |
# File 'lib/puppet/indirector/terminus.rb', line 103 def name2const(name) name.to_s.capitalize.sub(/_(.)/) { |_i| ::Regexp.last_match(1).upcase } end |
.register_terminus_class(klass) ⇒ Object
Register a class, probably autoloaded.
108 109 110 111 |
# File 'lib/puppet/indirector/terminus.rb', line 108 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.
114 115 116 117 |
# File 'lib/puppet/indirector/terminus.rb', line 114 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.
120 121 122 123 124 125 |
# File 'lib/puppet/indirector/terminus.rb', line 120 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
154 155 156 |
# File 'lib/puppet/indirector/terminus.rb', line 154 def allow_remote_requests? true end |
#indirection ⇒ Object
134 135 136 |
# File 'lib/puppet/indirector/terminus.rb', line 134 def indirection self.class.indirection end |
#model ⇒ Object
142 143 144 |
# File 'lib/puppet/indirector/terminus.rb', line 142 def model self.class.model end |
#name ⇒ Object
146 147 148 |
# File 'lib/puppet/indirector/terminus.rb', line 146 def name self.class.name end |
#require_environment? ⇒ Boolean
150 151 152 |
# File 'lib/puppet/indirector/terminus.rb', line 150 def require_environment? true end |
#terminus_type ⇒ Object
158 159 160 |
# File 'lib/puppet/indirector/terminus.rb', line 158 def terminus_type self.class.terminus_type end |
#validate(request) ⇒ Object
162 163 164 165 166 167 |
# File 'lib/puppet/indirector/terminus.rb', line 162 def validate(request) if request.instance validate_model(request) validate_key(request) end end |
#validate_key(request) ⇒ Object
169 170 171 172 173 |
# File 'lib/puppet/indirector/terminus.rb', line 169 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
175 176 177 178 179 |
# File 'lib/puppet/indirector/terminus.rb', line 175 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 |