tfa 0.0.6 → 0.0.7

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: 31998f68b2ffd5161cc0349d47aa078b5d09d356
4
- data.tar.gz: 08f0e8fcf9955ffe4b07073766d0108a2fcc2919
3
+ metadata.gz: c3231a5fbb89add5da947d85c14c6281c62f77ca
4
+ data.tar.gz: 4e289687adc78c62657595f42b6d0d7178466ca4
5
5
  SHA512:
6
- metadata.gz: da32ced0dce6eb07611e48bc019c0fac3f729051cac8cb838d3437c6045cf0b46bab2ecb096957fcd0daa74e939d38049396e3f3575767cc2f34ca0ae93a81f1
7
- data.tar.gz: 0d5b37925f8a2b3c67c4bb533d93d34468e85496e9c86b393e174b86ee27fd1fbef3dbf87c156bd39ee3ee40c435f13d3a65ec7b3a0ca03df651c15050f9db75
6
+ metadata.gz: 225f5599d4f2eb90c9c049392bfdea258cbfa66b7075941121caf8eb3e424e56b08f9000df3280a10474c4d49b42acd957bff92e0dccc1252274f9e38e80b9b5
7
+ data.tar.gz: fae0bfe272ad2c6eb01fadefacbc5fc59f5354884d0dc05b362b45e76d998eea26a272db32f77df9f0fb352d375c5a8de4769b51b0689f108f07728f92372e30
data/bin/tfa CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'tfa'
3
3
 
4
- puts TFA::Console.new.run(ARGV)
4
+ puts TFA::CLI.start(ARGV)
data/lib/tfa/cli.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "thor"
2
+
3
+ module TFA
4
+ class CLI < Thor
5
+ package_name "TFA"
6
+ class_option :filename
7
+
8
+ desc "add NAME SECRET", "add a new secret to the database"
9
+ def add(name, secret)
10
+ AddCommand.new(storage).run([name, secret])
11
+ end
12
+
13
+ desc "show NAME", "shows the secret for the given key"
14
+ def show(name)
15
+ ShowCommand.new(storage).run([name])
16
+ end
17
+
18
+ desc "totp NAME", "generate a Time based One Time Password"
19
+ def totp(name)
20
+ TotpCommand.new(storage).run([name])
21
+ end
22
+
23
+ private
24
+
25
+ def storage
26
+ @storage ||= Storage.new(filename: options[:filename] || 'tfa')
27
+ end
28
+ end
29
+ end
data/lib/tfa/storage.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module TFA
2
2
  class Storage
3
- def initialize(filename)
3
+ def initialize(filename:)
4
4
  @storage = PStore.new(File.join(Dir.home, ".#{filename}.pstore"))
5
5
  end
6
6
 
data/lib/tfa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TFA
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/tfa.rb CHANGED
@@ -5,5 +5,5 @@ require "tfa/add_command"
5
5
  require "tfa/show_command"
6
6
  require "tfa/totp_command"
7
7
  require "tfa/usage_command"
8
- require "tfa/console"
8
+ require "tfa/cli"
9
9
  require "tfa/storage"
@@ -1,26 +1,20 @@
1
1
  module TFA
2
- describe Console do
3
- subject { Console.new('testing') }
2
+ describe CLI do
3
+ subject { CLI.new }
4
4
  let(:secret) { ::ROTP::Base32.random_base32 }
5
5
 
6
6
  describe "#run" do
7
7
  context "when adding a key" do
8
8
  it "saves a new secret" do
9
- subject.run(["add", "development", secret])
10
- expect(subject.run(["show", "development"])).to eql(secret)
9
+ subject.add("development", secret)
10
+ expect(subject.show("development")).to eql(secret)
11
11
  end
12
12
  end
13
13
 
14
14
  context "when getting a one time password" do
15
15
  it "creates a totp for a certain key" do
16
- subject.run(["add", "development", secret])
17
- expect(subject.run(["totp", "development"])).to_not be_nil
18
- end
19
- end
20
-
21
- context "when running an unknown command" do
22
- it "returns the usage" do
23
- expect(subject.run([])).to_not be_nil
16
+ subject.add("development", secret)
17
+ expect(subject.totp("development")).to_not be_nil
24
18
  end
25
19
  end
26
20
  end
@@ -1,7 +1,7 @@
1
1
  module TFA
2
2
  describe ShowCommand do
3
3
  subject { ShowCommand.new(storage) }
4
- let(:storage) { Storage.new(SecureRandom.uuid) }
4
+ let(:storage) { Storage.new(filename: SecureRandom.uuid) }
5
5
 
6
6
  describe "#run" do
7
7
  context "when looking up the secret for a specific key" do
@@ -1,8 +1,7 @@
1
1
  module TFA
2
2
  describe TotpCommand do
3
3
  subject { TotpCommand.new(storage) }
4
- let(:storage) { Storage.new(Tempfile.new('test').path) }
5
- let(:storage) { Storage.new(SecureRandom.uuid) }
4
+ let(:storage) { Storage.new(filename: SecureRandom.uuid) }
6
5
 
7
6
  def code_for(secret)
8
7
  ::ROTP::TOTP.new(secret).now
data/tfa.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "rotp"
22
+ spec.add_dependency "thor"
22
23
  spec.add_development_dependency "bundler", "~> 1.6"
23
24
  spec.add_development_dependency "rake"
24
25
  spec.add_development_dependency "rspec"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-03 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rotp
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -84,7 +98,7 @@ files:
84
98
  - bin/tfa
85
99
  - lib/tfa.rb
86
100
  - lib/tfa/add_command.rb
87
- - lib/tfa/console.rb
101
+ - lib/tfa/cli.rb
88
102
  - lib/tfa/show_command.rb
89
103
  - lib/tfa/storage.rb
90
104
  - lib/tfa/totp_command.rb
data/lib/tfa/console.rb DELETED
@@ -1,26 +0,0 @@
1
- module TFA
2
- class Console
3
- def initialize(filename = "tfa")
4
- @storage = Storage.new(filename)
5
- end
6
-
7
- def run(arguments)
8
- command_name = arguments.first
9
- command_for(command_name).run(arguments - [command_name])
10
- end
11
-
12
- private
13
-
14
- def command_for(command_name)
15
- registry[command_name].call
16
- end
17
-
18
- def registry
19
- Hash.new { |x, y| lambda { UsageCommand.new(@storage) } }.tap do |commands|
20
- commands['add'] = lambda { AddCommand.new(@storage) }
21
- commands['show'] = lambda { ShowCommand.new(@storage) }
22
- commands['totp'] = lambda { TotpCommand.new(@storage) }
23
- end
24
- end
25
- end
26
- end