Class: OpsWalrus::Secret

Inherits:
Object
  • Object
show all
Defined in:
lib/opswalrus/hosts_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, secret_value, id_references) ⇒ Secret

Returns a new instance of Secret.



364
365
366
367
368
# File 'lib/opswalrus/hosts_file.rb', line 364

def initialize(name, secret_value, id_references)
  @name = name
  @value = secret_value
  @ids = id_references
end

Instance Method Details

#decrypt(cipher) ⇒ Object



402
403
404
405
# File 'lib/opswalrus/hosts_file.rb', line 402

def decrypt(cipher)
  @value = cipher.decrypt(@value) if cipher.encrypted?(@value)
  @value
end

#encode_with(coder) ⇒ Object



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/opswalrus/hosts_file.rb', line 375

def encode_with(coder)
  coder.tag = nil

  # per https://rubydoc.info/stdlib/psych/3.0.0/Psych/Coder#scalar-instance_method
  # coder.represent_scalar(nil, @public_key)

  # coder.scalar = @public_key
  single_line_ids = @ids.join(", ")
  if single_line_ids.size <= 80
    coder['ids'] = single_line_ids
  else
    coder['ids'] = @ids
  end
  coder['value'] = @value
end

#encrypt(cipher) ⇒ Object



397
398
399
400
# File 'lib/opswalrus/hosts_file.rb', line 397

def encrypt(cipher)
  @value = cipher.encrypt(@value, @ids) unless cipher.encrypted?(@value)
  @value
end

#init_with(coder) ⇒ Object

deserialise from yaml



392
393
394
395
# File 'lib/opswalrus/hosts_file.rb', line 392

def init_with(coder)
  @public_key = coder.scalar
  # @public_key = coder['public_key']
end

#to_sObject



407
408
409
# File 'lib/opswalrus/hosts_file.rb', line 407

def to_s
  @value
end