gpgenv 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -7
- data/lib/gpgenv/base_command.rb +1 -1
- data/lib/gpgenv/edit_command.rb +34 -32
- data/lib/gpgenv/exec_command.rb +3 -15
- data/lib/gpgenv/executor_provider.rb +18 -0
- data/lib/gpgenv/profile.rb +4 -2
- data/lib/gpgenv/shell_command.rb +11 -4
- data/lib/gpgenv/version.rb +1 -1
- data/lib/gpgenv.rb +0 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4134e591d0fa638a7abbdb84f88cc52b356d16ea
|
4
|
+
data.tar.gz: 908031007c8d67fa59ceea449d390de988b3e35e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41df5b4c20ed2e4d84ea414374d5d4ca243f459d9ae04fd392fbc2212b32301dcb3119250b70c96913ff6f00d6acb1b54857c5bfb1b5dc2973d1d73e84004dd0
|
7
|
+
data.tar.gz: 979419629cbc17df4052bdffb11780b5dc7d1faf639414c327c5f0c249d7d41c33c3c3210f4c86926ce91e3257c66c02c10d270031693ee6defda593d1d523c9
|
data/README.md
CHANGED
@@ -14,38 +14,56 @@ export them as environment variables, and never store sensitive information in p
|
|
14
14
|
I hope that you find `gpgenv` useful, and you use it to avoid security sins.
|
15
15
|
|
16
16
|
## Installation
|
17
|
-
|
17
|
+
`gem install gpgenv`
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
### Setup
|
22
22
|
```bash
|
23
|
-
#
|
23
|
+
# Add this to your profile:
|
24
24
|
export GPGENV_KEY_ID=<key-id-to-use-to-encrypt-stuff>
|
25
25
|
```
|
26
26
|
|
27
27
|
### Create or update files in a .gpgenv directory
|
28
28
|
|
29
29
|
Gpgenv can create a .gpgenv directory without you ever needing to store plaintext
|
30
|
-
files permanently on disk.
|
31
|
-
|
30
|
+
files permanently on disk. Use `gpgenv edit` to edit a `yaml` file using `$EDITOR`.
|
31
|
+
When you are done editing the file, it will be parsed and saved to your `.gpgenv` directory.
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
You can also use `gpgenv import` to convert a `.env` file in the current directory to a `.gpgenv`
|
34
|
+
directory.
|
35
35
|
|
36
36
|
### Run a process
|
37
37
|
Gpgenv can spawn a child process that inherits environment variables like so:
|
38
38
|
```bash
|
39
|
-
gpgenv
|
39
|
+
gpgenv exec <command> arg1 arg2 ...
|
40
40
|
```
|
41
41
|
|
42
42
|
### Export environment variables
|
43
43
|
Gpgenv can export environment variables in your current shell session, like so:
|
44
|
+
|
44
45
|
```bash
|
45
46
|
cd /dir/that/contains/.gpgenv
|
46
47
|
eval `gpgshell`
|
47
48
|
```
|
48
49
|
|
50
|
+
### Profiles
|
51
|
+
|
52
|
+
Gpgenv supports profiles. Create a ~/.gpgenvrc file like this:
|
53
|
+
|
54
|
+
```yaml
|
55
|
+
---
|
56
|
+
profile1:
|
57
|
+
- /home/YOU/.gpgenv/dir1
|
58
|
+
- /home/YOU/.gpgenv/extra_stuff
|
59
|
+
profile2:
|
60
|
+
- /home/YOU/.gpgenv/dir1
|
61
|
+
```
|
62
|
+
|
63
|
+
You can then pass a `-p` parameter to `gpenv exec` or `gpgenv shell` specifying
|
64
|
+
which profile to use, rather than using the `.gpgenv` directory relative to the current path.
|
65
|
+
All of the directories specified in the profile will be loaded sequentially.
|
66
|
+
|
49
67
|
## Contributing
|
50
68
|
|
51
69
|
1. Fork it ( https://github.com/[my-github-username]/gpgenv/fork )
|
data/lib/gpgenv/base_command.rb
CHANGED
@@ -2,7 +2,7 @@ require 'clamp'
|
|
2
2
|
class Gpgenv
|
3
3
|
class BaseCommand < Clamp::Command
|
4
4
|
|
5
|
-
option ['-d', '--dir'], "DIR", "Directory to read env files from", default: "
|
5
|
+
option ['-d', '--dir'], "DIR", "Directory to read env files from", default: "./.gpgenv"
|
6
6
|
|
7
7
|
def gpgenv
|
8
8
|
@gpgenv ||= Gpgenv.new(dir: dir)
|
data/lib/gpgenv/edit_command.rb
CHANGED
@@ -1,45 +1,57 @@
|
|
1
|
-
require 'fileutils'
|
2
1
|
require 'clamp'
|
2
|
+
require 'fileutils'
|
3
3
|
require 'gpgenv'
|
4
4
|
require 'gpgenv/base_command'
|
5
5
|
require 'tempfile'
|
6
|
-
|
6
|
+
require 'yaml'
|
7
7
|
|
8
8
|
class Gpgenv
|
9
9
|
class EditCommand < Gpgenv::BaseCommand
|
10
10
|
|
11
11
|
def execute
|
12
|
-
env =
|
13
|
-
Tempfile.open('
|
14
|
-
env.
|
15
|
-
f.write("#{k}=#{v}\n")
|
16
|
-
end
|
12
|
+
env = gpgenv.read_files
|
13
|
+
Tempfile.open(['env', '.yaml'], ENV.fetch('TMPDIR', '/tmp')) do |f|
|
14
|
+
f.write(env.to_yaml)
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
done = false
|
17
|
+
new_env = nil
|
18
|
+
begin
|
19
|
+
# Write out current env to the file, as yaml.
|
20
|
+
f.close
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
# Run the user's choice of editor on the file, wait until they're done.
|
23
|
+
system("#{ENV['EDITOR']} #{f.path}")
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
key = line[0..i-1]
|
31
|
-
value = line[i+1..-1]
|
32
|
-
new_env[key] = value
|
33
|
-
end
|
25
|
+
# Reopen the file, return to the start, load yaml from it.
|
26
|
+
f.open
|
27
|
+
f.rewind
|
28
|
+
|
29
|
+
file_contents = f.read
|
34
30
|
|
31
|
+
begin
|
32
|
+
new_env = YAML.load(file_contents)
|
33
|
+
rescue Psych::SyntaxError => e
|
34
|
+
puts e.message
|
35
|
+
STDOUT.write "Invalid yaml file. Try again (y/n)? "
|
36
|
+
fail("Aborted") unless STDIN.gets.downcase.strip == 'y'
|
37
|
+
f.rewind
|
38
|
+
end
|
39
|
+
|
40
|
+
# Keep looping until we get valid yaml.
|
41
|
+
end until new_env
|
42
|
+
|
43
|
+
# Write out yaml to gpgenv.
|
44
|
+
::FileUtils.mkdir_p(gpgenv.dir)
|
35
45
|
new_env.each do |key, value|
|
36
|
-
gpgenv.set(key,
|
46
|
+
gpgenv.set(key, value)
|
37
47
|
end
|
38
48
|
|
49
|
+
# Calculate missing keys
|
39
50
|
missing_keys = env.keys.select do |k|
|
40
51
|
!new_env.keys.include?(k)
|
41
52
|
end
|
42
53
|
|
54
|
+
# Delete missing keys.
|
43
55
|
missing_keys.each do |missing_key|
|
44
56
|
gpgenv.set(missing_key, nil)
|
45
57
|
end
|
@@ -59,16 +71,6 @@ class Gpgenv
|
|
59
71
|
end
|
60
72
|
end
|
61
73
|
|
62
|
-
# Convert from editable back to the format to write to the file.
|
63
|
-
# Replace literal \n with newines, strip quotes.
|
64
|
-
def from_editable(str)
|
65
|
-
if str =~ /\\n/
|
66
|
-
str.gsub(/\\n/, "\n")
|
67
|
-
else
|
68
|
-
str
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
74
|
end
|
73
75
|
|
74
76
|
end
|
data/lib/gpgenv/exec_command.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'clamp'
|
2
|
+
require 'gpgenv'
|
2
3
|
require 'gpgenv/base_command'
|
4
|
+
require 'gpgenv/executor_provider'
|
3
5
|
require 'gpgenv/profile'
|
4
|
-
require 'gpgenv'
|
5
6
|
|
6
7
|
class Gpgenv
|
7
8
|
class ExecCommand < Gpgenv::BaseCommand
|
9
|
+
include ExecutorProvider
|
8
10
|
|
9
11
|
option ['-p', '--profile'], "PROFILE", "Profile to use, from ~/.gpgenvrc", attribute_name: :profile
|
10
12
|
parameter "ARGUMENTS ...", "arguments", :attribute_name => :args
|
@@ -13,19 +15,5 @@ class Gpgenv
|
|
13
15
|
executor.exec_command args[0..-1].join(' ')
|
14
16
|
end
|
15
17
|
|
16
|
-
def executor
|
17
|
-
# If GPGENV_PRPOFILE is set or a profile is passed on the CLI, use the given profile
|
18
|
-
# Otherwise use a standard Gpgenv object to execute.
|
19
|
-
if prof
|
20
|
-
Profile.new("#{ENV['HOME']}/.gpgenvrc", prof)
|
21
|
-
else
|
22
|
-
gpgenv
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def prof
|
27
|
-
profile || ENV['GPGENV_PROFILE']
|
28
|
-
end
|
29
|
-
|
30
18
|
end
|
31
19
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'gpgenv/profile'
|
2
|
+
class Gpgenv
|
3
|
+
module ExecutorProvider
|
4
|
+
def executor
|
5
|
+
# If GPGENV_PRPOFILE is set or a profile is passed on the CLI, use the given profile
|
6
|
+
# Otherwise use a standard Gpgenv object to execute.
|
7
|
+
if prof
|
8
|
+
Profile.new("#{ENV['HOME']}/.gpgenvrc", prof)
|
9
|
+
else
|
10
|
+
gpgenv
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def prof
|
15
|
+
profile || ENV['GPGENV_PROFILE']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/gpgenv/profile.rb
CHANGED
@@ -12,8 +12,6 @@ class Gpgenv
|
|
12
12
|
exec(read_files, cmd)
|
13
13
|
end
|
14
14
|
|
15
|
-
private
|
16
|
-
|
17
15
|
def read_files
|
18
16
|
hash = {}
|
19
17
|
gpgenvs.each do |gpgenv|
|
@@ -22,10 +20,14 @@ class Gpgenv
|
|
22
20
|
hash
|
23
21
|
end
|
24
22
|
|
23
|
+
private
|
24
|
+
|
25
25
|
def gpgenvs
|
26
26
|
fail(".gpgenvrc file does not exist") unless File.exist?(file)
|
27
|
+
|
27
28
|
yaml = YAML.load(File.read(file))
|
28
29
|
fail("Invalid .gpgenvrc file") unless yaml.is_a?(Hash)
|
30
|
+
|
29
31
|
value = yaml[name]
|
30
32
|
|
31
33
|
fail("No such profile: #{name} in .gpgenvrc") unless value
|
data/lib/gpgenv/shell_command.rb
CHANGED
@@ -1,16 +1,23 @@
|
|
1
|
-
require 'gpgenv'
|
2
|
-
require 'shellwords'
|
3
1
|
require 'clamp'
|
2
|
+
require 'gpgenv'
|
4
3
|
require 'gpgenv/base_command'
|
4
|
+
require 'gpgenv/executor_provider'
|
5
|
+
require 'shellwords'
|
5
6
|
|
6
7
|
class Gpgenv
|
8
|
+
|
7
9
|
class ShellCommand < Gpgenv::BaseCommand
|
8
10
|
|
11
|
+
include ExecutorProvider
|
12
|
+
|
13
|
+
option ['-p', '--profile'], "PROFILE", "Profile to use, from ~/.gpgenvrc", attribute_name: :profile
|
14
|
+
|
9
15
|
def execute
|
10
|
-
|
11
|
-
puts "export #{k}
|
16
|
+
executor.read_files.each do |k, v|
|
17
|
+
puts "export #{k}='#{v.gsub("'", "\'").gsub("\n", "\\n")}'"
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
15
21
|
end
|
22
|
+
|
16
23
|
end
|
data/lib/gpgenv/version.rb
CHANGED
data/lib/gpgenv.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Shea
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/gpgenv/edit_command.rb
|
142
142
|
- lib/gpgenv/error.rb
|
143
143
|
- lib/gpgenv/exec_command.rb
|
144
|
+
- lib/gpgenv/executor_provider.rb
|
144
145
|
- lib/gpgenv/export_command.rb
|
145
146
|
- lib/gpgenv/gpgenv_command.rb
|
146
147
|
- lib/gpgenv/import_command.rb
|