Commit c48a3db
Changed files (4)
lib
spec
lib
lib/tfa/cli.rb
@@ -22,11 +22,16 @@ module TFA
name ? storage.secret_for(name) : storage.all
end
- desc "totp NAME", "generate a Time based One Time Password"
+ 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
lib/tfa/totp_command.rb
@@ -4,8 +4,7 @@ module TFA
@storage = storage
end
- def run(name)
- secret = secret_for(name)
+ def run(name, secret = secret_for(name))
secret ? password_for(secret) : all_passwords
end
lib/tfa/version.rb
@@ -1,3 +1,3 @@
module TFA
- VERSION = "0.0.12".freeze
+ VERSION = "0.0.13".freeze
end
spec/lib/cli_spec.rb
@@ -77,5 +77,11 @@ module TFA
expect(subject.show(name)).to be_nil
end
end
+
+ describe "#now" do
+ it "returns a time based one time password for the given secret" do
+ expect(subject.now(dev_secret)).to eql(code_for(dev_secret))
+ end
+ end
end
end