gpgenv 0.1.4 → 0.1.5

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: d779ed0c8aed80a81a2db211b6990d2653910ee2
4
- data.tar.gz: 6a9afb2072364af270d5456decdb633f362140e7
3
+ metadata.gz: 23dabff81dce36a19ee497ea877ba0c953d5fcad
4
+ data.tar.gz: bfda2ffd3841dc7755d5b51022b306fadcacfeb1
5
5
  SHA512:
6
- metadata.gz: 37458f219f3b15e4a6802a37d02b0c923716c778065721799192445baa2e54b9594d9ea8ac4240595a7f6adc93927c77b2d354a0a2dcb8cdc6a267b7e0be5a2b
7
- data.tar.gz: ea868f8200878b67c4026264dfe12052eaa2dff8b238659d59c77b1bf8b62bc52e81766485427ccfc7f128c60626d7e14a3c9b0f6308e1d2faad72c852cc686f
6
+ metadata.gz: 4b52ad37a810bc6174d6550e725c353e053dff9ac44d5a3224625a9b56b79ed0bc33d68f402b650cb933d10e1ec1ecd05c06120ec6cb425b469445e8c483ebf3
7
+ data.tar.gz: 614b4e19d4a87e0d803f4b691559a31d13ac8dcd8a1791adecc2ee1e8e6a98184c89183e10d7b7dcb16580b3ad8d3aa7866fa38c2d9dc29ee0a04a6038c7a041
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  *.gem
12
12
  .gpgenv/**/*
13
13
  .env
14
+ /tags
data/README.md CHANGED
@@ -10,8 +10,10 @@ As an admin, I am guilty of occasionally storing sensitive credentials on disk.
10
10
  extremely common. Your .netrc file probably contains all sorts of sensitive data, and even if you use a gpg-encrypted .netrc file, many tools
11
11
  simply don't understand gpg. Storing this stuff in plaintext is dangerous - but you do it anyway because the alternatives are just too painful.
12
12
 
13
- I love [pass](http://www.passwordstore.org/), because it makes it easy to store passwords encrypted. But it doesn't make it easy to *use* them in any capacity other than copy-and-pasting them. I wrote `gpgenv` to bridge that gap, and make it easy for me to never store sensitive information in an unencrypted format
14
- on my own machine. I hope that you find it useful as well, and you use it to stop yourself from committing security sins.
13
+ I love [pass](http://www.passwordstore.org/), because it makes it easy to store passwords encrypted. But it doesn't make it easy to *use*
14
+ them in any capacity other than copy-and-pasting them. I wrote `gpgenv` to bridge that gap: Easily edit gpg-encrypted files, easily
15
+ export them as environment variables, and never store sensitive information in plaintext on your machine.
16
+ I hope that you find `gpgenv` useful, and you use it to avoid security sins.
15
17
 
16
18
  ## Installation
17
19
  ```gem install gpgenv```
@@ -27,8 +29,8 @@ export GPGENV_KEY_ID=<key-id-to-use-to-encrypt-stuff>
27
29
  ### Create or update files in a .gpgenv directory
28
30
 
29
31
  Gpgenv can create a .gpgenv directory without you ever needing to store plaintext
30
- files permanently on disk. Simply run `gpgedit` to either create a new .gpgenv
31
- directory, or edit the keys and values in an existing one.
32
+ files permanently on disk. Simply run `gpgedit` to create a new .gpgenv
33
+ directory or edit the keys and values in an existing one.
32
34
 
33
35
  Alternatively, if you have a .env file and you'd like to switch to gpgenv, run
34
36
  `dotenv2gpg`. You can switch back by running `gpg2dotenv`, if you choose.
@@ -42,7 +44,7 @@ gpgenv "process_to_run argument1 argument2"
42
44
  ### Export environment variables
43
45
  Gpgenv can export environment variables in your current shell session, like so:
44
46
  ```bash
45
- cd /dir/that/has/a/.gpgenv/subdirectory
47
+ cd /dir/that/contains/.gpgenv
46
48
  eval `gpgshell`
47
49
  ```
48
50
 
data/gpgenv.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency 'clamp'
30
30
 
31
31
  spec.add_development_dependency "bundler", "~> 1.9"
32
+ spec.add_development_dependency "byebug"
32
33
  spec.add_development_dependency "rake", "~> 10.0"
33
34
  spec.add_development_dependency "pry"
34
35
  spec.add_development_dependency "rspec"
@@ -0,0 +1,12 @@
1
+ require 'clamp'
2
+ class Gpgenv
3
+ class BaseCommand < Clamp::Command
4
+
5
+ option ['-d', '--dir'], "DIR", "Directory to read env files from", default: "#{Dir.pwd}/.gpgenv"
6
+
7
+ def gpgenv
8
+ @gpgenv ||= Gpgenv.new(dir: dir)
9
+ end
10
+
11
+ end
12
+ end
@@ -1,14 +1,15 @@
1
1
  require 'fileutils'
2
2
  require 'clamp'
3
3
  require 'gpgenv'
4
+ require 'gpgenv/base_command'
4
5
  require 'tempfile'
5
6
 
6
7
 
7
- module Gpgenv
8
- class EditCommand < Clamp::Command
8
+ class Gpgenv
9
+ class EditCommand < Gpgenv::BaseCommand
9
10
 
10
11
  def execute
11
- env = Hash[Gpgenv.read_files.map{|k,v| [ k, to_editable(v) ] }]
12
+ env = Hash[gpgenv.read_files.map{|k,v| [ k, to_editable(v) ] }]
12
13
  Tempfile.open('.env', ENV.fetch('TMPDIR', '/tmp')) do |f|
13
14
  env.each do |k,v|
14
15
  f.write("#{k}=#{v}\n")
@@ -21,13 +22,28 @@ module Gpgenv
21
22
  f.rewind
22
23
  lines = f.read.split("\n")
23
24
 
24
- ::FileUtils.mkdir_p(Gpgenv.dir)
25
- lines.each do |line|
25
+ ::FileUtils.mkdir_p(gpgenv.dir)
26
+ new_env = {}
27
+ lines.each_with_index do |line, index|
26
28
  i = line.index('=')
29
+ fail("Line #{index+1} is invalid") unless i
27
30
  key = line[0..i-1]
28
31
  value = line[i+1..-1]
29
- Gpgenv.set(key, from_editable(value))
32
+ new_env[key] = value
30
33
  end
34
+
35
+ new_env.each do |key, value|
36
+ gpgenv.set(key, from_editable(value))
37
+ end
38
+
39
+ missing_keys = env.keys.select do |k|
40
+ !new_env.keys.include?(k)
41
+ end
42
+
43
+ missing_keys.each do |missing_key|
44
+ gpgenv.set(missing_key, nil)
45
+ end
46
+
31
47
  end
32
48
  end
33
49
 
@@ -54,4 +70,5 @@ module Gpgenv
54
70
  end
55
71
 
56
72
  end
73
+
57
74
  end
data/lib/gpgenv/error.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Gpgenv
1
+ class Gpgenv
2
2
  class Error < StandardError
3
3
  end
4
4
  end
@@ -1,13 +1,14 @@
1
1
  require 'clamp'
2
+ require 'gpgenv/base_command'
2
3
  require 'gpgenv'
3
4
 
4
- module Gpgenv
5
- class ExecCommand < Clamp::Command
5
+ class Gpgenv
6
+ class ExecCommand < Gpgenv::BaseCommand
6
7
 
7
8
  parameter "ARGUMENTS ...", "arguments", :attribute_name => :args
8
9
 
9
10
  def execute
10
- Gpgenv.exec_command args[0..-1].join(' ')
11
+ gpgenv.exec_command args[0..-1].join(' ')
11
12
  end
12
13
 
13
14
  end
@@ -1,9 +1,10 @@
1
1
  require 'gpgenv'
2
+ require 'gpgenv/base_command'
2
3
  require 'shellwords'
3
4
  require 'clamp'
4
5
 
5
- module Gpgenv
6
- class ExportCommand < Clamp::Command
6
+ class Gpgenv
7
+ class ExportCommand < Gpgenv::BaseCommand
7
8
 
8
9
  option ['-f', '--force'], :flag, "Force overwrite of existing .env file"
9
10
 
@@ -13,7 +14,7 @@ module Gpgenv
13
14
  end
14
15
 
15
16
  File.open('.env', 'w') do |f|
16
- Gpgenv.read_files.each do |k, v|
17
+ gpgenv.read_files.each do |k, v|
17
18
  f.write "#{k}=#{Shellwords.escape(v)}"
18
19
  end
19
20
  end
@@ -1,24 +1,25 @@
1
1
  require 'fileutils'
2
2
  require 'gpgenv'
3
+ require 'gpgenv/base_command'
3
4
  require 'shellwords'
4
5
  require 'clamp'
5
6
 
6
- module Gpgenv
7
- class ImportCommand < Clamp::Command
7
+ class Gpgenv
8
+ class ImportCommand < Gpgenv::BaseCommand
8
9
 
9
10
  option ['-f', '--force'], :flag, "Force overwrite of existing .gpg directory, totally erases it."
10
11
 
11
12
  def execute
12
- if File.exist?(Gpgenv.dir) && !force?
13
- fail("#{Gpgenv.dir} already exists. Use --force to overwrite it.")
13
+ if File.exist?(gpgenv.dir) && !force?
14
+ fail("#{gpgenv.dir} already exists. Use --force to overwrite it.")
14
15
  end
15
16
 
16
- ::FileUtils.mkdir_p(Gpgenv.dir)
17
+ ::FileUtils.mkdir_p(gpgenv.dir)
17
18
  File.open('.env', 'r').each_line do |line|
18
19
  i = line.index('=')
19
20
  key=line[0..i-1]
20
21
  value=line[i+1..-1]
21
- Gpgenv.set(key, value)
22
+ gpgenv.set(key, value)
22
23
  end
23
24
  end
24
25
 
@@ -1,17 +1,18 @@
1
1
  require 'clamp'
2
2
  require 'gpgenv'
3
+ require 'gpgenv/base_command'
3
4
 
4
- module Gpgenv
5
- class SetCommand < Clamp::Command
5
+ class Gpgenv
6
+ class SetCommand < Gpgenv::BaseCommand
6
7
 
7
8
  parameter "ARGUMENTS ...", "arguments", :attribute_name => :args
8
9
 
9
10
  def execute
10
11
  FileUtils.mkdir_p(Gpgenv.dir)
11
12
  if args.size == 1
12
- Gpgenv.set(args[0], STDIN.read)
13
+ gpgenv.set(args[0], STDIN.read)
13
14
  elsif args.size == 2
14
- Gpgenv.set(args.first, args.last)
15
+ gpgenv.set(args.first, args.last)
15
16
  else
16
17
  fail("Usage: gpgset KEY [VALUE]")
17
18
  end
@@ -1,12 +1,13 @@
1
1
  require 'gpgenv'
2
2
  require 'shellwords'
3
3
  require 'clamp'
4
+ require 'gpgenv/base_command'
4
5
 
5
- module Gpgenv
6
- class ShellCommand < Clamp::Command
6
+ class Gpgenv
7
+ class ShellCommand < Gpgenv::BaseCommand
7
8
 
8
9
  def execute
9
- Gpgenv.read_files.each do |k, v|
10
+ gpgenv.read_files.each do |k, v|
10
11
  puts "export #{k}=#{Shellwords.escape(v)}"
11
12
  end
12
13
  end
@@ -1,3 +1,3 @@
1
- module Gpgenv
2
- VERSION = "0.1.4"
1
+ class Gpgenv
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/gpgenv.rb CHANGED
@@ -2,11 +2,21 @@ require "gpgenv/version"
2
2
  require 'gpgenv/error'
3
3
  require 'shellwords'
4
4
 
5
- module Gpgenv
5
+ class Gpgenv
6
6
 
7
- def self.read_files
7
+ attr_reader :dir
8
+
9
+ def initialize(dir:)
10
+ @dir = dir
11
+ end
12
+
13
+ def read_files
8
14
  hash = {}
9
15
 
16
+ fail("#{dir} does not exist.") unless File.exist?(dir)
17
+ fail("#{dir} is not a directory.") unless File.directory?(dir)
18
+
19
+
10
20
  Dir.glob("#{dir}/*.gpg").each do |f|
11
21
  ext = File.extname(f)
12
22
  var = File.basename(f, ext)
@@ -21,19 +31,20 @@ module Gpgenv
21
31
  hash
22
32
  end
23
33
 
24
- def self.set(key, value)
25
- system "echo #{Shellwords.shellescape(value)} | gpg --batch --yes -e -r #{key_id} -o #{dir}/#{key}.gpg"
34
+ def set(key, value)
35
+ if value.nil?
36
+ File.delete("#{dir}/#{key}.gpg")
37
+ else
38
+ system "echo #{Shellwords.shellescape(value)} | gpg --batch --yes -e -r #{key_id} -o #{dir}/#{key}.gpg"
39
+ end
26
40
  end
27
41
 
28
- def self.exec_command(cmd)
42
+ def exec_command(cmd)
29
43
  exec(read_files, cmd)
30
44
  end
31
45
 
32
- def self.dir
33
- "#{Dir.pwd}/.gpgenv"
34
- end
35
-
36
- def self.key_id
46
+ def key_id
37
47
  ENV['GPGENV_KEY_ID'] || fail("GPGENV_KEY_ID must be set.")
38
48
  end
49
+
39
50
  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
4
+ version: 0.1.5
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-06-13 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +129,6 @@ files:
115
129
  - LICENSE
116
130
  - README.md
117
131
  - Rakefile
118
- - bang
119
132
  - bin/dotenv2gpg
120
133
  - bin/gpg2dotenv
121
134
  - bin/gpgedit
@@ -124,6 +137,7 @@ files:
124
137
  - bin/gpgshell
125
138
  - gpgenv.gemspec
126
139
  - lib/gpgenv.rb
140
+ - lib/gpgenv/base_command.rb
127
141
  - lib/gpgenv/edit_command.rb
128
142
  - lib/gpgenv/error.rb
129
143
  - lib/gpgenv/exec_command.rb
data/bang DELETED
File without changes