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.



15
16
17
18
19
20
# File 'lib/bolt/target.rb', line 15

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

Class Method Details

.from_asserted_hash(hash) ⇒ Object

Satisfies the Puppet datatypes API



11
12
13
# File 'lib/bolt/target.rb', line 11

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

Instance Method Details

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

Returns:



47
48
49
# File 'lib/bolt/target.rb', line 47

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

#hashObject



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

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

#hostObject



60
61
62
# File 'lib/bolt/target.rb', line 60

def host
  @uri_obj.hostname
end

#nameObject

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



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

def name
  uri
end

#passwordObject



84
85
86
87
88
# File 'lib/bolt/target.rb', line 84

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

#portObject



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

def port
  @uri_obj.port || @port
end

#protocolObject



74
75
76
# File 'lib/bolt/target.rb', line 74

def protocol
  @uri_obj.scheme || @protocol
end

#to_sObject



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

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

#update_conf(conf) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bolt/target.rb', line 22

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

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

  url_keys = %w[user password port]
  @options = t_conf.reject { |k, _| url_keys.include?(k) }.merge(@options)

  self
end

#userObject



78
79
80
81
82
# File 'lib/bolt/target.rb', line 78

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