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.



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

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

#inventory=(value) ⇒ Object (writeonly)

Sets the attribute inventory

Parameters:

  • value

    the value to set the attribute inventory to.



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

def inventory=(value)
  @inventory = value
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



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

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

Instance Method Details

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

Returns:

  • (Boolean)


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

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

#featuresObject



66
67
68
69
70
71
72
# File 'lib/bolt/target.rb', line 66

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

#hashObject



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

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

#hostObject



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

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.



94
95
96
# File 'lib/bolt/target.rb', line 94

def name
  uri
end

#passwordObject



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

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

#portObject



98
99
100
# File 'lib/bolt/target.rb', line 98

def port
  @uri_obj.port || @port
end

#protocolObject



102
103
104
# File 'lib/bolt/target.rb', line 102

def protocol
  @uri_obj.scheme || @protocol
end

#to_sObject



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

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

#update_conf(conf) ⇒ Object



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

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



106
107
108
# File 'lib/bolt/target.rb', line 106

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