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 CHANGED
@@ -1,4 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in git-ssh-wrapper.gemspec
4
3
  gemspec
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
- GitSSHWrapper.new(:private_key => Pathname.new('id_rsa').read)
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 Temfiles when it is initialized. They will be cleaned at
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 'spec/rake/spectask'
5
- Spec::Rake::SpecTask.new(:spec) do |spec|
6
- spec.libs << 'lib' << 'spec'
7
- spec.spec_files = FileList['spec/**/*_spec.rb']
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
@@ -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.1"
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 "rspec"
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")
@@ -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
- @tempfiles = []
55
- @key_path = options[:private_key_path] || tempfile(options[:private_key])
56
- @ssh_config = ssh_config(@key_path)
57
- @path = script(@ssh_config)
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 git_ssh
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(config_path)
79
- tempfile(SCRIPT % config_path, EXEC_MODE)
80
- end
81
-
82
- def ssh_config(private_key_path)
83
- tempfile(SSH_CONFIG % private_key_path)
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
- lambda {
7
- Open4.spawn("#{@git_ssh_wrapper.git_ssh} git ls-remote git@github.com:martinemde/git-ssh-wrapper.git refs/heads/master", :stdout => '', :stderr => '')
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 { @git_ssh_wrapper.pathname.realpath }.should_not raise_error
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
- @git_ssh_wrapper.git_ssh.should == "GIT_SSH='#{@git_ssh_wrapper.path}'"
15
+ subject.git_ssh.should == "GIT_SSH='#{subject.path}'"
17
16
  end
18
17
 
19
18
  it "disappears when unlinked" do
20
- pathname = @git_ssh_wrapper.pathname
21
- @git_ssh_wrapper.unlink
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
- before { @git_ssh_wrapper = described_class.new(:private_key => private_key) }
28
- after { @git_ssh_wrapper.unlink }
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
- before { @git_ssh_wrapper = described_class.new(:private_key_path => private_key_path) }
34
- after { @git_ssh_wrapper.unlink }
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
- @git_ssh_wrapper.unlink
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
- lambda {
58
- Open4.spawn("#{wrapper.git_ssh} git ls-remote git@github.com:martinemde/git-ssh-wrapper.git refs/heads/master", :stdout => '', :stderr => '')
59
- }.should_not raise_error
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
 
@@ -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 'spec'
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
- Spec::Runner.configure do |config|
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
- hash: 29
5
- prerelease: false
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
- date: 2010-12-04 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rspec
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
- requirement: &id001 !ruby/object:Gem::Requirement
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
- hash: 3
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
- requirement: &id002 !ruby/object:Gem::Requirement
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
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
47
44
  type: :development
48
- version_requirements: *id002
49
- description: Generate a permissive GIT_SSH wrapper script using a private key string or file for use with git commands that need ssh.
50
- email:
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
- hash: 3
86
- segments:
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
87
79
  - 0
88
- version: "0"
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
- hash: 3
95
- segments:
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
96
88
  - 0
97
- version: "0"
89
+ hash: -3599100337838962590
98
90
  requirements: []
99
-
100
91
  rubyforge_project:
101
- rubygems_version: 1.3.7
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
@@ -1 +0,0 @@
1
- --color