Class: OpsWalrus::AgeEncryption

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

Constant Summary collapse

AGE_ENCRYPTED_FILE_HEADER =
'-----BEGIN AGE ENCRYPTED FILE-----'

Class Method Summary collapse

Class Method Details

.decrypt(value, private_key_file_paths) ⇒ Object



281
282
283
284
285
286
287
288
# File 'lib/opswalrus/hosts_file.rb', line 281

def self.decrypt(value, private_key_file_paths)
  raise "Unable to decrypt the requested value because there is no age encryption identity (private key) specified" if private_key_file_paths.empty?
  identity_file_args = private_key_file_paths.map {|private_key_file_path| "-i #{private_key_file_path}" }
  cmd = "age -d  #{identity_file_args.join(' ')}"
  stdout, stderr, status = Open3.capture3(cmd, stdin_data: value)
  raise "Failed to run age encryption: `#{cmd}`" unless status.success?
  stdout
end

.encrypt(value, public_keys) ⇒ Object



273
274
275
276
277
278
279
# File 'lib/opswalrus/hosts_file.rb', line 273

def self.encrypt(value, public_keys)
  recipient_args = public_keys.map {|public_key| "-r #{public_key}" }
  cmd = "age -e -a #{recipient_args.join(' ')}"
  stdout, stderr, status = Open3.capture3(cmd, stdin_data: value)
  raise "Failed to run age encryption: `#{cmd}`" unless status.success?
  stdout
end