commit 9e4aa01b9d642965f57437df4a5e6f4d3e731291
parent 09bc12d485c7c3b9f67416bb2ae217d8a1aa8a43
Author: Daniel Barlow <dan@telent.net>
Date: Mon, 9 Aug 2021 17:39:04 +0100
default store location under XDG_DATA_HOME
Diffstat:
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/features/moss.feature b/features/moss.feature
@@ -70,7 +70,10 @@ Feature: command-line password management
Then the change to "home/ebay.age" is committed to version control
- Scenario: It pushes changes to a git remote
+ Scenario: Sensible path to the store
+ Given I do not specify a store
+ Then the store directory is under XDG_DATA_HOME
+
diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb
@@ -132,3 +132,15 @@ Then("the change to {string} is committed to version control") do |name|
log = shell "cd #{ENV["MOSS_STORE"]} && git log #{name}"
expect(log).to match /new secret/
end
+
+Given("I do not specify a store") do
+ ENV.delete('MOSS_STORE')
+end
+
+Then("the store directory is under XDG_DATA_HOME") do
+ ENV["XDG_DATA_HOME"] = "/tmp/#{6.times.map { rand(36).to_s(36) }.join}"
+ result = JSON.load(shell "#{MOSS} config")
+ store = result["store"]
+ expect(store).to start_with(ENV["XDG_DATA_HOME"])
+end
+
diff --git a/moss.rb b/moss.rb
@@ -1,10 +1,17 @@
#!/usr/bin/env ruby
require 'pathname'
require 'tempfile'
+require 'json'
+def xdg_data_home
+ ENV.fetch("XDG_DATA_HOME", "#{ENV['HOME']}/.local/share")
+end
+
+STORE = Pathname.new(ENV['MOSS_STORE'] || "#{xdg_data_home}/moss/store")
+IDENTITY_FILE = ENV.fetch('MOSS_IDENTITY_FILE', "#{xdg_data_home}/moss/identity")
-STORE = Pathname.new(ENV['MOSS_STORE'] || "/tmp/store").realpath
-IDENTITY_FILE = ENV['MOSS_IDENTITY_FILE']
+File.exist?(IDENTITY_FILE) or
+ raise "missing identity file (private key) at #{IDENTITY_FILE}, use age-keygen to create"
def git_managed?
STORE.join(".git").exist?
@@ -100,6 +107,13 @@ when 'search','list'
files.each do |n|
puts n
end
+when 'config'
+ config = {
+ store: STORE.to_s,
+ identity_file: IDENTITY_FILE.to_s,
+ git: git_managed?
+ }
+ puts JSON.generate(config)
else
raise "command #{action} unrecognized"
end