leeloo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f0947c2693f489c179cb9503873aae98b28e8c3
4
- data.tar.gz: 7ca98af2b5903a47a37ec92872011615a670c294
3
+ metadata.gz: fa4daaab758be586a6e9f7fc44e2bb4445c7adf5
4
+ data.tar.gz: af1ae064a581a8807a193d3a6ffe6be7a37476cd
5
5
  SHA512:
6
- metadata.gz: c4becf8486245bc0c0f6a1bd0846103f6a71d9166ebab18aba28d3e092a5804e9e860ad09fe6feba4e93eb1fa0530c9148bb71103154c8121dd0939b7c23067d
7
- data.tar.gz: 22d06419760f57701b34c3f7f4be4694dbe221afbdcc73377da6e36e85e1dbf2b2945f0a51b2e00ad4cf34c7bc03d2360fac08aa6ab64efb0b3ecdf05df8141e
6
+ metadata.gz: d0426b52b963eab544459e05ad7c8cf986e3781c3ccc210fc873f9c04be611a3ded5089031532aa79df22d62894c97fbb3c8483805aa957d322c7bee48518639
7
+ data.tar.gz: 6d2ae73665be34ca2dd566092ce4180a525e8fa06dbd5135a47ba1a39d7752b8a78800ab2460b48351426b461dd0d1205662d3da25613747a332d3459a84681e
data/lib/leeloo.rb CHANGED
File without changes
@@ -1,4 +1,5 @@
1
1
  require 'commander/import'
2
+ require 'securerandom'
2
3
 
3
4
  module Leeloo
4
5
  class Command
@@ -36,54 +37,83 @@ module Leeloo
36
37
  end
37
38
 
38
39
  command :"list secret" do |c|
39
- c.syntax = 'leeloo list secret <keystore>'
40
- c.description = "Display secrets list"
41
- c.action do |args, options|
42
- abort "keytore is missing" unless args.length == 1
40
+ c.syntax = 'leeloo list secret [options]'
41
+ c.description = "Display secrets list of keystore (private by default)"
42
+ c.option '--keystore STRING', String, 'a selected keystore'
43
43
 
44
- Secret::list Config.get_keystore(args.first)
44
+ c.action do |args, options|
45
+ options.default :keystore => 'private'
46
+ Secret::list Config.get_keystore(options.keystore)
45
47
  end
46
48
  end
47
49
 
48
50
  command :"add keystore" do |c|
49
51
  c.syntax = 'leeloo add keystore <name> <path>'
50
- c.description = "add a new keystore"
52
+ c.description = "Add a new keystore"
51
53
 
52
54
  c.action do |args, options|
53
55
 
54
56
  abort "name or path are missing" unless args.length == 2
57
+ name = args.first
58
+ keystore = args.last
55
59
 
56
- Keystore.add_keystore args.first, args.last
57
- Config.add_keystore args.first, args.last
60
+ Keystore.add_keystore name, keystore
61
+ Config.add_keystore name, keystore
62
+ end
63
+ end
64
+
65
+ command :"sync secrets" do |c|
66
+ c.syntax = 'leeloo recrypt secrets'
67
+ c.description = "(re)sync all secrets from a given keystore (private by default)"
68
+ c.option '--keystore STRING', String, 'a selected keystore'
69
+
70
+ c.action do |args, options|
71
+ options.default :keystore => 'private'
72
+ Secret.sync_secrets Config.get_keystore(options.keystore)
58
73
  end
59
74
  end
60
75
 
61
76
  command :"add secret" do |c|
62
- c.syntax = 'leeloo add secret <keystore> <name>'
63
- c.description = "add a new secret in a keystore"
77
+ c.syntax = 'leeloo add secret <name>'
78
+ c.description = "Add a new secret in a keystore (private by default)"
79
+ c.option '--keystore STRING', String, 'a selected keystore'
80
+ c.option '--generate INTEGER', Integer, 'a number of randomized characters'
81
+ c.option '--stdin', nil, 'secret given by stdin pipe'
64
82
 
65
83
  c.action do |args, options|
66
- keystore = Config.get_keystore(args.first)
84
+ abort "name is missing" unless args.length == 1
85
+ name = args.first
86
+
87
+ options.default :keystore => 'private'
88
+ keystore = Config.get_keystore(options.keystore)
89
+
90
+ secret = nil
91
+ secret = STDIN.read if options.stdin
92
+ secret = SecureRandom.base64(options.generate) if options.generate
67
93
 
68
- abort "keytore or name are missing" unless args.length == 2
69
- secret = password "secret"
70
- confirm = password "confirm it"
71
- abort "not the same secret" unless secret == confirm
94
+ unless secret
95
+ secret = password "secret"
96
+ confirm = password "confirm it"
97
+ abort "not the same secret" unless secret == confirm
98
+ end
72
99
 
73
- Secret.add_secret keystore, args.last, secret
100
+ Secret.add_secret keystore, name, secret
74
101
  end
75
102
  end
76
103
 
77
104
  command :"read secret" do |c|
78
- c.syntax = 'leeloo read secret <keystore> <name>'
79
- c.description = "read a secret from a keystore"
105
+ c.syntax = 'leeloo read secret <name>'
106
+ c.description = "Display a secret from a keystore (private by default)"
107
+ c.option '--keystore STRING', String, 'a selected keystore'
80
108
 
81
109
  c.action do |args, options|
82
- keystore = Config.get_keystore(args.first)
110
+ abort "name is missing" unless args.length == 1
111
+ name = args.first
83
112
 
84
- abort "keytore or name are missing" unless args.length == 2
113
+ options.default :keystore => 'private'
114
+ keystore = Config.get_keystore(options.keystore)
85
115
 
86
- Secret.read_secret keystore, args.last
116
+ Secret.read_secret keystore, name
87
117
  end
88
118
  end
89
119
  end
data/lib/leeloo/config.rb CHANGED
@@ -9,6 +9,9 @@ module Leeloo
9
9
  @@keystores = []
10
10
 
11
11
  def self.init
12
+ unless Keystore::secret_key_exists?
13
+ abort "a secret key PGP is mandatory"
14
+ end
12
15
  Keystore::add_keystore "private", "#{PATH}/private"
13
16
  Config::add_keystore "private", "#{PATH}/private"
14
17
  say "Initialization completed"
@@ -5,6 +5,10 @@ require 'git'
5
5
  module Leeloo
6
6
  class Keystore
7
7
 
8
+ def self.secret_key_exists?
9
+ GPGME::Key.find(:secret, nil, ).empty?
10
+ end
11
+
8
12
  def self.add_keystore name, path
9
13
  FileUtils.mkdir_p path
10
14
  FileUtils.mkdir_p "#{path}/secrets/"
data/lib/leeloo/secret.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'gpgme'
2
2
  require 'tty-tree'
3
3
  require 'git'
4
+ require 'fileutils'
4
5
 
5
6
  module Leeloo
6
7
  class Secret
@@ -11,12 +12,9 @@ module Leeloo
11
12
 
12
13
  def self.add_secret(keystore, name, secret)
13
14
  recipients = []
14
- Dir.foreach("#{keystore}/keys") do |key|
15
- unless File.directory? key
16
- recipients << File.basename(key, ".*")
17
- GPGME::Key.import(File.open("#{keystore}/keys/#{key}"))
18
- end
19
- end
15
+ Dir.foreach("#{keystore}/keys") { |key| recipients << File.basename(key, ".*") unless File.directory? key }
16
+
17
+ FileUtils.mkdir_p File.dirname "#{keystore}/secrets/#{name}"
20
18
 
21
19
  crypto = GPGME::Crypto.new :always_trust => true
22
20
  crypto.encrypt secret,
@@ -34,5 +32,42 @@ module Leeloo
34
32
  crypto = GPGME::Crypto.new
35
33
  say crypto.decrypt File.open("#{keystore}/secrets/#{name}")
36
34
  end
35
+
36
+ def self.sync_secrets keystore
37
+
38
+ g = Git.open keystore
39
+
40
+ recipients = []
41
+ Dir.foreach("#{keystore}/keys") do |key|
42
+ unless File.directory? key
43
+ recipients << File.basename(key, ".*")
44
+ GPGME::Key.import(File.open("#{keystore}/keys/#{key}"))
45
+ end
46
+ end
47
+
48
+ crypto = GPGME::Crypto.new :always_trust => true
49
+ find_secrets("#{keystore}/secrets").each do |secret|
50
+ say "."
51
+ decrypted = crypto.decrypt File.open(secret)
52
+ crypto.encrypt decrypted,
53
+ :output => File.open(secret,"w+"),
54
+ :recipients => recipients
55
+ g.add secret
56
+ end
57
+
58
+ g.commit "sync"
59
+
60
+ say "keystore synced successfully"
61
+ end
62
+
63
+ def self.find_secrets path
64
+ elements = []
65
+ Dir.glob("#{path}/**") do |element|
66
+ elements << element unless Dir.exist? element
67
+ elements << find_secrets(element) if Dir.exist? element
68
+ end
69
+ return elements.flatten
70
+ end
71
+
37
72
  end
38
73
  end
@@ -1,4 +1,4 @@
1
1
  module Leeloo
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  DESCRIPTION = "The easiest way to share securely your secrets".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leeloo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvek
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-06 00:00:00.000000000 Z
11
+ date: 2017-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.2.2
160
+ rubygems_version: 2.6.10
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: The easiest way to share securely your secrets