gpgenv 0.1.0 → 0.1.1

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: 61dc67c1d292e3bc921f5f9b339242b837343618
4
- data.tar.gz: f7c17f198c57e38a52f82adacea4553ad2d8ea4f
3
+ metadata.gz: 017ba30f555fd557cc878944b5d0506b8b8d0ccf
4
+ data.tar.gz: 0f42e386012535c8a387b1fd31080dee5c717ce6
5
5
  SHA512:
6
- metadata.gz: bf9163ff53362c7a6b6516ae7ec0b8278632070bf665199e965839a286bda5e27c14ccb1019fac4ae25a5a1d4ff3e9e1a81674777b3ed79860edfb2bf99a9898
7
- data.tar.gz: c68b159231cab74e839b21de888e61294d9bc5c5d9e74b05b0010d0d4e92f00aea5fa54cf66d10ef896b7c5bf4785c124b342ad57ca9b0658f0ba09a46069435
6
+ metadata.gz: ab81c8a64d35121baea8cb225b7a4598cec12ce6a5e30da6b1adc6340dbc5f81da9f4bb3e1fac60c9afb6d5de9015d8fa6691d56fbb5f6637fa684fc5254d24a
7
+ data.tar.gz: 75ffe58628a24a6bf6a3bbd4386b475ec3ae5a3fc96315c3a665104203eaef8bdf8e9bca956b75891714c3a093011532c717de3e52868f8324a43e881c4b63fb
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .env
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
data/README.md CHANGED
@@ -17,13 +17,13 @@ Gpgenv plays very nicely with [pass](http://www.passwordstore.org/). For example
17
17
 
18
18
  ```bash
19
19
  # Set up a shortcut to your passwordstore home directory
20
- export GPGENV_HOME=$HOME/.password-store
20
+ export GPGENV_HOME=$HOME/.password-store/env
21
21
 
22
22
  # Insert your oauth token into your password store:
23
- pass insert myservice/OAUTH_TOKEN
23
+ pass insert env/myservice/OAUTH_TOKEN
24
24
 
25
25
  # Use gpgenv to spawn a bash session:
26
- gpgenv $GPGENV_HOME/myservice bash
26
+ gpgenv myservice bash
27
27
 
28
28
  # From the new bash session, use your oauth token to hit the service:
29
29
  curl https://$user:$OAUTH_TOKEN@myservice.com/get_some_data
@@ -34,8 +34,7 @@ As an admin, I am guilty of occasionally storing sensitive credentials on disk.
34
34
  extremely common. Your .netrc file probably contains all sorts of sensitive data, and even if you use a gpg-encrypted .netrc file, many tools
35
35
  simply don't understand gpg. Storing this stuff in plaintext is dangerous - but you do it anyway because the alternatives are just too painful.
36
36
 
37
- 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
38
- (tbh, that isn't its job). I wrote `gpgenv` to bridge that gap, and make it easy for me to never store sensitive information in an unencrypted format
37
+ 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
39
38
  on my own machine. I hope that you find it useful as well, and you use it to stop yourself from committing security sins.
40
39
 
41
40
  ## Installation
data/bin/gpgenv CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- require 'gpgenv/exec_command'
2
+ require 'gpgenv/main_command'
3
3
  begin
4
- Gpgenv::ExecCommand.new(ARGV).run
4
+ Gpgenv::MainCommand.run
5
5
  rescue StandardError => bang
6
6
  raise if ENV['DEBUG'] == 'true'
7
7
  puts bang.message
data/gpgenv.gemspec CHANGED
@@ -26,6 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
+ spec.add_dependency 'clamp'
30
+
29
31
  spec.add_development_dependency "bundler", "~> 1.9"
30
32
  spec.add_development_dependency "rake", "~> 10.0"
31
33
  spec.add_development_dependency "rspec"
@@ -1,18 +1,14 @@
1
+ require 'clamp'
1
2
  require 'gpgenv'
2
3
 
3
4
  module Gpgenv
4
- class ExecCommand
5
+ class ExecCommand < Clamp::Command
5
6
 
6
- attr_reader :args
7
+ parameter "ARGUMENTS ...", "arguments", :attribute_name => :args
7
8
 
8
- def initialize(args)
9
- @args = args
10
- end
11
-
12
- def run
13
- fail("Usage: gpgenv dir1 dir2 dir3 ... command") unless args.size >= 2
14
- directories = args[0..-2]
9
+ def execute
15
10
  cmd = args.last
11
+ directories = args[0..-2]
16
12
  hash = Gpgenv.read_files(directories)
17
13
  hash.each{ |k,v| ENV[k]=v }
18
14
  exec cmd
@@ -0,0 +1,27 @@
1
+ require 'clamp'
2
+
3
+ module Gpgenv
4
+ class ExportCommand < Clamp::Command
5
+ parameter 'DIRS ...', 'dirs', :attribute_name => :directories
6
+
7
+ option '--file', 'FILE', 'env file to read from', :default => '.env'
8
+
9
+ def full_dir
10
+ if ENV['GPGENV_HOME']
11
+ "#{ENV['GPGENV_HOME']}/#{dir}"
12
+ else
13
+ dir
14
+ end
15
+ end
16
+
17
+ def execute
18
+ hash = Gpgenv.read_files(directories)
19
+ str = ''
20
+ hash.each do |k,v|
21
+ str << "#{k}=#{v}\n"
22
+ end
23
+ File.write(file, str)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ require 'clamp'
2
+
3
+ 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
+
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
17
+
18
+ def execute
19
+ IO.foreach(file) do |line|
20
+ line = line.strip
21
+ i = line.index('=')
22
+ key=line[0..i-1]
23
+ 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}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,18 @@
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
@@ -1,18 +1,15 @@
1
1
  require 'gpgenv'
2
2
  require 'shellwords'
3
+ require 'clamp'
3
4
 
4
5
  module Gpgenv
5
- class ShellCommand
6
+ class ShellCommand < Clamp::Command
6
7
 
7
- attr_reader :args
8
+ parameter "DIRECTORIES ...", "directories", :attribute_name => :directories
8
9
 
9
- def initialize(args)
10
- @args = args
11
- end
12
-
13
- def run
14
- fail("Usage: gpgshell dir1 dir2 ...") unless args.size >= 1
15
- hash = Gpgenv.read_files(args)
10
+ def execute
11
+ fail("You must specify at least one directory") unless directories.size >= 1
12
+ hash = Gpgenv.read_files(directories)
16
13
  hash.each do |k, v|
17
14
  puts "export #{k}=#{Shellwords.escape(v)}"
18
15
  end
@@ -1,3 +1,3 @@
1
1
  module Gpgenv
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpgenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Shea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clamp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -71,7 +85,6 @@ email:
71
85
  - michael.shea@heroku.com
72
86
  executables:
73
87
  - gpgenv
74
- - gpgshell
75
88
  extensions: []
76
89
  extra_rdoc_files: []
77
90
  files:
@@ -83,12 +96,14 @@ files:
83
96
  - README.md
84
97
  - Rakefile
85
98
  - bin/gpgenv
86
- - bin/gpgshell
87
99
  - gpgenv.gemspec
88
100
  - lib/gpgenv.rb
89
101
  - lib/gpgenv/config.rb
90
102
  - lib/gpgenv/error.rb
91
103
  - lib/gpgenv/exec_command.rb
104
+ - lib/gpgenv/export_command.rb
105
+ - lib/gpgenv/import_command.rb
106
+ - lib/gpgenv/main_command.rb
92
107
  - lib/gpgenv/shell_command.rb
93
108
  - lib/gpgenv/version.rb
94
109
  homepage: https://github.com/heroku/gpgenv
data/bin/gpgshell DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'gpgenv/shell_command'
3
- begin
4
- Gpgenv::ShellCommand.new(ARGV).run
5
- rescue StandardError => bang
6
- raise if ENV['DEBUG'] == 'true'
7
- puts bang.message
8
- exit 1
9
- end