From eef9f2a9669a2c2b95fbf9cafd2d63f98c84dd0a Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 25 Jul 2014 15:50:35 -0600 Subject: dump all secrets. --- lib/tfa/show_command.rb | 14 +++++++++++--- spec/lib/show_command_spec.rb | 28 ++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/tfa/show_command.rb b/lib/tfa/show_command.rb index 0bfcd67..fe9c908 100644 --- a/lib/tfa/show_command.rb +++ b/lib/tfa/show_command.rb @@ -5,9 +5,17 @@ module TFA end def run(arguments) - name = arguments.last - @storage.transaction(true) do - @storage[name] + if arguments.any? + name = arguments.last + @storage.transaction(true) do + @storage[name] + end + else + @storage.transaction(true) do + @storage.roots.map do |key| + @storage[key] + end + end end end end diff --git a/spec/lib/show_command_spec.rb b/spec/lib/show_command_spec.rb index 7cfcb31..a647451 100644 --- a/spec/lib/show_command_spec.rb +++ b/spec/lib/show_command_spec.rb @@ -3,14 +3,30 @@ module TFA subject { ShowCommand.new(storage) } let(:storage) { PStore.new(Tempfile.new('blah').path) } - it "retrieves the secret associated with the key given" do - secret = SecureRandom.uuid - storage.transaction do - storage['production'] = secret + describe "#run" do + context "when looking up the secret for a specific key" do + it "retrieves the secret associated with the key given" do + secret = SecureRandom.uuid + storage.transaction do + storage['production'] = secret + end + + result = subject.run(['production']) + expect(result).to eql(secret) + end end - result = subject.run(['production']) - expect(result).to eql(secret) + context "when a specific name is not given" do + it "returns all the secrets" do + storage.transaction do + storage['development'] = "1" + storage['staging'] = "2" + storage['production'] = "3" + end + + expect(subject.run([])).to eql(["1", "2", "3"]) + end + end end end end -- cgit v1.2.3