gpgenv 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.pryrc +2 -0
- data/bang +0 -0
- data/bin/dotenv2gpg +12 -0
- data/bin/gpg2dotenv +12 -0
- data/bin/gpgedit +11 -0
- data/bin/gpgenv +2 -2
- data/bin/gpgset +12 -0
- data/bin/gpgshell +12 -0
- data/gpgenv.gemspec +1 -0
- data/lib/gpgenv/edit_command.rb +35 -0
- data/lib/gpgenv/exec_command.rb +1 -5
- data/lib/gpgenv/export_command.rb +11 -15
- data/lib/gpgenv/import_command.rb +13 -19
- data/lib/gpgenv/set_command.rb +21 -0
- data/lib/gpgenv/shell_command.rb +1 -5
- data/lib/gpgenv/version.rb +1 -1
- data/lib/gpgenv.rb +27 -35
- metadata +30 -4
- data/lib/gpgenv/config.rb +0 -7
- data/lib/gpgenv/main_command.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a766f9fb2e19f31afb07dccee60a02b2a5223e56
|
4
|
+
data.tar.gz: e8491b464059bd169ec725760f64f80cad1f119c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dfc1f23d9ad0d63f0402ca33d3ef69485cbe714f302443fa20aa3b6c0fd28982b53b33fad6eef9b1f6147948343ad2dc2647aa4bb795492507e32196919e031
|
7
|
+
data.tar.gz: d1cb7b8b2665462d61a4f72bc4e32fbaa637051780a3f1af497b7b718ad0779432844488ee29ba96f4fbe17bb996f320170cbb8fb10d328414eb6da1a1ebe50c
|
data/.gitignore
CHANGED
data/.pryrc
ADDED
data/bang
ADDED
File without changes
|
data/bin/dotenv2gpg
ADDED
data/bin/gpg2dotenv
ADDED
data/bin/gpgedit
ADDED
data/bin/gpgenv
CHANGED
data/bin/gpgset
ADDED
data/bin/gpgshell
ADDED
data/gpgenv.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 1.9"
|
32
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "pry"
|
33
34
|
spec.add_development_dependency "rspec"
|
34
35
|
spec.add_development_dependency "simplecov"
|
35
36
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'clamp'
|
3
|
+
require 'gpgenv'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
|
7
|
+
module Gpgenv
|
8
|
+
class EditCommand < Clamp::Command
|
9
|
+
|
10
|
+
def execute
|
11
|
+
env = Gpgenv.read_files
|
12
|
+
Tempfile.open('.env', ENV.fetch('TMPDIR', '/tmp')) do |f|
|
13
|
+
env.each do |k,v|
|
14
|
+
f.write("#{k}=#{v}\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
f.close
|
18
|
+
system("#{ENV['EDITOR']} #{f.path}")
|
19
|
+
f.open
|
20
|
+
|
21
|
+
f.rewind
|
22
|
+
lines = f.read.split("\n")
|
23
|
+
|
24
|
+
::FileUtils.mkdir_p(Gpgenv.dir)
|
25
|
+
lines.each do |line|
|
26
|
+
i = line.index('=')
|
27
|
+
key = line[0..i-1]
|
28
|
+
value = line[i+1..-1]
|
29
|
+
Gpgenv.set(key, value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/gpgenv/exec_command.rb
CHANGED
@@ -7,11 +7,7 @@ module Gpgenv
|
|
7
7
|
parameter "ARGUMENTS ...", "arguments", :attribute_name => :args
|
8
8
|
|
9
9
|
def execute
|
10
|
-
|
11
|
-
directories = args[0..-2]
|
12
|
-
hash = Gpgenv.read_files(directories)
|
13
|
-
hash.each{ |k,v| ENV[k]=v }
|
14
|
-
exec cmd
|
10
|
+
Gpgenv.exec_command args[0..-1].join(' ')
|
15
11
|
end
|
16
12
|
|
17
13
|
end
|
@@ -1,26 +1,22 @@
|
|
1
|
+
require 'gpgenv'
|
2
|
+
require 'shellwords'
|
1
3
|
require 'clamp'
|
2
4
|
|
3
5
|
module Gpgenv
|
4
|
-
class ExportCommand
|
5
|
-
parameter 'DIRS ...', 'dirs', :attribute_name => :directories
|
6
|
+
class ExportCommand < Clamp::Command
|
6
7
|
|
7
|
-
option '
|
8
|
+
option ['-f', '--force'], :flag, "Force overwrite of existing .env file"
|
8
9
|
|
9
|
-
def
|
10
|
-
if
|
11
|
-
"
|
12
|
-
else
|
13
|
-
dir
|
10
|
+
def execute
|
11
|
+
if File.exist?('.env') && !force?
|
12
|
+
fail(".env file already exists. Use --force to overwrite it.")
|
14
13
|
end
|
15
|
-
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
str << "#{k}=#{v}\n"
|
15
|
+
File.open('.env', 'w') do |f|
|
16
|
+
Gpgenv.read_files.each do |k, v|
|
17
|
+
f.write "#{k}=#{Shellwords.escape(v)}"
|
18
|
+
end
|
22
19
|
end
|
23
|
-
File.write(file, str)
|
24
20
|
end
|
25
21
|
|
26
22
|
end
|
@@ -1,32 +1,26 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'gpgenv'
|
3
|
+
require 'shellwords'
|
1
4
|
require 'clamp'
|
2
5
|
|
3
6
|
module Gpgenv
|
4
|
-
class ImportCommand
|
5
|
-
option '--dir', 'DIRECTORY', 'directory, relative to $GPGENV_HOME, to store files in', :attribute_name => 'dir', :required => true
|
6
|
-
option '--file', 'FILE', 'env file to read from', :default => '.env'
|
7
|
+
class ImportCommand < Clamp::Command
|
7
8
|
|
8
|
-
|
9
|
-
if ENV['GPGENV_HOME']
|
10
|
-
index = ENV['GPGENV_HOME'].index('.password-store')
|
11
|
-
prefix = ENV['GPGENV_HOME'][index+16..-1]
|
12
|
-
"#{prefix}/#{dir}"
|
13
|
-
else
|
14
|
-
dir
|
15
|
-
end
|
16
|
-
end
|
9
|
+
option ['-f', '--force'], :flag, "Force overwrite of existing .gpg directory, totally erases it."
|
17
10
|
|
18
11
|
def execute
|
19
|
-
|
20
|
-
|
12
|
+
if File.exist?(Gpgenv.dir) && !force?
|
13
|
+
fail("#{Gpgenv.dir} already exists. Use --force to overwrite it.")
|
14
|
+
end
|
15
|
+
|
16
|
+
::FileUtils.mkdir_p(Gpgenv.dir)
|
17
|
+
File.open('.env', 'r').each_line do |line|
|
21
18
|
i = line.index('=')
|
22
19
|
key=line[0..i-1]
|
23
20
|
value=line[i+1..-1]
|
24
|
-
|
25
|
-
cmd="echo \"#{Shellwords.shellescape(value)}\" | pass insert -f -m #{full_dir}/#{key}"
|
26
|
-
puts cmd
|
27
|
-
system "echo \"#{Shellwords.shellescape(key)}\" | pass insert -f -m #{full_dir}/#{key}"
|
21
|
+
Gpgenv.set(key, value)
|
28
22
|
end
|
29
23
|
end
|
24
|
+
|
30
25
|
end
|
31
26
|
end
|
32
|
-
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'clamp'
|
2
|
+
require 'gpgenv'
|
3
|
+
|
4
|
+
module Gpgenv
|
5
|
+
class SetCommand < Clamp::Command
|
6
|
+
|
7
|
+
parameter "ARGUMENTS ...", "arguments", :attribute_name => :args
|
8
|
+
|
9
|
+
def execute
|
10
|
+
FileUtils.mkdir_p(Gpgenv.dir)
|
11
|
+
if args.size == 1
|
12
|
+
Gpgenv.set(args[0], STDIN.read)
|
13
|
+
elsif args.size == 2
|
14
|
+
Gpgenv.set(args.first, args.last)
|
15
|
+
else
|
16
|
+
fail("Usage: gpgset KEY [VALUE]")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/gpgenv/shell_command.rb
CHANGED
@@ -5,12 +5,8 @@ require 'clamp'
|
|
5
5
|
module Gpgenv
|
6
6
|
class ShellCommand < Clamp::Command
|
7
7
|
|
8
|
-
parameter "DIRECTORIES ...", "directories", :attribute_name => :directories
|
9
|
-
|
10
8
|
def execute
|
11
|
-
|
12
|
-
hash = Gpgenv.read_files(directories)
|
13
|
-
hash.each do |k, v|
|
9
|
+
Gpgenv.read_files.each do |k, v|
|
14
10
|
puts "export #{k}=#{Shellwords.escape(v)}"
|
15
11
|
end
|
16
12
|
end
|
data/lib/gpgenv/version.rb
CHANGED
data/lib/gpgenv.rb
CHANGED
@@ -1,47 +1,39 @@
|
|
1
1
|
require "gpgenv/version"
|
2
|
-
require 'gpgenv/config'
|
3
2
|
require 'gpgenv/error'
|
3
|
+
require 'shellwords'
|
4
4
|
|
5
5
|
module Gpgenv
|
6
|
-
def self.read_files(directories)
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
7
|
+
def self.read_files
|
8
|
+
hash = {}
|
9
|
+
|
10
|
+
Dir.glob("#{dir}/*.gpg").each do |f|
|
11
|
+
ext = File.extname(f)
|
12
|
+
var = File.basename(f, ext)
|
13
|
+
if ext == '.gpg'
|
14
|
+
data = `gpg --batch --quiet --decrypt #{f}`
|
15
|
+
raise Error.new("Decrypting #{f} failed.") unless $?.success?
|
16
|
+
else
|
17
|
+
data = File.read(f)
|
21
18
|
end
|
19
|
+
hash[var] = data.rstrip
|
22
20
|
end
|
21
|
+
hash
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
raise Error.new("#{d} is not a directory.") unless File.directory?(d)
|
28
|
-
end
|
24
|
+
def self.set(key, value)
|
25
|
+
system "echo #{Shellwords.shellescape(value)} | gpg --batch --yes -e -r #{key_id} -o #{dir}/#{key}.gpg"
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
ext = File.extname(f)
|
34
|
-
var = File.basename(f, ext)
|
35
|
-
if ext == '.gpg'
|
36
|
-
data = `gpg --batch --quiet --decrypt #{f}`
|
37
|
-
raise Error.new("Decrypting #{f} failed.") unless $?.success?
|
38
|
-
else
|
39
|
-
data = File.read(f)
|
40
|
-
end
|
41
|
-
hash[var] = data.rstrip
|
42
|
-
end
|
43
|
-
end
|
28
|
+
def self.exec_command(cmd)
|
29
|
+
exec(read_files, cmd)
|
30
|
+
end
|
44
31
|
|
45
|
-
|
32
|
+
def self.dir
|
33
|
+
"#{Dir.pwd}/.gpgenv"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.key_id
|
37
|
+
ENV['GPGENV_KEY_ID'] || fail("GPGENV_KEY_ID must be set.")
|
46
38
|
end
|
47
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gpgenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Shea
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clamp
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,26 +98,38 @@ description: Plays nicely with passwordstore.org
|
|
84
98
|
email:
|
85
99
|
- michael.shea@heroku.com
|
86
100
|
executables:
|
101
|
+
- dotenv2gpg
|
102
|
+
- gpg2dotenv
|
103
|
+
- gpgedit
|
87
104
|
- gpgenv
|
105
|
+
- gpgset
|
106
|
+
- gpgshell
|
88
107
|
extensions: []
|
89
108
|
extra_rdoc_files: []
|
90
109
|
files:
|
91
110
|
- ".gitignore"
|
111
|
+
- ".pryrc"
|
92
112
|
- ".rspec"
|
93
113
|
- ".travis.yml"
|
94
114
|
- Gemfile
|
95
115
|
- LICENSE
|
96
116
|
- README.md
|
97
117
|
- Rakefile
|
118
|
+
- bang
|
119
|
+
- bin/dotenv2gpg
|
120
|
+
- bin/gpg2dotenv
|
121
|
+
- bin/gpgedit
|
98
122
|
- bin/gpgenv
|
123
|
+
- bin/gpgset
|
124
|
+
- bin/gpgshell
|
99
125
|
- gpgenv.gemspec
|
100
126
|
- lib/gpgenv.rb
|
101
|
-
- lib/gpgenv/
|
127
|
+
- lib/gpgenv/edit_command.rb
|
102
128
|
- lib/gpgenv/error.rb
|
103
129
|
- lib/gpgenv/exec_command.rb
|
104
130
|
- lib/gpgenv/export_command.rb
|
105
131
|
- lib/gpgenv/import_command.rb
|
106
|
-
- lib/gpgenv/
|
132
|
+
- lib/gpgenv/set_command.rb
|
107
133
|
- lib/gpgenv/shell_command.rb
|
108
134
|
- lib/gpgenv/version.rb
|
109
135
|
homepage: https://github.com/heroku/gpgenv
|
data/lib/gpgenv/config.rb
DELETED
data/lib/gpgenv/main_command.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'clamp'
|
2
|
-
require 'gpgenv/exec_command'
|
3
|
-
require 'gpgenv/import_command'
|
4
|
-
require 'gpgenv/export_command'
|
5
|
-
require 'gpgenv/shell_command'
|
6
|
-
|
7
|
-
module Gpgenv
|
8
|
-
class MainCommand < Clamp::Command
|
9
|
-
subcommand 'exec', 'Exec a command', Gpgenv::ExecCommand
|
10
|
-
subcommand 'import', 'Import from .env to gpgenv', ImportCommand
|
11
|
-
subcommand 'export', 'Export from gpgenv to .env', ExportCommand
|
12
|
-
subcommand 'shell', 'Print out "export" commands, for use with eval', ShellCommand
|
13
|
-
|
14
|
-
def execute
|
15
|
-
super
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|