Sha256: d69b3a95583ff4b248c84109b813c7e530f773a5445db9cc0d668d4abf58e0c2
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
require "thor" module TFA class CLI < Thor package_name "TFA" class_option :filename desc "add NAME SECRET", "add a new secret to the database" def add(name, secret) secret = clean(secret) storage.save(name, secret) "Added #{name}" end desc "destroy NAME", "remove the secret associated with the name" def destroy(name) storage.delete(name) end desc "show NAME", "shows the secret for the given key" def show(name = nil) name ? storage.secret_for(name) : storage.all end desc "totp NAME", "generate a Time based One Time Password using the secret associated with the given NAME." def totp(name = nil) TotpCommand.new(storage).run(name) end desc "now SECRET", "generate a Time based One Time Password for the given secret" def now(secret) TotpCommand.new(storage).run('', secret) end private def storage @storage ||= Storage.new(filename: options[:filename] || 'tfa') end def clean(secret) if secret.include?("=") /secret=([^&]*)/.match(secret).captures.first else secret end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tfa-0.0.14 | lib/tfa/cli.rb |
tfa-0.0.13 | lib/tfa/cli.rb |