gitcredential 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +32 -0
- data/README.md +34 -0
- data/Rakefile +7 -0
- data/VERSION +1 -0
- data/gitcredential.gemspec +16 -0
- data/lib/gitcredential.rb +73 -0
- data/spec/gitcredential_spec.rb +68 -0
- data/spec/spec_helper.rb +12 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDY2YmFhZDg0YWI3OGQ1MWI0ZTg1YmE1YTUxMDAwOWJjMDY5YmNiMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDdhZmY5MjQ3NGE4OGU2NjliYmEyZDY3NjRlM2Q0OGY0MjliMDJkOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmZkZWQ3Y2I5MjBiYTNkNDU5M2Y2MjY0ODQwMTE5OWYyODE3NmRjOTkwMzQ0
|
10
|
+
YjBhOThiNTM5ZGMxNThmZjk2MDJhNTVkMTliZmY5ZDUzOTU2N2U0OTg0YzQ1
|
11
|
+
ZGZlMjExNGZmMGEzMGI5MjU5YzRhZGIxM2MzZjM4YzY1Zjg0OWE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MWFmNWJiYjQzYjM3ZWVlNWFjNDE0MDY5YTUxYjczZWZjMjBhMGM1NmIzNDk3
|
14
|
+
NzIwNmZkNDk2ZjlkYmRlMWZjNTY4ZTk2YzAyODZjMjRiZjE4Yjc2YWRjNTFk
|
15
|
+
NjQ3NzE1MDEzNGU3NTFkNmU0NDk4MjQ0YThiNjM0MzMwYjRiZjU=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gitcredential (0.0.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
excon (0.16.10)
|
11
|
+
highline (1.6.20)
|
12
|
+
rake (10.1.0)
|
13
|
+
rspec (2.14.1)
|
14
|
+
rspec-core (~> 2.14.0)
|
15
|
+
rspec-expectations (~> 2.14.0)
|
16
|
+
rspec-mocks (~> 2.14.0)
|
17
|
+
rspec-core (2.14.7)
|
18
|
+
rspec-expectations (2.14.4)
|
19
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
20
|
+
rspec-mocks (2.14.4)
|
21
|
+
woof_util (0.0.18)
|
22
|
+
excon (~> 0.16.10)
|
23
|
+
highline (~> 1.6.15)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
gitcredential!
|
30
|
+
rake
|
31
|
+
rspec
|
32
|
+
woof_util (~> 0.0.18)
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
`git credential` wrapper gem
|
2
|
+
============================
|
3
|
+
|
4
|
+
```
|
5
|
+
require "gitcredential"
|
6
|
+
|
7
|
+
user_data = { :proto => "https", :host => "heroku.com", :path => "/",
|
8
|
+
:user => "bovik" }
|
9
|
+
|
10
|
+
gc = Gitcredential.new :backend => :default
|
11
|
+
|
12
|
+
cred = gc.get user_data
|
13
|
+
cred # => nil
|
14
|
+
|
15
|
+
result = gc.set(user_data.merge(:password => "s3kr1+"))
|
16
|
+
result # => true
|
17
|
+
|
18
|
+
cred = gc.get user_data
|
19
|
+
cred # => "s3kr1+"
|
20
|
+
|
21
|
+
gc.set(user_data.merge(:password => "aW3s0m3"))
|
22
|
+
|
23
|
+
cred = gc.get user_data
|
24
|
+
cred # => "aW3s0m3"
|
25
|
+
|
26
|
+
result = gc.unset user_data
|
27
|
+
result # => true
|
28
|
+
|
29
|
+
cred = gc.get user_data
|
30
|
+
cred # => nil
|
31
|
+
|
32
|
+
result = gc.unset user_data
|
33
|
+
result # => false
|
34
|
+
```
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'find'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'gitcredential'
|
5
|
+
s.version = File.read("VERSION").chomp
|
6
|
+
s.summary = 'Ruby Wrapper for `git credential`'
|
7
|
+
s.description = "Shells out to git-credential's various backends for secure credential management"
|
8
|
+
s.authors = ["Tom Maher"]
|
9
|
+
s.email = "tmaher@pw0n.me"
|
10
|
+
s.license = "MIT"
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.homepage = "https://github.com/tmaher/gitcredential"
|
13
|
+
s.add_development_dependency "woof_util", "~> 0.0.18"
|
14
|
+
s.add_development_dependency "rake"
|
15
|
+
s.add_development_dependency "rspec"
|
16
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class Gitcredential
|
2
|
+
|
3
|
+
def self.default_backend
|
4
|
+
case RUBY_PLATFORM
|
5
|
+
when /-darwin[\d\.]+\z/
|
6
|
+
"osxkeychain"
|
7
|
+
when /win32/
|
8
|
+
"winstore"
|
9
|
+
else
|
10
|
+
"cache"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :backend
|
15
|
+
def initialize args = {}
|
16
|
+
@valid_backends = ["osxkeychain", "winstore", "cache", "store", "default"]
|
17
|
+
@search_dft = {:proto => "https", :path => "/"}
|
18
|
+
@backend = args[:backend] || Gitcredential.default_backend
|
19
|
+
|
20
|
+
raise Exception "no such backend" unless @valid_backends.include?(@backend)
|
21
|
+
end
|
22
|
+
|
23
|
+
def cmd
|
24
|
+
"git-credential-#{@backend}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_payload search_data={}
|
28
|
+
u = @search_dft.merge search_data
|
29
|
+
<<-__EOS
|
30
|
+
protocol=#{u[:proto]}
|
31
|
+
host=#{u[:host]}
|
32
|
+
path=#{u[:path]}
|
33
|
+
username=#{u[:user]}
|
34
|
+
__EOS
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_payload set_data={}
|
38
|
+
get_payload(set_data) + "password=#{set_data[:password]}\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
def get u
|
42
|
+
out = nil
|
43
|
+
IO.popen([cmd, 'get'], mode='r+') { |fd|
|
44
|
+
fd.write(get_payload u)
|
45
|
+
fd.close_write
|
46
|
+
out = fd.read
|
47
|
+
}
|
48
|
+
return nil if (out.nil? or out.empty?)
|
49
|
+
out.sub!(/^password=/, '').chomp
|
50
|
+
end
|
51
|
+
|
52
|
+
def set u
|
53
|
+
unset(u) unless get(u).nil?
|
54
|
+
IO.popen([cmd, 'store'], mode='r+') { |fd|
|
55
|
+
fd.write(set_payload u)
|
56
|
+
fd.close_write
|
57
|
+
}
|
58
|
+
raise "can't save pw for #{u[:user]}" if get(u).nil?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def unset u
|
63
|
+
return true if get(u).nil?
|
64
|
+
|
65
|
+
IO.popen([cmd, 'erase'], mode='r+') { |fd|
|
66
|
+
fd.write(get_payload u)
|
67
|
+
fd.close_write
|
68
|
+
}
|
69
|
+
|
70
|
+
raise "deletion error on #{u[:user]}" unless get(u).nil?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitcredential do
|
4
|
+
|
5
|
+
user_one = "user1_#{SecureRandom.hex 8}"
|
6
|
+
user_two = "user2_#{SecureRandom.hex 8}"
|
7
|
+
pw_one = "pw1_#{SecureRandom.hex 8}"
|
8
|
+
pw_two = "pw2_#{SecureRandom.hex 8}"
|
9
|
+
|
10
|
+
user_data = { :proto => "https",
|
11
|
+
:host => "gitcredential.example.rspec",
|
12
|
+
:path => "/",
|
13
|
+
:user => user_one }
|
14
|
+
|
15
|
+
it "uses the default backend" do
|
16
|
+
Gitcredential.new.backend.should eq Gitcredential.default_backend
|
17
|
+
end
|
18
|
+
|
19
|
+
it "only allows known backends" do
|
20
|
+
expect { Gitcredential.new(:backend => "necronomicon") }.to raise_exception
|
21
|
+
Gitcredential.new(:backend => "osxkeychain").backend.should eq "osxkeychain"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "doesn't find nonexistent users" do
|
25
|
+
gc = Gitcredential.new
|
26
|
+
gc.get(user_data).should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can save new user accounts" do
|
30
|
+
gc = Gitcredential.new
|
31
|
+
gc.set(user_data.merge(:password => pw_one)).should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can retrieve user accounts" do
|
35
|
+
gc = Gitcredential.new
|
36
|
+
gc.get(user_data).should eq pw_one
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can overwrite passwords" do
|
40
|
+
gc = Gitcredential.new
|
41
|
+
gc.set(user_data.merge(:password => pw_two))
|
42
|
+
gc.get(user_data).should eq pw_two
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can delete user accounts" do
|
46
|
+
gc = Gitcredential.new
|
47
|
+
gc.unset(user_data).should be_true
|
48
|
+
gc.get(user_data).should be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "can handle multiple accounts concurrently" do
|
52
|
+
gc = Gitcredential.new
|
53
|
+
gc.get(user_data).should be_nil
|
54
|
+
gc.set(user_data.merge(:password => pw_one)).should be_true
|
55
|
+
gc.set(user_data.merge(:user => user_two, :password => pw_two)).should be_true
|
56
|
+
gc.get(user_data).should eq pw_one
|
57
|
+
gc.get(user_data.merge(:user => user_two)).should eq pw_two
|
58
|
+
end
|
59
|
+
|
60
|
+
it "does cleanup" do
|
61
|
+
gc = Gitcredential.new
|
62
|
+
gc.unset(user_data)
|
63
|
+
gc.unset(user_data.merge(:user => user_two))
|
64
|
+
end
|
65
|
+
|
66
|
+
1
|
67
|
+
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitcredential
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Maher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: woof_util
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.18
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.18
|
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: Shells out to git-credential's various backends for secure credential
|
56
|
+
management
|
57
|
+
email: tmaher@pw0n.me
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- gitcredential.gemspec
|
68
|
+
- lib/gitcredential.rb
|
69
|
+
- spec/gitcredential_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
homepage: https://github.com/tmaher/gitcredential
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.7
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Ruby Wrapper for `git credential`
|
95
|
+
test_files: []
|