tfa 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tfa/cli.rb +4 -3
- data/lib/tfa/storage.rb +9 -1
- data/lib/tfa/totp_command.rb +4 -10
- data/lib/tfa/version.rb +1 -1
- data/lib/tfa.rb +1 -4
- data/spec/lib/totp_command_spec.rb +3 -3
- metadata +1 -6
- data/lib/tfa/add_command.rb +0 -13
- data/lib/tfa/show_command.rb +0 -12
- data/lib/tfa/usage_command.rb +0 -16
- data/spec/lib/show_command_spec.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24e830bb0060ce472fd83b1a72cedca8b21e68bb
|
4
|
+
data.tar.gz: dfffb8e6ca0d88e6bffea3fadc7adae6af6b9f38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c3877dab4a1f13f06664aede58b0c835547c4285d0bf147c099eb12f87d047a2dcb72593ed4ac136ed725104df14e35d7c73a193b6d63e0a901fa240b79acc3
|
7
|
+
data.tar.gz: bf4ba1c1523aca58a5b7f772e9a4d4c02d5ebb9b86eba31e419e62c6b6608671bb8e213ea6e8501adfe211a3655f47565853ccaa33345e95043768616549df88
|
data/lib/tfa/cli.rb
CHANGED
@@ -7,16 +7,17 @@ module TFA
|
|
7
7
|
|
8
8
|
desc "add NAME SECRET", "add a new secret to the database"
|
9
9
|
def add(name, secret)
|
10
|
-
|
10
|
+
storage.save(name, secret)
|
11
|
+
"Added #{name}"
|
11
12
|
end
|
12
13
|
|
13
14
|
desc "show NAME", "shows the secret for the given key"
|
14
15
|
def show(name = nil)
|
15
|
-
|
16
|
+
name ? storage.secret_for(name) : storage.all
|
16
17
|
end
|
17
18
|
|
18
19
|
desc "totp NAME", "generate a Time based One Time Password"
|
19
|
-
def totp(name)
|
20
|
+
def totp(name = nil)
|
20
21
|
TotpCommand.new(storage).run([name])
|
21
22
|
end
|
22
23
|
|
data/lib/tfa/storage.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
module TFA
|
2
2
|
class Storage
|
3
|
+
include Enumerable
|
4
|
+
|
3
5
|
def initialize(filename:)
|
4
6
|
@storage = PStore.new(File.join(Dir.home, ".#{filename}.pstore"))
|
5
7
|
end
|
6
8
|
|
7
|
-
def
|
9
|
+
def each
|
10
|
+
all.each do |each|
|
11
|
+
yield each
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def all
|
8
16
|
open_readonly do |storage|
|
9
17
|
storage.roots.map { |key| { key => storage[key] } }
|
10
18
|
end
|
data/lib/tfa/totp_command.rb
CHANGED
@@ -4,9 +4,9 @@ module TFA
|
|
4
4
|
@storage = storage
|
5
5
|
end
|
6
6
|
|
7
|
-
def run(
|
8
|
-
|
9
|
-
all_passwords
|
7
|
+
def run(name)
|
8
|
+
secret = secret_for(name)
|
9
|
+
secret ? password_for(secret) : all_passwords
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
@@ -16,19 +16,13 @@ module TFA
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def all_passwords
|
19
|
-
|
20
|
-
secrets.each do |hash|
|
19
|
+
@storage.each do |hash|
|
21
20
|
hash[hash.keys.first] = password_for(hash[hash.keys.first])
|
22
21
|
end
|
23
|
-
secrets
|
24
22
|
end
|
25
23
|
|
26
24
|
def secret_for(key)
|
27
25
|
@storage.secret_for(key)
|
28
26
|
end
|
29
|
-
|
30
|
-
def valid?(arguments)
|
31
|
-
arguments.any? && secret_for(arguments.first)
|
32
|
-
end
|
33
27
|
end
|
34
28
|
end
|
data/lib/tfa/version.rb
CHANGED
data/lib/tfa.rb
CHANGED
@@ -13,7 +13,7 @@ module TFA
|
|
13
13
|
|
14
14
|
it "returns a time based one time password for the authentication secret given" do
|
15
15
|
storage.save('development', secret)
|
16
|
-
expect(subject.run(
|
16
|
+
expect(subject.run("development")).to eql(code_for(secret))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -24,8 +24,8 @@ module TFA
|
|
24
24
|
it "returns the one time password for all keys" do
|
25
25
|
storage.save('development', development_secret)
|
26
26
|
storage.save('staging', staging_secret)
|
27
|
-
expect(subject.run(
|
28
|
-
{ 'development' => code_for(development_secret) },
|
27
|
+
expect(subject.run(nil)).to eql([
|
28
|
+
{ 'development' => code_for(development_secret) },
|
29
29
|
{ 'staging' => code_for(staging_secret) }
|
30
30
|
])
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tfa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo khan
|
@@ -97,15 +97,11 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- bin/tfa
|
99
99
|
- lib/tfa.rb
|
100
|
-
- lib/tfa/add_command.rb
|
101
100
|
- lib/tfa/cli.rb
|
102
|
-
- lib/tfa/show_command.rb
|
103
101
|
- lib/tfa/storage.rb
|
104
102
|
- lib/tfa/totp_command.rb
|
105
|
-
- lib/tfa/usage_command.rb
|
106
103
|
- lib/tfa/version.rb
|
107
104
|
- spec/lib/console_spec.rb
|
108
|
-
- spec/lib/show_command_spec.rb
|
109
105
|
- spec/lib/totp_command_spec.rb
|
110
106
|
- spec/spec_helper.rb
|
111
107
|
- tfa.gemspec
|
@@ -135,6 +131,5 @@ specification_version: 4
|
|
135
131
|
summary: A CLI to manage your one time passwords.
|
136
132
|
test_files:
|
137
133
|
- spec/lib/console_spec.rb
|
138
|
-
- spec/lib/show_command_spec.rb
|
139
134
|
- spec/lib/totp_command_spec.rb
|
140
135
|
- spec/spec_helper.rb
|
data/lib/tfa/add_command.rb
DELETED
data/lib/tfa/show_command.rb
DELETED
data/lib/tfa/usage_command.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module TFA
|
2
|
-
describe ShowCommand do
|
3
|
-
subject { ShowCommand.new(storage) }
|
4
|
-
let(:storage) { Storage.new(filename: SecureRandom.uuid) }
|
5
|
-
|
6
|
-
describe "#run" do
|
7
|
-
context "when looking up the secret for a specific key" do
|
8
|
-
it "retrieves the secret associated with the key given" do
|
9
|
-
secret = SecureRandom.uuid
|
10
|
-
storage.save('production', secret)
|
11
|
-
result = subject.run(['production'])
|
12
|
-
expect(result).to eql(secret)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when a specific name is not given" do
|
17
|
-
it "returns all the secrets" do
|
18
|
-
storage.save('development', "1")
|
19
|
-
storage.save('staging', "2")
|
20
|
-
storage.save('production', "3")
|
21
|
-
expect(subject.run([])).to eql([{"development" => "1"}, { "staging" => "2" }, { "production" => "3" }])
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|