Commit b20eb1b

mo khan <mo@mokhan.ca>
2016-11-18 17:15:33
Add a destroy command to remove a secret.
1 parent d39839c
lib/tfa/cli.rb
@@ -12,6 +12,11 @@ module TFA
       "Added #{name}"
     end
 
+    desc "destroy NAME", "remove the secret associated with the name"
+    def destroy(name)
+      storage.delete(name)
+    end
+
     desc "show NAME", "shows the secret for the given key"
     def show(name = nil)
       name ? storage.secret_for(name) : storage.all
lib/tfa/storage.rb
@@ -30,6 +30,12 @@ module TFA
       end
     end
 
+    def delete(key)
+      @storage.transaction do
+        @storage.delete(key)
+      end
+    end
+
     private
 
     def open_readonly
lib/tfa/totp_command.rb
@@ -13,7 +13,7 @@ module TFA
 
     def password_for(secret)
       ::ROTP::TOTP.new(secret).now
-    rescue ROTP::Base32::Base32Error => error
+    rescue ROTP::Base32::Base32Error
       "INVALID SECRET"
     end
 
spec/lib/cli_spec.rb
@@ -66,5 +66,16 @@ module TFA
         end
       end
     end
+
+    describe "#destroy" do
+      let(:name) { "development" }
+
+      it 'removes the secret with the given name' do
+        subject.add(name, dev_secret)
+        subject.destroy(name)
+
+        expect(subject.show(name)).to be_nil
+      end
+    end
   end
 end