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, Ldap, Memory, Msgpack, None, Plain, REST, SslFile, StoreConfigs, Yaml
Constant Summary
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
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
- #terminus_type ⇒ Object
- #validate(request) ⇒ Object
- #validate_key(request) ⇒ Object
- #validate_model(request) ⇒ Object
Methods included from Util::InstanceLoader
instance_docs, instance_hash, instance_load, instance_loader, instance_loading?, loaded_instance, loaded_instances
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#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.
15 16 17 |
# File 'lib/puppet/indirector/terminus.rb', line 15 def abstract_terminus @abstract_terminus end |
.indirection ⇒ Object
Returns the value of attribute indirection.
15 16 17 |
# File 'lib/puppet/indirector/terminus.rb', line 15 def indirection @indirection end |
.name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/puppet/indirector/terminus.rb', line 14 def name @name end |
.terminus_type ⇒ Object
Returns the value of attribute terminus_type.
14 15 16 |
# File 'lib/puppet/indirector/terminus.rb', line 14 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?
19 20 21 |
# File 'lib/puppet/indirector/terminus.rb', line 19 def abstract_terminus? abstract_terminus end |
.const2name(const) ⇒ Object
Convert a constant to a short name.
24 25 26 |
# File 'lib/puppet/indirector/terminus.rb', line 24 def const2name(const) const.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_#{i.downcase}" }.intern end |
.indirection_name ⇒ Object
39 40 41 |
# File 'lib/puppet/indirector/terminus.rb', line 39 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.
46 47 48 49 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 |
# File 'lib/puppet/indirector/terminus.rb', line 46 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.
87 88 89 |
# File 'lib/puppet/indirector/terminus.rb', line 87 def mark_as_abstract_terminus @abstract_terminus = true end |
.model ⇒ Object
91 92 93 |
# File 'lib/puppet/indirector/terminus.rb', line 91 def model indirection.model end |
.name2const(name) ⇒ Object
Convert a short name to a constant.
96 97 98 |
# File 'lib/puppet/indirector/terminus.rb', line 96 def name2const(name) name.to_s.capitalize.sub(/_(.)/) { |i| $1.upcase } end |
.register_terminus_class(klass) ⇒ Object
Register a class, probably autoloaded.
101 102 103 104 |
# File 'lib/puppet/indirector/terminus.rb', line 101 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.
107 108 109 110 |
# File 'lib/puppet/indirector/terminus.rb', line 107 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.
113 114 115 116 117 118 |
# File 'lib/puppet/indirector/terminus.rb', line 113 def terminus_classes(indirection_name) setup_instance_loading indirection_name instance_loader(indirection_name).files_to_load.map do |file| File.basename(file).chomp(".rb").intern end end |
Instance Method Details
#allow_remote_requests? ⇒ Boolean
143 144 145 |
# File 'lib/puppet/indirector/terminus.rb', line 143 def allow_remote_requests? true end |
#indirection ⇒ Object
127 128 129 |
# File 'lib/puppet/indirector/terminus.rb', line 127 def indirection self.class.indirection end |
#model ⇒ Object
135 136 137 |
# File 'lib/puppet/indirector/terminus.rb', line 135 def model self.class.model end |
#name ⇒ Object
139 140 141 |
# File 'lib/puppet/indirector/terminus.rb', line 139 def name self.class.name end |
#terminus_type ⇒ Object
147 148 149 |
# File 'lib/puppet/indirector/terminus.rb', line 147 def terminus_type self.class.terminus_type end |
#validate(request) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/puppet/indirector/terminus.rb', line 151 def validate(request) if request.instance validate_model(request) validate_key(request) end end |
#validate_key(request) ⇒ Object
158 159 160 161 162 |
# File 'lib/puppet/indirector/terminus.rb', line 158 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
164 165 166 167 168 |
# File 'lib/puppet/indirector/terminus.rb', line 164 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 |