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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 017ba30f555fd557cc878944b5d0506b8b8d0ccf
4
- data.tar.gz: 0f42e386012535c8a387b1fd31080dee5c717ce6
3
+ metadata.gz: a766f9fb2e19f31afb07dccee60a02b2a5223e56
4
+ data.tar.gz: e8491b464059bd169ec725760f64f80cad1f119c
5
5
  SHA512:
6
- metadata.gz: ab81c8a64d35121baea8cb225b7a4598cec12ce6a5e30da6b1adc6340dbc5f81da9f4bb3e1fac60c9afb6d5de9015d8fa6691d56fbb5f6637fa684fc5254d24a
7
- data.tar.gz: 75ffe58628a24a6bf6a3bbd4386b475ec3ae5a3fc96315c3a665104203eaef8bdf8e9bca956b75891714c3a093011532c717de3e52868f8324a43e881c4b63fb
6
+ metadata.gz: 3dfc1f23d9ad0d63f0402ca33d3ef69485cbe714f302443fa20aa3b6c0fd28982b53b33fad6eef9b1f6147948343ad2dc2647aa4bb795492507e32196919e031
7
+ data.tar.gz: d1cb7b8b2665462d61a4f72bc4e32fbaa637051780a3f1af497b7b718ad0779432844488ee29ba96f4fbe17bb996f320170cbb8fb10d328414eb6da1a1ebe50c
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
  /spec/reports/
10
10
  /tmp/
11
11
  *.gem
12
+ .gpgenv/**/*
13
+ .env
data/.pryrc ADDED
@@ -0,0 +1,2 @@
1
+ $:<<'lib'
2
+ require 'gpgenv'
data/bang ADDED
File without changes
data/bin/dotenv2gpg ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgenv/import_command'
3
+ begin
4
+ Gpgenv::ImportCommand.run
5
+ rescue StandardError => bang
6
+ raise if ENV['DEBUG'] == 'true'
7
+ puts bang.message
8
+ exit 1
9
+ end
10
+
11
+
12
+
data/bin/gpg2dotenv ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgenv/export_command'
3
+ begin
4
+ Gpgenv::ExportCommand.run
5
+ rescue StandardError => bang
6
+ raise if ENV['DEBUG'] == 'true'
7
+ puts bang.message
8
+ exit 1
9
+ end
10
+
11
+
12
+
data/bin/gpgedit ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgenv/edit_command'
3
+ begin
4
+ Gpgenv::EditCommand.run
5
+ rescue StandardError => bang
6
+ raise if ENV['DEBUG'] == 'true'
7
+ puts bang.message
8
+ exit 1
9
+ end
10
+
11
+
data/bin/gpgenv CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- require 'gpgenv/main_command'
2
+ require 'gpgenv/exec_command'
3
3
  begin
4
- Gpgenv::MainCommand.run
4
+ Gpgenv::ExecCommand.run
5
5
  rescue StandardError => bang
6
6
  raise if ENV['DEBUG'] == 'true'
7
7
  puts bang.message
data/bin/gpgset ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgenv/set_command'
3
+ begin
4
+ Gpgenv::SetCommand.run
5
+ rescue StandardError => bang
6
+ raise if ENV['DEBUG'] == 'true'
7
+ puts bang.message
8
+ exit 1
9
+ end
10
+
11
+
12
+
data/bin/gpgshell ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gpgenv/shell_command'
3
+ begin
4
+ Gpgenv::ShellCommand.run
5
+ rescue StandardError => bang
6
+ raise if ENV['DEBUG'] == 'true'
7
+ puts bang.message
8
+ exit 1
9
+ end
10
+
11
+
12
+
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
@@ -7,11 +7,7 @@ module Gpgenv
7
7
  parameter "ARGUMENTS ...", "arguments", :attribute_name => :args
8
8
 
9
9
  def execute
10
- cmd = args.last
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 < Clamp::Command
5
- parameter 'DIRS ...', 'dirs', :attribute_name => :directories
6
+ class ExportCommand < Clamp::Command
6
7
 
7
- option '--file', 'FILE', 'env file to read from', :default => '.env'
8
+ option ['-f', '--force'], :flag, "Force overwrite of existing .env file"
8
9
 
9
- def full_dir
10
- if ENV['GPGENV_HOME']
11
- "#{ENV['GPGENV_HOME']}/#{dir}"
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
- def execute
18
- hash = Gpgenv.read_files(directories)
19
- str = ''
20
- hash.each do |k,v|
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 < Clamp::Command
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
- def full_dir
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
- IO.foreach(file) do |line|
20
- line = line.strip
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
- value = value[1..-2] if value[0] == '"' && value[-1] == '"'
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
@@ -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
- fail("You must specify at least one directory") unless directories.size >= 1
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
@@ -1,3 +1,3 @@
1
1
  module Gpgenv
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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
- # Prefix relative paths that don't exist with gpgenv_home directory, if it is set.
9
- if Config.gpgenv_home
10
- directories = directories.map do |d|
11
- if File.directory?(d)
12
- d
13
- else
14
- gpgenv_dir = "#{Config.gpgenv_home}/#{d}"
15
- if File.directory?(gpgenv_dir)
16
- gpgenv_dir
17
- else
18
- d
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
- # Validate existence of directories
25
- directories.each do |d|
26
- raise Error.new("#{d} does not exist.") unless File.exists?(d)
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
- hash = {}
31
- directories.each do |dir|
32
- Dir.glob("#{dir}/*").reject{|f| File.directory? f }.each do |f|
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
- hash
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.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-01-20 00:00:00.000000000 Z
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/config.rb
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/main_command.rb
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
@@ -1,7 +0,0 @@
1
- module Gpgenv
2
- module Config
3
- def self.gpgenv_home
4
- ENV['GPGENV_HOME']
5
- end
6
- end
7
- end
@@ -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