tfa 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47c5413e1e1629847f5b3a930e26650a0318993b
4
- data.tar.gz: dfde14c6b7e4bb9011819319dc0990f2d4798647
3
+ metadata.gz: 24e830bb0060ce472fd83b1a72cedca8b21e68bb
4
+ data.tar.gz: dfffb8e6ca0d88e6bffea3fadc7adae6af6b9f38
5
5
  SHA512:
6
- metadata.gz: fc9085378b59b702147c9e8d97e890460c0060563b3ac60a962c5db0f252ac9da3d5359b278a4aabcdd16bcc932384821f036620611affc86a2ea0a97b052443
7
- data.tar.gz: a7231f4b3f853a36eab71af8e35189324e42062218a1e36baa540bffbfa86f73e09e8ec4bda19139df65873b51eabf2aca46eb3c4ba018368cce9c3c1e5e78fe
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
- AddCommand.new(storage).run([name, secret])
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
- ShowCommand.new(storage).run([name].compact)
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 all_secrets
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
@@ -4,9 +4,9 @@ module TFA
4
4
  @storage = storage
5
5
  end
6
6
 
7
- def run(arguments)
8
- return password_for(secret_for(arguments.first)) if valid?(arguments)
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
- secrets = @storage.all_secrets
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
@@ -1,3 +1,3 @@
1
1
  module TFA
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/tfa.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  require "pstore"
2
2
  require "rotp"
3
3
  require "tfa/version"
4
- require "tfa/add_command"
5
- require "tfa/show_command"
6
4
  require "tfa/totp_command"
7
- require "tfa/usage_command"
8
- require "tfa/cli"
9
5
  require "tfa/storage"
6
+ require "tfa/cli"
@@ -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(["development"])).to eql(code_for(secret))
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([])).to eql([
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.8
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
@@ -1,13 +0,0 @@
1
- module TFA
2
- class AddCommand
3
- def initialize(storage)
4
- @storage = storage
5
- end
6
-
7
- def run(arguments)
8
- name = arguments.first
9
- @storage.save(arguments.first, arguments.last)
10
- "Added #{name}"
11
- end
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- module TFA
2
- class ShowCommand
3
- def initialize(storage)
4
- @storage = storage
5
- end
6
-
7
- def run(arguments)
8
- return @storage.secret_for(arguments.last) if arguments.any?
9
- @storage.all_secrets
10
- end
11
- end
12
- end
@@ -1,16 +0,0 @@
1
- module TFA
2
- class UsageCommand
3
- def initialize(storage)
4
- @storage = storage
5
- end
6
-
7
- def run(arguments)
8
- <<-MESSAGE
9
- Try:
10
- - tfa add develoment <secret>
11
- - tfa show development
12
- - tfa totp development
13
- MESSAGE
14
- end
15
- end
16
- end
@@ -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