Class: Itamae::Secrets::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/itamae/secrets/cli.rb

Instance Method Summary collapse

Instance Method Details

#get(name) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/itamae/secrets/cli.rb', line 50

def get(name)
  value = store[name]
  if value
    puts value
  else
    exit 1
  end
end

#newkey(name = 'default') ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/itamae/secrets/cli.rb', line 18

def newkey(name='default')
  if keychain.exist?(name)
    raise ArgumentError, "key #{name} already exists"
  end

  key = case options[:method] || config['generate_method']
  when 'aes-random'
    AesKey.generate_random(name)
  when 'aes-passphrase'
    passphrase = ask_noecho('Passphrase:', $stdin.tty?)
    AesKey.generate_pkcs5(name, passphrase)
  else
    raise ArgumentError, "Unknown method: #{options[:method] || config['generate_method']}"
  end

  keychain.save(key)
end

#set(name, value = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/itamae/secrets/cli.rb', line 39

def set(name, value = nil)
  value ||= if options[:noecho]
              ask_noecho("#{name}:", false)
            else
              $stdin.read.chomp
            end

  store.store(name, value, options[:key])
end