pw_provider 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d00025b3c176a7a3dfc7acca473b000ec4b94ba0
4
+ data.tar.gz: 546ccf1815042ca0add47dafdcd0ebd1986ad378
5
+ SHA512:
6
+ metadata.gz: fbf1cf90efc40b2af3dcce05040b20dd1460a0c819dac07ffbef187b36cc7bb794c44ff32f0402427e2b5465e16375a7e332d64ab26afaa4de7de2ae8e1f194e
7
+ data.tar.gz: a60bf721874fc6d24a8a578fcfcc25d201f2dabb828e74800a3fa68647cef9bca75d5fe130a74d4e9b4ceb52fb562f32b9eb1aec315246e2626296cb1c96806a
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rspec"
4
+ gem "inifile"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Zsolt Kecskemeti
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.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # pw_provider
2
+
3
+ A very simple password utility to pull passwords from different sources, currently supporting:
4
+ - environment variables (for backwards compatibility)
5
+ - Mac OSX KeyChain (more secure)
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'pw_provider'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install pw_provider
21
+
22
+ ## Usage
23
+
24
+ Configure the method you want to use:
25
+
26
+ $ cat ~/.pw_provider
27
+ [config]
28
+ pass_source=KeyChain
29
+
30
+ or
31
+
32
+ [config]
33
+ pass_source=Environment
34
+
35
+ It defaults to Environment when no config file is present.
36
+
37
+ In your code where you need a password:
38
+
39
+ PwProvider.get('account_name')
40
+
41
+ Example:
42
+
43
+ OpenSSL::PKey::RSA.new(cert_private_key, PwProvider.get('my_cert_pass_identifier'))
44
+
45
+
46
+
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/[my-github-username]/pw_provider/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #require 'rubygems'
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
data/bin/addpwd.rb ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pw_provider/keychain'
3
+ KeyChain.add_pw(ARGV[0], ARGV[1])
@@ -0,0 +1,22 @@
1
+ require 'inifile'
2
+
3
+ # reads .pw_provider from user home dir to decide
4
+ # where to read our passwords from:
5
+ # - keychain
6
+ # - environment variables
7
+ module Conf
8
+
9
+ def Conf.abs_path(dotfile)
10
+ dotfile =~ /^\// ? dotfile : File.join(Dir.home, dotfile)
11
+ end
12
+
13
+ def Conf.inifile(dotfile)
14
+ @inifile ||= IniFile.load(abs_path(dotfile))
15
+ end
16
+
17
+ # default to 'Environment'
18
+ def Conf.pass_source(dotfile: '.pw_provider')
19
+ inifile(dotfile) ? inifile(dotfile)['config']['pass_source'] : 'Environment'
20
+ end
21
+ end
22
+
@@ -0,0 +1,5 @@
1
+ class Environment
2
+ def self.get_pw(var)
3
+ ENV[var]
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # TODO use one of the available keychain gems for this
2
+
3
+ class KeyChain
4
+ def self.get_pw(account)
5
+ cmd = quiet_cmd("security find-generic-password -g -a " + account)
6
+ response = `#{cmd}`
7
+ response[/^password: "(.*)"$/, 1]
8
+ end
9
+
10
+ def self.add_pw(account, password)
11
+ cmd = quiet_cmd("security add-generic-password -a " + account + " -s " + account + " -w " + password)
12
+ `#{cmd}`
13
+ end
14
+
15
+ def self.del_pw(account)
16
+ cmd = quiet_cmd("security delete-generic-password -a " + account)
17
+ `#{cmd}`
18
+ end
19
+
20
+ def self.quiet_cmd(cmd)
21
+ cmd + ' 2>&1 >/dev/null'
22
+ end
23
+
24
+ end
@@ -0,0 +1,3 @@
1
+ module PwProvider
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'pw_provider/version'
2
+ require 'pw_provider/key_chain'
3
+ require 'pw_provider/conf'
4
+ require 'pw_provider/environment'
5
+
6
+ module PwProvider
7
+
8
+ def PwProvider.get(key)
9
+ eval(Conf.pass_source).get_pw(key)
10
+ end
11
+
12
+ end
13
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pw_provider/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pw_provider"
8
+ spec.version = PwProvider::VERSION
9
+ spec.authors = ["Zsolt Kecskemeti"]
10
+ spec.email = ["zsooo@zsooo.org"]
11
+ spec.summary = %q{Password provider}
12
+ spec.description = %q{Originally created for tests that require SSL certs with passphrases}
13
+ spec.homepage = "http://rubygems.org/gems/pw_provider"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ end
@@ -0,0 +1,56 @@
1
+ require 'pw_provider/conf'
2
+ require 'tempfile'
3
+ require 'securerandom'
4
+
5
+ RSpec.describe Conf do
6
+
7
+ before(:each) do
8
+ Object.send(:remove_const, 'Conf')
9
+ load 'pw_provider/conf.rb'
10
+ end
11
+
12
+ describe "#pass_source" do
13
+ it "returns the pass source from temp file" do
14
+ # given
15
+ dotfile = Tempfile.new('testconfig')
16
+ dotfile.puts '[config]'
17
+ dotfile.puts 'pass_source=t123'
18
+ dotfile.flush
19
+
20
+ # when then
21
+ expect(Conf.pass_source(dotfile: dotfile.path)).to eq('t123')
22
+
23
+ # teardown
24
+ dotfile.close
25
+ dotfile.unlink
26
+ end
27
+ end
28
+
29
+ describe "#pass_source" do
30
+ it "returns 'Environment' when file doesn't exist" do
31
+ # given
32
+ non_existent_file = '/file_not_here' + SecureRandom.uuid
33
+ # when then
34
+ expect(Conf.pass_source(dotfile: non_existent_file)).to eq('Environment')
35
+ end
36
+ end
37
+
38
+ describe "#abs_path" do
39
+ it "abs_path with absolute path" do
40
+ # given
41
+ dotfile = '/tmp/test1'
42
+ # when then
43
+ expect(Conf.abs_path(dotfile)).to eq(dotfile)
44
+ end
45
+ end
46
+
47
+ describe "#abs_path" do
48
+ it "abs_path with user dir" do
49
+ # given
50
+ dotfile = 'test2'
51
+ # when then
52
+ expect(Conf.abs_path(dotfile)).to eq(File.join(Dir.home, dotfile))
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,59 @@
1
+ require 'pw_provider/key_chain'
2
+
3
+ RSpec.describe KeyChain do
4
+
5
+ describe "#add_pw" do
6
+ it "creates a new password" do
7
+ # given
8
+ account = 'pw_provider-test'
9
+ pass = 'testpass'
10
+
11
+ # when
12
+ KeyChain.add_pw(account, pass)
13
+
14
+ # then
15
+ expect(KeyChain.get_pw(account)).to eq(pass)
16
+
17
+ # teardown
18
+ KeyChain.del_pw(account)
19
+ end
20
+ end
21
+
22
+
23
+
24
+ describe "#get_pw" do
25
+ it "gets the pass from the keychain" do
26
+ # given
27
+ account = 'pw_provider-test'
28
+ pass = 'testpass'
29
+ KeyChain.add_pw(account, pass)
30
+
31
+ # when
32
+ result = KeyChain.get_pw(account)
33
+
34
+ # then
35
+ expect(result).to eq(pass)
36
+
37
+ # teardown
38
+ KeyChain.del_pw(account)
39
+ end
40
+ end
41
+
42
+
43
+ describe "#del_pw" do
44
+ it "deletes the pass from the keychain" do
45
+ # given
46
+ account = 'pw_provider-test'
47
+ pass = 'testpass'
48
+ KeyChain.add_pw(account, pass)
49
+
50
+ # when
51
+ KeyChain.del_pw(account)
52
+
53
+ # then
54
+ empty = KeyChain.get_pw(account)
55
+ expect(empty).to eq(nil)
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,31 @@
1
+ require 'pw_provider'
2
+ require 'pw_provider/conf'
3
+
4
+ RSpec.describe PwProvider do
5
+
6
+ describe "#get" do
7
+ it "returns the pass from keychain" do
8
+ # given
9
+ account = 'testacc'
10
+ pass = 'testpass'
11
+ allow(PwProvider).to receive(:pass_source).and_return('KeyChain')
12
+ allow(KeyChain).to receive(:get_pw).with(account).and_return(pass)
13
+
14
+ # when then
15
+ expect(PwProvider.get(account)).to eq(pass)
16
+ end
17
+ end
18
+
19
+ describe "#get" do
20
+ it "returns the pass from the env" do
21
+ # given
22
+ account = 'testacc'
23
+ pass = 'testpass'
24
+ allow(Conf).to receive(:pass_source).and_return('Environment')
25
+ allow(Environment).to receive(:get_pw).with(account).and_return(pass)
26
+
27
+ # when then
28
+ expect(PwProvider.get(account)).to eq(pass)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'pw_provider'
5
+
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pw_provider
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zsolt Kecskemeti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-10 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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: '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'
55
+ description: Originally created for tests that require SSL certs with passphrases
56
+ email:
57
+ - zsooo@zsooo.org
58
+ executables:
59
+ - addpwd.rb
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/addpwd.rb
70
+ - lib/pw_provider.rb
71
+ - lib/pw_provider/conf.rb
72
+ - lib/pw_provider/environment.rb
73
+ - lib/pw_provider/key_chain.rb
74
+ - lib/pw_provider/version.rb
75
+ - pw_provider.gemspec
76
+ - spec/pw_provider/conf_spec.rb
77
+ - spec/pw_provider/key_chain_spec.rb
78
+ - spec/pw_provider_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: http://rubygems.org/gems/pw_provider
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.2.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Password provider
104
+ test_files:
105
+ - spec/pw_provider/conf_spec.rb
106
+ - spec/pw_provider/key_chain_spec.rb
107
+ - spec/pw_provider_spec.rb
108
+ - spec/spec_helper.rb