git-ssh-wrapper 0.0.1 → 0.1.0
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.
- data/Gemfile +0 -1
- data/README.md +12 -3
- data/Rakefile +4 -5
- data/git-ssh-wrapper.gemspec +3 -2
- data/lib/git-ssh-wrapper.rb +12 -26
- data/spec/git_ssh_wrapper_spec.rb +23 -15
- data/spec/spec_helper.rb +2 -2
- metadata +55 -65
- data/spec/spec.opts +0 -1
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ can be used to connect git to protected git@github.com repositories.
|
|
6
6
|
## Example
|
7
7
|
|
8
8
|
def get_refs
|
9
|
-
wrapper = GitSSHWrapper.new(:private_key_path => '~/.ssh/id_rsa')
|
9
|
+
wrapper = GitSSHWrapper.new(:private_key_path => '~/.ssh/id_rsa', :log_level => 'ERROR')
|
10
10
|
`env #{wrapper.git_ssh} git ls-remote git@github.com:martinemde/git-ssh-wrapper.git`
|
11
11
|
ensure
|
12
12
|
wrapper.unlink
|
@@ -14,7 +14,16 @@ can be used to connect git to protected git@github.com repositories.
|
|
14
14
|
|
15
15
|
OR
|
16
16
|
|
17
|
-
|
17
|
+
# :log_level default in 'INFO'
|
18
|
+
def get_refs
|
19
|
+
GitSSHWrapper.new(:private_key_path => '~/.ssh/id_rsa') do |wrapper|
|
20
|
+
`env #{wrapper.cmd_prefix} git ls-remote git@github.com:martinemde/git-ssh-wrapper.git`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
OR
|
25
|
+
|
26
|
+
wrapper = GitSSHWrapper.new(:private_key => Pathname.new('id_rsa').read)
|
18
27
|
|
19
|
-
The wrapper creates
|
28
|
+
The wrapper creates Tempfiles when it is initialized. They will be cleaned at
|
20
29
|
program exit, or you can unlink them by calling #unlink like the example above.
|
data/Rakefile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new do |t|
|
6
|
+
t.rspec_opts = %w[--color]
|
7
|
+
t.pattern = 'spec/**/*_spec.rb'
|
8
8
|
end
|
9
|
-
|
10
9
|
task :default => :spec
|
data/git-ssh-wrapper.gemspec
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = "git-ssh-wrapper"
|
4
|
-
s.version = "0.0
|
4
|
+
s.version = "0.1.0"
|
5
5
|
s.authors = ["Martin Emde"]
|
6
6
|
s.email = ["martin.emde@gmail.com"]
|
7
7
|
s.homepage = "http://github.org/martinemde/git-ssh-wrapper"
|
8
8
|
s.summary = %q{Generate a permissive GIT_SSH wrapper script on the fly}
|
9
9
|
s.description = %q{Generate a permissive GIT_SSH wrapper script using a private key string or file for use with git commands that need ssh.}
|
10
10
|
|
11
|
-
s.add_development_dependency "
|
11
|
+
s.add_development_dependency "rake"
|
12
|
+
s.add_development_dependency "rspec", '~> 2.0'
|
12
13
|
s.add_development_dependency "open4"
|
13
14
|
|
14
15
|
s.files = `git ls-files`.split("\n")
|
data/lib/git-ssh-wrapper.rb
CHANGED
@@ -12,21 +12,6 @@ class GitSSHWrapper
|
|
12
12
|
SAFE_MODE = 0600
|
13
13
|
EXEC_MODE = 0700
|
14
14
|
|
15
|
-
SSH_CONFIG = <<-CONFIG
|
16
|
-
Host *
|
17
|
-
PasswordAuthentication no
|
18
|
-
StrictHostKeyChecking no
|
19
|
-
RSAAuthentication yes
|
20
|
-
ConnectTimeout 5
|
21
|
-
IdentityFile %s
|
22
|
-
CheckHostIP no
|
23
|
-
CONFIG
|
24
|
-
|
25
|
-
SCRIPT = <<-SCRIPT
|
26
|
-
#!/bin/bash
|
27
|
-
unset SSH_AUTH_SOCK
|
28
|
-
ssh -F %s $*
|
29
|
-
SCRIPT
|
30
15
|
|
31
16
|
def self.tempfile(content, mode=SAFE_MODE)
|
32
17
|
file = Tempfile.new("git-ssh-wrapper")
|
@@ -51,19 +36,20 @@ ssh -F %s $*
|
|
51
36
|
raise PrivateKeyRequired
|
52
37
|
end
|
53
38
|
|
54
|
-
|
55
|
-
@
|
56
|
-
|
57
|
-
@path
|
39
|
+
log_level = (options[:log_level] || 'INFO').upcase
|
40
|
+
@tempfiles = []
|
41
|
+
key_path = options[:private_key_path] || tempfile(options[:private_key])
|
42
|
+
@path = script(key_path, log_level)
|
58
43
|
end
|
59
44
|
|
60
45
|
def pathname
|
61
46
|
Pathname.new(path)
|
62
47
|
end
|
63
48
|
|
64
|
-
def
|
49
|
+
def cmd_prefix
|
65
50
|
"GIT_SSH='#{path}'"
|
66
51
|
end
|
52
|
+
alias git_ssh cmd_prefix
|
67
53
|
|
68
54
|
def set_env
|
69
55
|
ENV['GIT_SSH'] = path
|
@@ -75,12 +61,12 @@ ssh -F %s $*
|
|
75
61
|
|
76
62
|
private
|
77
63
|
|
78
|
-
def script(
|
79
|
-
tempfile(SCRIPT
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
64
|
+
def script(private_key_path, log_level)
|
65
|
+
tempfile(<<-SCRIPT, EXEC_MODE)
|
66
|
+
#!/bin/sh
|
67
|
+
unset SSH_AUTH_SOCK
|
68
|
+
ssh -o 'CheckHostIP no' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'LogLevel #{log_level}' -o 'IdentityFile #{private_key_path}' -o 'IdentitiesOnly yes' -o 'UserKnownHostsFile /dev/null' $*
|
69
|
+
SCRIPT
|
84
70
|
end
|
85
71
|
|
86
72
|
def tempfile(content, mode=SAFE_MODE)
|
@@ -3,41 +3,40 @@ require 'spec_helper'
|
|
3
3
|
describe GitSSHWrapper do
|
4
4
|
shared_examples_for "a GIT_SSH wrapper" do
|
5
5
|
it "allows access to secure github repositories" do
|
6
|
-
|
7
|
-
|
8
|
-
}.should_not raise_error
|
6
|
+
`#{subject.cmd_prefix} git ls-remote git@github.com:martinemde/git-ssh-wrapper.git refs/heads/master 2>&1`
|
7
|
+
$?.should be_true
|
9
8
|
end
|
10
9
|
|
11
10
|
it "has a script path that really exists" do
|
12
|
-
lambda {
|
11
|
+
lambda { subject.pathname.realpath }.should_not raise_error
|
13
12
|
end
|
14
13
|
|
15
14
|
it "formats a string with the GIT_SSH= in front of the script" do
|
16
|
-
|
15
|
+
subject.git_ssh.should == "GIT_SSH='#{subject.path}'"
|
17
16
|
end
|
18
17
|
|
19
18
|
it "disappears when unlinked" do
|
20
|
-
pathname =
|
21
|
-
|
19
|
+
pathname = subject.pathname
|
20
|
+
subject.unlink
|
22
21
|
pathname.should_not be_exist # ;_; syntax h8
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
25
|
context "with a key string" do
|
27
|
-
|
28
|
-
after {
|
26
|
+
subject { described_class.new(:private_key => private_key) }
|
27
|
+
after { subject.unlink }
|
29
28
|
it_should_behave_like "a GIT_SSH wrapper"
|
30
29
|
end
|
31
30
|
|
32
31
|
context "with a key file" do
|
33
|
-
|
34
|
-
after {
|
32
|
+
subject { described_class.new(:private_key_path => private_key_path) }
|
33
|
+
after { subject.unlink }
|
35
34
|
it_should_behave_like "a GIT_SSH wrapper"
|
36
35
|
|
37
36
|
it "should not delete the keyfile when unlinked" do
|
38
37
|
pathname = Pathname.new(private_key_path)
|
39
38
|
pathname.should be_exist
|
40
|
-
|
39
|
+
subject.unlink
|
41
40
|
pathname.should be_exist
|
42
41
|
end
|
43
42
|
end
|
@@ -54,9 +53,18 @@ describe GitSSHWrapper do
|
|
54
53
|
context "#with_git_ssh" do
|
55
54
|
it "allows access to secure github repositories" do
|
56
55
|
GitSSHWrapper.with_wrapper(:private_key => private_key) do |wrapper|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
`#{wrapper.git_ssh} git ls-remote git@github.com:martinemde/git-ssh-wrapper.git refs/heads/master 2>&1`
|
57
|
+
$?.should be_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "allows less noisy ssh" do
|
62
|
+
GitSSHWrapper.with_wrapper(:private_key => private_key, :log_level => "info") do |wrapper|
|
63
|
+
`#{wrapper.git_ssh} git ls-remote git@github.com:martinemde/git-ssh-wrapper.git refs/heads/master 2>&1`.should include("Warning: Permanently added 'github.com' (RSA) to the list of known hosts.")
|
64
|
+
end
|
65
|
+
|
66
|
+
GitSSHWrapper.with_wrapper(:private_key => private_key, :log_level => "error") do |wrapper|
|
67
|
+
`#{wrapper.git_ssh} git ls-remote git@github.com:martinemde/git-ssh-wrapper.git refs/heads/master 2>&1`.should_not include("Warning: Permanently added 'github.com' (RSA) to the list of known hosts.")
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,7 @@ end
|
|
7
7
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
8
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
9
|
require 'git-ssh-wrapper'
|
10
|
-
require '
|
10
|
+
require 'rspec'
|
11
11
|
require 'open4'
|
12
12
|
|
13
13
|
module TestPrivateKey
|
@@ -20,6 +20,6 @@ module TestPrivateKey
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
RSpec.configure do |config|
|
24
24
|
config.include TestPrivateKey
|
25
25
|
end
|
metadata
CHANGED
@@ -1,61 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-ssh-wrapper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Martin Emde
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
date: 2012-02-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70113546137280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
version_requirements: *70113546137280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70113546135600 !ruby/object:Gem::Requirement
|
25
28
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
33
|
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: open4
|
37
34
|
prerelease: false
|
38
|
-
|
35
|
+
version_requirements: *70113546135600
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: open4
|
38
|
+
requirement: &70113546148800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
47
44
|
type: :development
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70113546148800
|
47
|
+
description: Generate a permissive GIT_SSH wrapper script using a private key string
|
48
|
+
or file for use with git commands that need ssh.
|
49
|
+
email:
|
51
50
|
- martin.emde@gmail.com
|
52
51
|
executables: []
|
53
|
-
|
54
52
|
extensions: []
|
55
|
-
|
56
53
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
files:
|
54
|
+
files:
|
59
55
|
- .gitignore
|
60
56
|
- Gemfile
|
61
57
|
- LICENSE
|
@@ -64,47 +60,41 @@ files:
|
|
64
60
|
- git-ssh-wrapper.gemspec
|
65
61
|
- lib/git-ssh-wrapper.rb
|
66
62
|
- spec/git_ssh_wrapper_spec.rb
|
67
|
-
- spec/spec.opts
|
68
63
|
- spec/spec_helper.rb
|
69
64
|
- spec/test_key
|
70
65
|
- spec/test_key.pub
|
71
|
-
has_rdoc: true
|
72
66
|
homepage: http://github.org/martinemde/git-ssh-wrapper
|
73
67
|
licenses: []
|
74
|
-
|
75
68
|
post_install_message:
|
76
69
|
rdoc_options: []
|
77
|
-
|
78
|
-
require_paths:
|
70
|
+
require_paths:
|
79
71
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
73
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
segments:
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
segments:
|
87
79
|
- 0
|
88
|
-
|
89
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
hash: -3599100337838962590
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
82
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
|
95
|
-
segments:
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
segments:
|
96
88
|
- 0
|
97
|
-
|
89
|
+
hash: -3599100337838962590
|
98
90
|
requirements: []
|
99
|
-
|
100
91
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 1.8.15
|
102
93
|
signing_key:
|
103
94
|
specification_version: 3
|
104
95
|
summary: Generate a permissive GIT_SSH wrapper script on the fly
|
105
|
-
test_files:
|
96
|
+
test_files:
|
106
97
|
- spec/git_ssh_wrapper_spec.rb
|
107
|
-
- spec/spec.opts
|
108
98
|
- spec/spec_helper.rb
|
109
99
|
- spec/test_key
|
110
100
|
- spec/test_key.pub
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|