lib/bolt/target.rb in bolt-1.5.0 vs lib/bolt/target.rb in bolt-1.6.0
- old
+ new
@@ -4,11 +4,13 @@
require 'bolt/error'
module Bolt
class Target
attr_reader :uri, :options
- attr_writer :inventory
+ # CODEREVIEW: this feels wrong. The altertative is threading inventory through the
+ # executor to the RemoteTransport
+ attr_accessor :inventory
PRINT_OPTS ||= %w[host user port protocol].freeze
# Satisfies the Puppet datatypes API
def self.from_asserted_hash(hash)
@@ -39,11 +41,11 @@
end
def update_conf(conf)
@protocol = conf[:transport]
- t_conf = conf[:transports][protocol.to_sym]
+ t_conf = conf[:transports][transport.to_sym] || {}
# Override url methods
@user = t_conf['user']
@password = t_conf['password']
@port = t_conf['port']
@@ -83,21 +85,42 @@
def to_s
opts = @options.select { |k, _| PRINT_OPTS.include? k }
"Target('#{@uri}', #{opts})"
end
+ def to_h
+ options.merge(
+ 'name' => name,
+ 'uri' => uri,
+ 'protocol' => protocol,
+ 'user' => user,
+ 'password' => password,
+ 'host' => host,
+ 'port' => port
+ )
+ end
+
def host
@uri_obj.hostname
end
# name is currently just uri but should be used instead to identify the
# Target ouside the transport or uri options.
def name
uri
end
+ def remote?
+ @uri_obj.scheme == 'remote' || @protocol == 'remote'
+ end
+
def port
@uri_obj.port || @port
+ end
+
+ # transport is separate from protocol for remote targets.
+ def transport
+ remote? ? 'remote' : protocol
end
def protocol
@uri_obj.scheme || @protocol
end