From fd133309d5bcb1912597e0c3f0bc8bbcb6d0590e Mon Sep 17 00:00:00 2001 From: Sylvain Maucourt Date: Fri, 18 Feb 2022 14:43:24 +0100 Subject: [PATCH] add insert/generate/init/rm password store commands compatibilities --- leeloo/lib/leeloo/command.rb | 41 +++++++++++++++++++++++++-------- leeloo/lib/leeloo/controller.rb | 4 ++-- leeloo/lib/leeloo/keystore.rb | 1 + leeloo/lib/leeloo/version.rb | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/leeloo/lib/leeloo/command.rb b/leeloo/lib/leeloo/command.rb index 5ea29f8..bca1db1 100644 --- a/leeloo/lib/leeloo/command.rb +++ b/leeloo/lib/leeloo/command.rb @@ -43,6 +43,11 @@ def run end end + command :init do |c| + c.syntax = 'leeloo init' + c.description = "Just to be compatible with passwordstore.org" + end + command :list do |c| c.syntax = 'leeloo list [options]' c.description = "Display secrets list of stored on a keystore" @@ -79,7 +84,7 @@ def run end end - command "keystore remove" do |c| + command :"keystore remove" do |c| c.syntax = 'leeloo keystore remove ' c.description = "remove a keystore (path/to/keystore is not destroyed)" @@ -92,7 +97,7 @@ def run end end - command "keystore add" do |c| + command :"keystore add" do |c| c.syntax = 'leeloo keystore add ' c.description = "add a keystore" @@ -106,7 +111,7 @@ def run end end - command "keystore default" do |c| + command :"keystore default" do |c| c.syntax = 'leeloo keystore default name' c.description = "set the default keystore" @@ -131,7 +136,7 @@ def run end end - command "key sync" do |c| + command :"key sync" do |c| c.syntax = 'leeloo keys sync' c.description = "synchronize secrets with keys" c.option '--keystore STRING', String, 'a selected keystore' @@ -143,7 +148,7 @@ def run end end - command "key add" do |c| + command :"key add" do |c| c.syntax = 'leeloo key add ' c.description = "add a dedicated key" c.option '--keystore STRING', String, 'a selected keystore' @@ -157,7 +162,7 @@ def run end end - command "key remove" do |c| + command :"key remove" do |c| c.syntax = 'leeloo key remove ' c.description = "remove a dedicated key" c.option '--keystore STRING', String, 'a selected keystore' @@ -202,6 +207,23 @@ def run ctl.display end end + alias_command :insert, :write + + command :generate do |c| + c.syntax = 'leeloo generate ' + c.description = "Generate a secret from a keystore" + c.option '--keystore STRING', String, 'a selected keystore' + c.option '--clipboard', nil, 'copy to clipboard' + + c.action do |args, options| + abort "name or number are missing" unless args.length == 2 + name = args.first + options.__hash__[:generate] = args.last.to_i + ctl = SecretController.new(options) + ctl.write(name) + ctl.display + end + end command :translate do |c| c.syntax = 'leeloo translate' @@ -229,8 +251,9 @@ def run puts "done." end end + alias_command :rm, :remove - command "keystore sync" do |c| + command :"keystore sync" do |c| c.syntax = 'leeloo sync' c.description = "Synchronize a keystore" c.option '--keystore STRING', String, 'a selected keystore' @@ -242,7 +265,7 @@ def run end end - command "keystore export" do |c| + command :"keystore export" do |c| c.syntax = 'leeloo export' c.description = "Export all secrets from a keystore" c.option '--keystore STRING', String, 'a selected keystore' @@ -253,7 +276,7 @@ def run end end - command "keystore init" do |c| + command :"keystore init" do |c| c.syntax = 'leeloo init' c.description = "Initialize a keystore" c.option '--keystore STRING', String, 'a selected keystore' diff --git a/leeloo/lib/leeloo/controller.rb b/leeloo/lib/leeloo/controller.rb index 1c7e3d7..af9e7a5 100644 --- a/leeloo/lib/leeloo/controller.rb +++ b/leeloo/lib/leeloo/controller.rb @@ -83,8 +83,8 @@ def write name phrase = SecureRandom.base64(32).truncate(@options.generate.to_i) if @options.generate unless phrase - phrase = password "secret" - confirm = password "confirm it" + phrase = password "Enter password for #{name}" + confirm = password "Confirm it" abort "not the same secret" unless phrase == confirm end diff --git a/leeloo/lib/leeloo/keystore.rb b/leeloo/lib/leeloo/keystore.rb index 6e50965..2ba6114 100644 --- a/leeloo/lib/leeloo/keystore.rb +++ b/leeloo/lib/leeloo/keystore.rb @@ -72,6 +72,7 @@ class PrivateLocalFileSystemKeystore < Keystore def initialize name, path super name @path = path + FileUtils.touch "#{@path}/.gpg-id" FileUtils.mkdir_p "#{@path}/secrets" end diff --git a/leeloo/lib/leeloo/version.rb b/leeloo/lib/leeloo/version.rb index 1638646..a544a64 100644 --- a/leeloo/lib/leeloo/version.rb +++ b/leeloo/lib/leeloo/version.rb @@ -1,4 +1,4 @@ module Leeloo - VERSION = '0.5.1'.freeze + VERSION = '0.5.2'.freeze DESCRIPTION = "The easiest way to share securely your secrets".freeze end