lib/tfa/totp_command.rb in tfa-0.0.3 vs lib/tfa/totp_command.rb in tfa-0.0.4
- old
+ new
@@ -3,18 +3,28 @@
def initialize(storage)
@storage = storage
end
def run(arguments)
- name = arguments.first
- ::ROTP::TOTP.new(secret_for(name)).now
+ return password_for(secret_for(arguments.first)) if arguments.any?
+ all_passwords
end
private
- def secret_for(name)
- @storage.transaction(true) do
- @storage[name]
+ def password_for(secret)
+ ::ROTP::TOTP.new(secret).now
+ end
+
+ def all_passwords
+ secrets = @storage.all_secrets
+ secrets.each do |hash|
+ hash[hash.keys.first] = password_for(hash[hash.keys.first])
end
+ secrets
+ end
+
+ def secret_for(key)
+ @storage.secret_for(key)
end
end
end