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
- #detail ⇒ Object
-
#eql?(other) ⇒ Boolean
(also: #==)
TODO: WHAT does equality mean here? should we just compare names? is there something else that is meaninful?.
- #facts ⇒ Object
- #features ⇒ Object (also: #feature_set)
- #hash ⇒ Object
- #host ⇒ Object (also: #safe_name)
-
#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
- #target_alias ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
-
#transport ⇒ Object
transport is separate from protocol for remote targets.
- #update_conf(conf) ⇒ Object
- #user ⇒ Object
- #vars ⇒ Object
Constructor Details
#initialize(uri, options = nil) ⇒ Target
URI can be passes as nil
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/bolt/target.rb', line 163 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
153 154 155 |
# File 'lib/bolt/target.rb', line 153 def inventory @inventory end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
150 151 152 |
# File 'lib/bolt/target.rb', line 150 def end |
#uri ⇒ Object
CODEREVIEW: this feels wrong. The altertative is threading inventory through the executor to the RemoteTransport
153 154 155 |
# File 'lib/bolt/target.rb', line 153 def uri @uri end |
Class Method Details
.from_asserted_hash(hash) ⇒ Object
Satisfies the Puppet datatypes API
158 159 160 |
# File 'lib/bolt/target.rb', line 158 def self.from_asserted_hash(hash) new(hash['uri'], hash['options']) end |
Instance Method Details
#detail ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/bolt/target.rb', line 287 def detail { 'name' => name, 'alias' => target_alias, 'config' => { 'transport' => transport, transport => }, 'vars' => vars, 'facts' => facts, 'features' => features.to_a, 'plugin_hooks' => plugin_hooks } end |
#eql?(other) ⇒ Boolean Also known as: ==
TODO: WHAT does equality mean here? should we just compare names? is there something else that is meaninful?
257 258 259 260 261 262 263 |
# File 'lib/bolt/target.rb', line 257 def eql?(other) if self.class.equal?(other.class) @uri ? @uri == other.uri : @name == other.name else false end end |
#facts ⇒ Object
247 248 249 |
# File 'lib/bolt/target.rb', line 247 def facts @inventory.facts(self) end |
#features ⇒ Object Also known as: feature_set
226 227 228 229 230 231 232 |
# File 'lib/bolt/target.rb', line 226 def features if @inventory @inventory.features(self) else Set.new end end |
#hash ⇒ Object
266 267 268 |
# File 'lib/bolt/target.rb', line 266 def hash @uri.hash ^ .hash end |
#host ⇒ Object Also known as: safe_name
302 303 304 |
# File 'lib/bolt/target.rb', line 302 def host @uri_obj&.hostname || @host end |
#name ⇒ Object
307 308 309 |
# File 'lib/bolt/target.rb', line 307 def name @name || @uri end |
#password ⇒ Object
332 333 334 |
# File 'lib/bolt/target.rb', line 332 def password Addressable::URI.unencode_component(@uri_obj&.password) || @password end |
#plugin_hooks ⇒ Object
235 236 237 238 239 240 241 |
# File 'lib/bolt/target.rb', line 235 def plugin_hooks if @inventory @inventory.plugin_hooks(self) else {} end end |
#port ⇒ Object
315 316 317 |
# File 'lib/bolt/target.rb', line 315 def port @uri_obj&.port || @port end |
#protocol ⇒ Object
324 325 326 |
# File 'lib/bolt/target.rb', line 324 def protocol @uri_obj&.scheme || @protocol end |
#remote? ⇒ Boolean
311 312 313 |
# File 'lib/bolt/target.rb', line 311 def remote? @uri_obj&.scheme == 'remote' || @protocol == 'remote' end |
#target_alias ⇒ Object
251 252 253 |
# File 'lib/bolt/target.rb', line 251 def target_alias @inventory.target_alias(self) end |
#to_h ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/bolt/target.rb', line 275 def to_h .merge( 'name' => name, 'uri' => uri, 'protocol' => protocol, 'user' => user, 'password' => password, 'host' => host, 'port' => port ) end |
#to_s ⇒ Object
270 271 272 273 |
# File 'lib/bolt/target.rb', line 270 def to_s opts = .select { |k, _| PRINT_OPTS.include? k } "Target('#{@uri}', #{opts})" end |
#transport ⇒ Object
transport is separate from protocol for remote targets.
320 321 322 |
# File 'lib/bolt/target.rb', line 320 def transport remote? ? 'remote' : protocol end |
#update_conf(conf) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/bolt/target.rb', line 196 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
328 329 330 |
# File 'lib/bolt/target.rb', line 328 def user Addressable::URI.unencode_component(@uri_obj&.user) || @user end |
#vars ⇒ Object
243 244 245 |
# File 'lib/bolt/target.rb', line 243 def vars @inventory.vars(self) end |