pairity 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: 86666c8a0bdbad0693fbab7b519e0b32fd75a37c
4
+ data.tar.gz: 1b3f5738d2404821e3770f7af23ef6cfcc36f558
5
+ !binary "U0hBNTEy":
6
+ metadata.gz: 5caefc8f154b8277f7cb1cbf315d0e20e3055322b9af2e9fdd2265c9d1d16f71e1372553d02ed2ae9936d512a539dd0983a98befb4c2034b1df57500ae6673f6
7
+ data.tar.gz: ef76c5e0b47fe35cf3ccdc42c738ac5c4c6fcba6b953910d9bdef7fdff03fff04dc552a32ec6d3cbd00b1350068ac9c2207b970689fb8b8ae7314add93763011
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pairity.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Derek Kastner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Pairity
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pairity'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pairity
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,107 @@
1
+ require "pairity/version"
2
+
3
+ class Pairity
4
+ class KeyNotConfigured < StandardError
5
+ attr_accessor :name
6
+
7
+ def initialize(name)
8
+ self.name = name
9
+ end
10
+
11
+ def message
12
+ "Could not find a file or env var for #{name}"
13
+ end
14
+ end
15
+
16
+ def self.home
17
+ ENV['HOME'] || '/tmp'
18
+ end
19
+
20
+ def self.root
21
+ @root ||= File.join(home, '.pairity')
22
+ end
23
+
24
+ def self.root=(path)
25
+ @root = path
26
+ end
27
+
28
+ def self.with_key_paths(*key_names, &blk)
29
+ keys = key_names.map { |name| new(name) }
30
+
31
+ paths = keys.map(&:path)
32
+
33
+ result = blk.call *paths
34
+
35
+ keys.map(&:unlink_temp_file)
36
+
37
+ result
38
+ end
39
+
40
+ def self.with_keys(*key_names, &blk)
41
+ keys = key_names.map { |name| new(name) }
42
+
43
+ contents = keys.map(&:content)
44
+
45
+ result = blk.call *contents
46
+
47
+ keys.map(&:unlink_temp_file)
48
+
49
+ result
50
+ end
51
+
52
+ attr_accessor :name
53
+
54
+ def initialize(name)
55
+ self.name = name.upcase
56
+ end
57
+
58
+ def friendly_name
59
+ name.downcase.gsub('_', '-')
60
+ end
61
+
62
+ def env
63
+ ENV[name]
64
+ end
65
+ def path_env
66
+ ENV["#{name}_PATH"]
67
+ end
68
+
69
+ def path
70
+ if File.exist?(default_path)
71
+ default_path
72
+ elsif path_env
73
+ path_env
74
+ elsif env
75
+ temp_path
76
+ else
77
+ raise KeyNotConfigured, name
78
+ end
79
+ end
80
+
81
+ def content
82
+ File.read path
83
+ end
84
+
85
+ def temp_path
86
+ temp_file.path
87
+ end
88
+
89
+ def temp_file
90
+ return @temp_file if @temp_file && File.exist?(@temp_file)
91
+
92
+ file = Tempfile.new 'temp-key'
93
+ file.write env
94
+ file.close
95
+ @temp_path = file
96
+ end
97
+
98
+ def default_path
99
+ File.join(self.class.root, "#{friendly_name}.key")
100
+ end
101
+
102
+ def unlink_temp_file
103
+ if path_env.nil? && env
104
+ temp_file.unlink
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,3 @@
1
+ class Pairity
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pairity/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pairity"
8
+ spec.version = Pairity::VERSION
9
+ spec.authors = ["Derek Kastner"]
10
+ spec.email = ["dkastner@gmail.com"]
11
+ spec.description = %q{Store key pairs (e.g. for SSH connections) in your ENV or in a file}
12
+ spec.summary = %q{Manage key pairs}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", '~> 2.14.1'
24
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+ require 'pairity'
4
+
5
+ describe Pairity do
6
+
7
+ describe '.with_key_paths' do
8
+
9
+ context 'with a static file' do
10
+
11
+ it 'yields a single path' do
12
+ Pairity.root = Dir.mktmpdir
13
+ key = File.open File.join(Pairity.root, 'secret-one.key'), 'w'
14
+ key.puts 'SECRET VALUE ONE'
15
+ key.close
16
+
17
+ Pairity.with_key_paths 'SECRET_ONE' do |path|
18
+ path.should == key.path
19
+ end
20
+ end
21
+
22
+ it 'yields multiple paths' do
23
+ Pairity.root = Dir.mktmpdir
24
+ key1 = File.open File.join(Pairity.root, 'secret-one.key'), 'w'
25
+ key1.puts 'SECRET VALUE ONE'
26
+ key1.close
27
+
28
+ key2 = File.open File.join(Pairity.root, 'secret-two.key'), 'w'
29
+ key2.puts 'SECRET VALUE TWO'
30
+ key2.close
31
+
32
+ Pairity.with_key_paths 'SECRET_ONE', 'SECRET_TWO' do |one, two|
33
+ one.should == key1.path
34
+ two.should == key2.path
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ context 'with an env value' do
41
+
42
+ it 'yields a single path' do
43
+ ENV['SINGLE_SECRET_ONE'] = 'SECRET VALUE ONE'
44
+
45
+ Pairity.with_key_paths 'SECRET_ONE' do |path|
46
+ File.read(path).should == "SECRET VALUE ONE\n"
47
+ end
48
+ end
49
+
50
+ it 'yields multiple paths' do
51
+ ENV['MULTIPLE_SECRET_ONE'] = 'MSECRET VALUE ONE'
52
+ ENV['MULTIPLE_SECRET_TWO'] = 'MSECRET VALUE TWO'
53
+
54
+ Pairity.with_key_paths 'multiple_secret_one', 'MULTIPLE_SECRET_TWO' do |one, two|
55
+ File.read(one).should == 'MSECRET VALUE ONE'
56
+ File.read(two).should == 'MSECRET VALUE TWO'
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ describe '.with_keys' do
65
+
66
+ context 'with a static file' do
67
+
68
+ it 'yields a single value' do
69
+ Pairity.root = Dir.mktmpdir
70
+ key = File.open File.join(Pairity.root, 'secret-one.key'), 'w'
71
+ key.puts 'SECRET VALUE ONE'
72
+ key.close
73
+
74
+ Pairity.with_keys 'SECRET_ONE' do |one|
75
+ one.should == "SECRET VALUE ONE\n"
76
+ end
77
+ end
78
+
79
+ it 'yields multiple paths' do
80
+ Pairity.root = Dir.mktmpdir
81
+ key1 = File.open File.join(Pairity.root, 'secret-one.key'), 'w'
82
+ key1.puts 'SECRET VALUE ONE'
83
+ key1.close
84
+
85
+ key2 = File.open File.join(Pairity.root, 'secret-two.key'), 'w'
86
+ key2.puts 'SECRET VALUE TWO'
87
+ key2.close
88
+
89
+ Pairity.with_key_paths 'SECRET_ONE', 'SECRET_TWO' do |one, two|
90
+ one.should == key1.path
91
+ two.should == key2.path
92
+ end
93
+ end
94
+
95
+ end
96
+
97
+ context 'with an env value' do
98
+
99
+ it 'yields a single path' do
100
+ ENV['SINGLE_SECRET_ONE'] = 'SECRET VALUE ONE'
101
+
102
+ Pairity.with_key_paths 'SINGLE_SECRET_ONE' do |path|
103
+ File.read(path).should == 'SECRET VALUE ONE'
104
+ end
105
+ end
106
+
107
+ it 'yields multiple paths' do
108
+ ENV['MULTIPLE_SECRET_ONE'] = 'MSECRET VALUE ONE'
109
+ ENV['MULTIPLE_SECRET_TWO'] = 'MSECRET VALUE TWO'
110
+
111
+ Pairity.with_key_paths 'multiple_secret_one', 'MULTIPLE_SECRET_TWO' do |one, two|
112
+ File.read(one).should == 'MSECRET VALUE ONE'
113
+ File.read(two).should == 'MSECRET VALUE TWO'
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+
@@ -0,0 +1,17 @@
1
+ require 'bundler/setup'
2
+
3
+ RSpec.configure do |config|
4
+ # ## Mock Framework
5
+ #
6
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
7
+ #
8
+ # config.mock_with :mocha
9
+ # config.mock_with :flexmock
10
+ # config.mock_with :rr
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = "random"
17
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pairity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Derek Kastner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ description: Store key pairs (e.g. for SSH connections) in your ENV or in a file
56
+ email:
57
+ - dkastner@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/pairity.rb
68
+ - lib/pairity/version.rb
69
+ - pairity.gemspec
70
+ - spec/pairity_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Manage key pairs
96
+ test_files:
97
+ - spec/pairity_spec.rb
98
+ - spec/spec_helper.rb
99
+ has_rdoc: