Class: Bolt::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/target.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = nil) ⇒ Target

Returns a new instance of Target.



13
14
15
16
17
# File 'lib/bolt/target.rb', line 13

def initialize(uri, options = nil)
  @uri = uri
  @uri_obj = parse(uri)
  @options = options || {}
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/bolt/target.rb', line 6

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/bolt/target.rb', line 6

def uri
  @uri
end

Class Method Details

.from_asserted_hash(hash) ⇒ Object

Satisfies the Puppet datatypes API



9
10
11
# File 'lib/bolt/target.rb', line 9

def self.from_asserted_hash(hash)
  new(hash['uri'], hash['options'])
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


44
45
46
# File 'lib/bolt/target.rb', line 44

def eql?(other)
  self.class.equal?(other.class) && @uri == other.uri
end

#hashObject



49
50
51
# File 'lib/bolt/target.rb', line 49

def hash
  @uri.hash ^ @options.hash
end

#hostObject



57
58
59
# File 'lib/bolt/target.rb', line 57

def host
  @uri_obj.hostname
end

#nameObject

name is currently just uri but should be be used instead to identify the Target ouside the transport or uri options.



63
64
65
# File 'lib/bolt/target.rb', line 63

def name
  uri
end

#passwordObject



81
82
83
84
85
# File 'lib/bolt/target.rb', line 81

def password
  Addressable::URI.unencode_component(
    @uri_obj.password || @password
  )
end

#portObject



67
68
69
# File 'lib/bolt/target.rb', line 67

def port
  @uri_obj.port || @port
end

#protocolObject



71
72
73
# File 'lib/bolt/target.rb', line 71

def protocol
  @uri_obj.scheme || @protocol
end

#to_sObject



53
54
55
# File 'lib/bolt/target.rb', line 53

def to_s
  "Target('#{@uri}', #{@options})"
end

#update_conf(conf) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bolt/target.rb', line 19

def update_conf(conf)
  @protocol = conf[:transport]

  t_conf = conf[:transports][protocol.to_sym]
  # Override url methods
  url_keys = %i[user password port]
  @user = t_conf[:user]
  @password = t_conf[:password]
  @port = t_conf[:port]

  @options = t_conf.reject { |k, _| url_keys.include?(k) }.merge(@options)

  self
end

#userObject



75
76
77
78
79
# File 'lib/bolt/target.rb', line 75

def user
  Addressable::URI.unencode_component(
    @uri_obj.user || @user
  )
end