rubygems_over_ssh 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,78 @@
1
+ require 'net/ssh/gateway'
2
+ require 'uri'
3
+
4
+ module RubyGemsOverSSH
5
+ class << self
6
+ def open_tunnel(gateway, remote_port)
7
+ begin
8
+ try_port = 1025 + rand(60_000)
9
+ gateway.open("localhost", remote_port, try_port)
10
+ return try_port
11
+ rescue Errno::EADDRINUSE
12
+ retry
13
+ end
14
+ end
15
+
16
+ def init_tunnel(host, port)
17
+ local_port = nil
18
+ port ||= 80
19
+ key = host + ":" + port.to_s
20
+ @tunnels ||= {}
21
+ @tunnels[key] ||= begin
22
+ gateway = Net::SSH::Gateway.new(host, `whoami`.chomp)
23
+ local_port = open_tunnel(gateway, port)
24
+ puts "rubygemsoverssh: opened tunnel to #{key} (listening locally on #{local_port})"
25
+ {:gateway => gateway, :local_port => local_port}
26
+ end
27
+ @tunnels[key][:local_port]
28
+ end
29
+ end
30
+ end
31
+
32
+ if Object.const_defined?(:Bundler)
33
+ module Bundler
34
+ module Source
35
+ class Rubygems
36
+ alias :specs_without_ssh :specs
37
+
38
+ def specs(*args, &block)
39
+ preserve_remotes = @remotes
40
+ @remotes = @remotes.map { |r|
41
+ if r.scheme == "ssh+http"
42
+ local_port = RubyGemsOverSSH.init_tunnel(r.host, r.port)
43
+ URI.parse("http://localhost:#{local_port}/")
44
+ else
45
+ r
46
+ end
47
+ }
48
+ specs_without_ssh(*args, &block)
49
+ ensure
50
+ @remotes = preserve_remotes
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ begin
58
+ require 'rubygems/commands/inabox_command'
59
+ rescue
60
+ end
61
+
62
+ if Gem::Commands.const_defined?(:InaboxCommand)
63
+ class Gem::Commands::InaboxCommand < Gem::Command
64
+ alias_method :geminabox_host_without_tunnel, :geminabox_host
65
+
66
+ def geminabox_host
67
+ host = geminabox_host_without_tunnel
68
+ uri = URI.parse(host)
69
+ if uri.scheme == "ssh+http"
70
+ puts uri.inspect
71
+ puts uri.port
72
+ local_port = RubyGemsOverSSH.init_tunnel(uri.host, uri.port)
73
+ host = "http://localhost:#{local_port}/"
74
+ end
75
+ host
76
+ end
77
+ end
78
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path("rubygems_over_ssh", File.dirname(__FILE__))
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems_over_ssh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Osheroff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: net-ssh-gateway
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ''
31
+ email:
32
+ - ben@gimbo.net
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/rubygems_over_ssh.rb
38
+ - lib/rubygems_plugin.rb
39
+ homepage: ''
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 1.3.6
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.24
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: leverage your pub-key architecture with a private gem host
63
+ test_files: []