Class: Bolt::ApplyTarget
- Inherits:
-
Object
- Object
- Bolt::ApplyTarget
- Defined in:
- lib/bolt/apply_target.rb
Constant Summary collapse
- ATTRIBUTES =
%i[uri name target_alias config vars facts features plugin_hooks safe_name].freeze
- COMPUTED =
%i[host password port protocol user].freeze
Class Method Summary collapse
-
._pcore_init_from_hash ⇒ Object
rubocop:enable Lint/UnusedMethodArgument.
-
.from_asserted_args(uri = nil, name = nil, safe_name = nil, target_alias = nil, config = nil, facts = nil, vars = nil, features = nil, plugin_hooks = nil) ⇒ Object
Target.new from a plan with just a uri.
-
.from_asserted_hash(hash) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument Target.new from a plan initialized with a hash.
Instance Method Summary collapse
- #_pcore_init_from_hash(init_hash) ⇒ Object
-
#initialize(target_hash, config) ⇒ ApplyTarget
constructor
A new instance of ApplyTarget.
- #parse_uri(string) ⇒ Object
Constructor Details
#initialize(target_hash, config) ⇒ ApplyTarget
Returns a new instance of ApplyTarget.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bolt/apply_target.rb', line 43 def initialize(target_hash, config) ATTRIBUTES.each do |attr| instance_variable_set("@#{attr}", target_hash[attr.to_s]) end # Merge the config hash with inventory config config = Bolt::Util.deep_merge(config, @config) transport = config['transport'] || 'ssh' t_conf = config['transports'][transport] || {} uri_obj = parse_uri(uri) @host = uri_obj.hostname || t_conf['host'] @password = Addressable::URI.unencode_component(uri_obj.password) || t_conf['password'] @port = uri_obj.port || t_conf['port'] @protocol = uri_obj.scheme || transport @user = Addressable::URI.unencode_component(uri_obj.user) || t_conf['user'] end |
Class Method Details
._pcore_init_from_hash ⇒ Object
rubocop:enable Lint/UnusedMethodArgument
32 33 34 |
# File 'lib/bolt/apply_target.rb', line 32 def self._pcore_init_from_hash raise "ApplyTarget shouldn't be instantiated from a pcore_init class method. How did this get called?" end |
.from_asserted_args(uri = nil, name = nil, safe_name = nil, target_alias = nil, config = nil, facts = nil, vars = nil, features = nil, plugin_hooks = nil) ⇒ Object
Target.new from a plan with just a uri.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bolt/apply_target.rb', line 19 def self.from_asserted_args(uri = nil, name = nil, safe_name = nil, target_alias = nil, config = nil, facts = nil, vars = nil, features = nil, plugin_hooks = nil) raise Bolt::Error.new("Target objects cannot be instantiated inside apply blocks", 'bolt/apply-error') end |
.from_asserted_hash(hash) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument Target.new from a plan initialized with a hash
14 15 16 |
# File 'lib/bolt/apply_target.rb', line 14 def self.from_asserted_hash(hash) raise Bolt::Error.new("Target objects cannot be instantiated inside apply blocks", 'bolt/apply-error') end |
Instance Method Details
#_pcore_init_from_hash(init_hash) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/bolt/apply_target.rb', line 36 def _pcore_init_from_hash(init_hash) inventory = Puppet.lookup(:bolt_inventory) initialize(init_hash, inventory.config_hash) inventory.create_apply_target(self) self end |
#parse_uri(string) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bolt/apply_target.rb', line 60 def parse_uri(string) require 'addressable/uri' if string.nil? Addressable::URI.new # Forbid empty uri elsif string.empty? raise Bolt::ParseError, "Could not parse target URI: URI is empty string" elsif string =~ %r{^[^:]+://} Addressable::URI.parse(string) else # Initialize with an empty scheme to ensure we parse the hostname correctly Addressable::URI.parse("//#{string}") end rescue Addressable::URI::InvalidURIError => e raise Bolt::ParseError, "Could not parse target URI: #{e.}" end |