commit dbd5957af3eb6dcff9be1003219668f7d4f5870d
parent 54f9b22e47e4bc28a34896635f08e794b8f9154c
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 13 Aug 2021 16:18:02 +0100
remove secrets
Diffstat:
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
@@ -182,7 +182,6 @@ security requirements, look elsewhere.
## TO DO
-* remove secrets
* copy to clipboard
* support re-encrypting a subtree when recipients change
* warn or fail if iffy store permissions?
diff --git a/features/moss.feature b/features/moss.feature
@@ -41,6 +41,12 @@ Feature: command-line password management
And I see the string "home/yahoomail"
And I see the string "home/ebay"
+ Scenario: I can delete a secret
+ Given I am using a temporary password store
+ And there is a secret for "home/ebay"
+ When I delete the secret for "home/ebay"
+ Then "home/ebay.age" does not exist
+
Scenario: I can search for a secret
Given I am using the example password store
When I search for "mail"
diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb
@@ -44,11 +44,24 @@ Given("I am using the example password store") do
ENV["MOSS_HOME"] = "fixtures"
end
+Given('there is a secret for {string}') do |name|
+ shell "#{MOSS} generate #{name} 20"
+end
+
When("I generate a secret for {string} with length {int}") do |name, length|
@stored_secret_name = name
@i_see = shell "#{MOSS} generate #{name} #{length}"
end
+When("I delete the secret for {string}") do |name|
+ @i_see = shell "#{MOSS} rm #{name}"
+end
+
+Then('{string} does not exist') do |path|
+ expect(store_path(path)).not_to exist
+end
+
+
When("I store a secret for {string} with content {string}") do |name, content|
@stored_secret_name = name
shell "echo -n #{content} | #{MOSS} insert #{name.inspect}"
diff --git a/moss.rb b/moss.rb
@@ -121,6 +121,12 @@ class Moss
"-d", pathname])
end
+ def remove_secret(name)
+ pathname = store.join("#{name}.age")
+ File.exist?(pathname) or raise MossError, "Can't remove non-existent file #{pathname}"
+ pathname.delete
+ end
+
def secrets
Dir[store.join("**/*.age")].map { |n|
Pathname.new(n).relative_path_from(store).sub_ext("").to_s
@@ -331,6 +337,10 @@ def cli
MOSS.create(Pathname.new(keyfile))
end
+ command :rm, "remove a secret" do |secret:|
+ MOSS.remove_secret(secret)
+ end
+
command :git, "perform git operation in store" do |* git_command|
MOSS.git_operation(git_command)
end