Module: ECSUtil::Vault

Included in:
Command
Defined in:
lib/ecsutil/vault.rb

Instance Method Summary collapse

Instance Method Details

#vault_edit(path, password_path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



6
7
8
9
10
11
# 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) ⇒ Object



13
14
15
16
17
18
19
# 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