summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mokhan@users.noreply.github.com>2017-01-11 10:21:01 -0700
committerGitHub <noreply@github.com>2017-01-11 10:21:01 -0700
commitd0595e82e1b6cf0ba8b5749020ec2449a659ef6c (patch)
tree3b0887f951ab0834ce7ac42ce81dbee24f3bf663
parent172e3dfb7ff0ebec111a8349daddd50ad86648aa (diff)
parentc48a3dbd5c853784739e80d8fec348ab40963c27 (diff)
Merge pull request #7 from mokhan/tfa-nowv0.0.13
add tfa now SECRET command.
-rw-r--r--lib/tfa/cli.rb7
-rw-r--r--lib/tfa/totp_command.rb3
-rw-r--r--lib/tfa/version.rb2
-rw-r--r--spec/lib/cli_spec.rb6
4 files changed, 14 insertions, 4 deletions
diff --git a/lib/tfa/cli.rb b/lib/tfa/cli.rb
index 03feeeb..28b3065 100644
--- a/lib/tfa/cli.rb
+++ b/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
diff --git a/lib/tfa/totp_command.rb b/lib/tfa/totp_command.rb
index 14bc064..57f0cc4 100644
--- a/lib/tfa/totp_command.rb
+++ b/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
diff --git a/lib/tfa/version.rb b/lib/tfa/version.rb
index ffd9203..40846e1 100644
--- a/lib/tfa/version.rb
+++ b/lib/tfa/version.rb
@@ -1,3 +1,3 @@
module TFA
- VERSION = "0.0.12".freeze
+ VERSION = "0.0.13".freeze
end
diff --git a/spec/lib/cli_spec.rb b/spec/lib/cli_spec.rb
index f1a68d4..3d5fcd6 100644
--- a/spec/lib/cli_spec.rb
+++ b/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