moss

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4a864673cf8854c16123f4dbfe30438383164d37
parent 92b89648b2a2ddc9130d4715bf583f48390fd2e1
Author: Daniel Barlow <dan@telent.net>
Date:   Thu, 12 Aug 2021 00:00:24 +0100

delete trailing whitespace

Diffstat:
Mfeatures/step_definitions/steps.rb | 4++--
Mmoss.rb | 29++++++++++++++++-------------
2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb @@ -29,7 +29,7 @@ def recipient_for_identity(identity_file) end Given("I set MOSS_HOME to a unique temporary pathname") do - ENV["MOSS_HOME"] = Dir.mktmpdir + ENV["MOSS_HOME"] = Dir.mktmpdir end Given("I am using a temporary password store") do @@ -160,7 +160,7 @@ end Then("the instance store exists") do expect(Pathname.new(ENV['MOSS_HOME']).join("store")).to be_directory end - + Then("the instance identity is {string}") do |keyfile| expect(store_path("../identity").read).to eq File.read("fixtures/keys/#{keyfile}") end diff --git a/moss.rb b/moss.rb @@ -34,7 +34,7 @@ class Moss f.read } end - + def pubkey_for_identity(filename) pubkey = if encrypted?(filename) @@ -43,7 +43,7 @@ class Moss f.write(plaintext) f.close_write f.read - end + end else capture_output([AGE_KEYGEN, "-y", filename.to_s]) end @@ -74,7 +74,7 @@ class Moss def identity_file root.join("identity") end - + def git_managed? store.join(".git").exist? end @@ -138,8 +138,11 @@ class Moss end def git_operation(parameters) - raise "not a git repo" unless git_managed? - Kernel.system(GIT, *parameters, {chdir: store}) + if (git_managed? || parameters.first == 'init') + Kernel.system(GIT, *parameters, {chdir: store}) + else + raise "not a git repo" + end end end @@ -163,7 +166,7 @@ def random_alnum(length) bytes.pack("C*") end - + class CLI @@commands = {} @@ -214,22 +217,22 @@ class CLI MOSS.write_secret(filename, secret) end aka :add, :insert - + command :show, "display a secret" do |file| STDOUT.write(MOSS.read_secret(file)) - end + end aka :show, :cat - + command :search, "search secrets with names matching term" do |*term| files = MOSS.secrets.filter {|f| f.match(Regexp.new(term.join(" "))) } files.each do |n| - puts n + puts n end end aka :search, :list - + command :edit, "edit a secret" do |file| content = MOSS.read_secret(file) Tempfile.create(file.gsub(/[\W]/,"")) do |f| @@ -244,11 +247,11 @@ class CLI end end end - + command :config, "show configuration" do puts JSON.generate(MOSS.config) end - + command :init, "create new moss repository" do |keyfile| MOSS.create(Pathname.new(keyfile)) end