Class: OpsWalrus::Secret
- Inherits:
-
Object
- Object
- OpsWalrus::Secret
- Defined in:
- lib/opswalrus/hosts_file.rb
Instance Method Summary collapse
- #decrypt(cipher) ⇒ Object
-
#encode_with(coder) ⇒ Object
#init_with and #encode_with are demonstrated here: - djellemah.com/blog/2014/07/23/yaml-deserialisation/ - stackoverflow.com/questions/10629209/how-can-i-control-which-fields-to-serialize-with-yaml - github.com/protocolbuffers/protobuf/issues/4391 serialise to yaml.
- #encrypt(cipher) ⇒ Object
-
#init_with(coder) ⇒ Object
deserialise from yaml.
-
#initialize(name, secret_value, id_references) ⇒ Secret
constructor
A new instance of Secret.
- #to_s ⇒ Object
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
#init_with and #encode_with are demonstrated here:
serialise to yaml
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_s ⇒ Object
407 408 409 |
# File 'lib/opswalrus/hosts_file.rb', line 407 def to_s @value end |