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.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bolt/target.rb', line 20

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

  if @options['user']
    @user = @options['user']
  end

  if @options['password']
    @password = @options['password']
  end

  if @options['port']
    @port = @options['port']
  end

  if @options['protocol']
    @protocol = @options['protocol']
  end
end

Instance Attribute Details

#inventoryObject

CODEREVIEW: this feels wrong. The altertative is threading inventory through the executor to the RemoteTransport



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

def inventory
  @inventory
end

#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



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

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

Instance Method Details

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

Returns:

  • (Boolean)


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

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

#featuresObject



70
71
72
73
74
75
76
# File 'lib/bolt/target.rb', line 70

def features
  if @inventory
    @inventory.features(self)
  else
    Set.new
  end
end

#hashObject



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

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

#hostObject



104
105
106
# File 'lib/bolt/target.rb', line 104

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.



110
111
112
# File 'lib/bolt/target.rb', line 110

def name
  uri
end

#passwordObject



135
136
137
# File 'lib/bolt/target.rb', line 135

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

#portObject



118
119
120
# File 'lib/bolt/target.rb', line 118

def port
  @uri_obj.port || @port
end

#protocolObject



127
128
129
# File 'lib/bolt/target.rb', line 127

def protocol
  @uri_obj.scheme || @protocol
end

#remote?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/bolt/target.rb', line 114

def remote?
  @uri_obj.scheme == 'remote' || @protocol == 'remote'
end

#to_hObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bolt/target.rb', line 92

def to_h
  options.merge(
    'name' => name,
    'uri' => uri,
    'protocol' => protocol,
    'user' => user,
    'password' => password,
    'host' => host,
    'port' => port
  )
end

#to_sObject



87
88
89
90
# File 'lib/bolt/target.rb', line 87

def to_s
  opts = @options.select { |k, _| PRINT_OPTS.include? k }
  "Target('#{@uri}', #{opts})"
end

#transportObject

transport is separate from protocol for remote targets.



123
124
125
# File 'lib/bolt/target.rb', line 123

def transport
  remote? ? 'remote' : protocol
end

#update_conf(conf) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bolt/target.rb', line 43

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

  t_conf = conf[:transports][transport.to_sym] || {}
  # Override url methods
  @user = t_conf['user']
  @password = t_conf['password']
  @port = t_conf['port']

  # Preserve everything in options so we can easily create copies of a Target.
  @options = t_conf.merge(@options)

  self
end

#userObject



131
132
133
# File 'lib/bolt/target.rb', line 131

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