Class: Bolt::Target
- Inherits:
-
Object
- Object
- Bolt::Target
- Defined in:
- lib/bolt/target.rb
Instance Attribute Summary collapse
-
#inventory ⇒ Object
CODEREVIEW: this feels wrong.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uri ⇒ Object
CODEREVIEW: this feels wrong.
Class Method Summary collapse
-
.from_asserted_hash(hash) ⇒ Object
Satisfies the Puppet datatypes API.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
TODO: WHAT does equality mean here? should we just compare names? is there something else that is meaninful?.
- #features ⇒ Object
- #hash ⇒ Object
- #host ⇒ Object
-
#initialize(uri, options = nil) ⇒ Target
constructor
URI can be passes as nil.
- #name ⇒ Object
- #password ⇒ Object
- #plugin_hooks ⇒ Object
- #port ⇒ Object
- #protocol ⇒ Object
- #remote? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
-
#transport ⇒ Object
transport is separate from protocol for remote targets.
- #update_conf(conf) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(uri, options = nil) ⇒ Target
URI can be passes as nil
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bolt/target.rb', line 20 def initialize(uri, = nil) # lazy-load expensive gem code require 'addressable/uri' @uri = uri @uri_obj = parse(uri) = || {} .freeze if ['user'] @user = ['user'] end if ['password'] @password = ['password'] end if ['port'] @port = ['port'] end if ['protocol'] @protocol = ['protocol'] end if ['host'] @host = ['host'] end # WARNING: name should never be updated @name = ['name'] || @uri end |
Instance Attribute Details
#inventory ⇒ Object
CODEREVIEW: this feels wrong. The altertative is threading inventory through the executor to the RemoteTransport
10 11 12 |
# File 'lib/bolt/target.rb', line 10 def inventory @inventory end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/bolt/target.rb', line 7 def end |
#uri ⇒ Object
CODEREVIEW: this feels wrong. The altertative is threading inventory through the executor to the RemoteTransport
10 11 12 |
# File 'lib/bolt/target.rb', line 10 def uri @uri end |
Class Method Details
.from_asserted_hash(hash) ⇒ Object
Satisfies the Puppet datatypes API
15 16 17 |
# File 'lib/bolt/target.rb', line 15 def self.from_asserted_hash(hash) new(hash['uri'], hash['options']) end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
TODO: WHAT does equality mean here? should we just compare names? is there something else that is meaninful?
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/bolt/target.rb', line 101 def eql?(other) if self.class.equal?(other.class) if @uri return @uri == other.uri else @name = other.name end end false end |
#features ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/bolt/target.rb', line 83 def features if @inventory @inventory.features(self) else Set.new end end |
#hash ⇒ Object
113 114 115 |
# File 'lib/bolt/target.rb', line 113 def hash @uri.hash ^ .hash end |
#host ⇒ Object
134 135 136 |
# File 'lib/bolt/target.rb', line 134 def host @uri_obj&.hostname || @host end |
#name ⇒ Object
138 139 140 |
# File 'lib/bolt/target.rb', line 138 def name @name || @uri end |
#password ⇒ Object
163 164 165 |
# File 'lib/bolt/target.rb', line 163 def password Addressable::URI.unencode_component(@uri_obj&.password) || @password end |
#plugin_hooks ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/bolt/target.rb', line 91 def plugin_hooks if @inventory @inventory.plugin_hooks(self) else {} end end |
#port ⇒ Object
146 147 148 |
# File 'lib/bolt/target.rb', line 146 def port @uri_obj&.port || @port end |
#protocol ⇒ Object
155 156 157 |
# File 'lib/bolt/target.rb', line 155 def protocol @uri_obj&.scheme || @protocol end |
#remote? ⇒ Boolean
142 143 144 |
# File 'lib/bolt/target.rb', line 142 def remote? @uri_obj&.scheme == 'remote' || @protocol == 'remote' end |
#to_h ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/bolt/target.rb', line 122 def to_h .merge( 'name' => name, 'uri' => uri, 'protocol' => protocol, 'user' => user, 'password' => password, 'host' => host, 'port' => port ) end |
#to_s ⇒ Object
117 118 119 120 |
# File 'lib/bolt/target.rb', line 117 def to_s opts = .select { |k, _| PRINT_OPTS.include? k } "Target('#{@uri}', #{opts})" end |
#transport ⇒ Object
transport is separate from protocol for remote targets.
151 152 153 |
# File 'lib/bolt/target.rb', line 151 def transport remote? ? 'remote' : protocol end |
#update_conf(conf) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bolt/target.rb', line 53 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'] @host = t_conf['host'] # Preserve everything in options so we can easily create copies of a Target. = t_conf.merge() self end |
#user ⇒ Object
159 160 161 |
# File 'lib/bolt/target.rb', line 159 def user Addressable::URI.unencode_component(@uri_obj&.user) || @user end |