module ECSUtil::Vault

Public Instance Methods

vault_edit(path, password_path) click to toggle source
# File lib/ecsutil/vault.rb, line 21
def vault_edit(path, password_path)
  temp = Tempfile.new
  temp.write(vault_read(path, password_path))
  temp.flush

  editor_path = `which $EDITOR`.strip
  if editor_path.empty?
    fail "EDITOR is not set!"
  end

  system "#{editor_path} #{temp.path}"
  unless $?.success?
    fail "Unable to save temp file"
  end

  vault_write(path, password_path, File.read(temp.path))

  temp.close
  temp.unlink
end
vault_read(path, password_path) click to toggle source
# File lib/ecsutil/vault.rb, line 6
def vault_read(path, password_path)
  Ansible::Vault.read(
    path: path,
    password: File.read(password_path).strip
  )
end
vault_write(path, password_path, data) click to toggle source
# File lib/ecsutil/vault.rb, line 13
def vault_write(path, password_path, data)
  Ansible::Vault.write(
    path: path,
    password: File.read(password_path).strip,
    plaintext: data
  )
end