ssh2http 0.0.1 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d974d8dc9bc699f7f9901a2ea7acb03598408bd2
4
- data.tar.gz: 21ca41ff81d373212eb1620dd01695cde286036c
3
+ metadata.gz: 17fc1afd739112cabb7957e881d29b21408f7191
4
+ data.tar.gz: 01e0ab012312aeb86404b46c30748f58162a0493
5
5
  SHA512:
6
- metadata.gz: 22a8012570674b907b4d751cc6d4d2fee0fc0a075ceb620bcbd2b9b1a526c782bf41ab1000ac7d37bd89b864d411f6cd25aaa27e909daecc1569ec1a05cff162
7
- data.tar.gz: 9b17fafe3cbdaf6e7cf01b68b9ad4a7a096e8dd07b03dd815c777c104dcee53894d939d8ddca3f79dae89bebe7f378abb5f1c216655eb7aea2ea114d8b804e7b
6
+ metadata.gz: a60bbd9c36b042b01cf35b0cf8ff980bc9b3eca6be29f4a6a258b0320d2d7cd5bab52c43e9853017d977afd098c583d9ecdbab44bdcf995ea594f603273aafc0
7
+ data.tar.gz: 2375843fc2e7e0aa5460639333729caecd8369cb9fd8919334f0ed9f502f60dc15bb9365dd9649040a43add4e559547616c9a939ef03f5ab989ab26426868ee9
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
4
  - 2.3.0
4
- before_install: gem install bundler -v 1.11.2
5
+
6
+ before_install:
7
+ - gem install bundler -v 1.11.2
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ssh2http.gemspec
4
4
  gemspec
5
+
6
+ gem 'codecov', :require => false, :group => :test
7
+ gem 'pry'
data/README.md CHANGED
@@ -10,12 +10,38 @@ which delegates git pull/push requests to a git http backend.
10
10
  [![](http://inch-ci.org/github/pmq20/ssh2http.svg?branch=master)](http://inch-ci.org/github/pmq20/ssh2http?branch=master)
11
11
 
12
12
 
13
- ## installation
13
+ ## Installation
14
14
 
15
- gem install ssh2http
15
+ Add this line to your application's Gemfile:
16
16
 
17
- ## usage
17
+ ```ruby
18
+ gem 'ssh2http'
19
+ ```
18
20
 
19
- 'chsh' -s $(command -v ssh2http) <user>
20
- 'git clone' <user>`@localhost:/path/to/repo.git`
21
- 'ssh' <user>`@localhost`
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install ssh2http
28
+
29
+ ## Usage
30
+
31
+ Add this line to your ~<user>/.ssh/authorized_keys:
32
+
33
+ command="source $HOME/.profile && cd <your_project_path> && bundle exec ssh2http <HTTP destination>",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty <your_pub_key>
34
+
35
+ Or if you prefer to install the gem globally:
36
+
37
+ command="source $HOME/.profile && ssh2http <HTTP destination>",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty <your_pub_key>
38
+
39
+ For example,
40
+
41
+ command="source $HOME/.profile && cd /Users/pmq20/ssh2http && bundle exec ssh2http http://localhost",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa XXXXXXXXXXXXXXXXXXXX pmq2001@gmail.com
42
+
43
+ Then:
44
+
45
+ git clone pmq20@localhost:/path/to/repo.git
46
+
47
+ and the request will be delegated to `http://localhost/path/to/repo.git`.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ssh2http'
6
+
7
+ Ssh2http.die "Only ssh allowed." unless ENV['SSH_CONNECTION']
8
+ Ssh2http.die "Please provide a destination url." unless ARGV[0] && ARGV[0].length > 0
9
+
10
+ Ssh2http.new(ARGV[0], *ENV['SSH_ORIGINAL_COMMAND'].to_s.split).run!
11
+ exit 0
@@ -1,12 +1,110 @@
1
+ require 'open-uri'
1
2
  require "ssh2http/version"
2
3
 
3
- module Ssh2http
4
- def self.exec(origin_cmd)
5
- unless origin_cmd
6
- puts "Welcome to ssh2http!"
7
- return true
4
+ class Ssh2http
5
+ def initialize(destination, *cmds)
6
+ @destination = destination
7
+ @cmds = cmds
8
+ end
9
+
10
+ def run!
11
+ case cmd
12
+ when 'git-upload-pack'
13
+ upload!
14
+ when 'git-receive-pack'
15
+ receive!
16
+ else
17
+ die 'Unknown command'
18
+ end
19
+ end
20
+
21
+ def upload!
22
+ open(url('/info/refs?service=git-upload-pack')) do |f|
23
+ f.each_line do |line|
24
+ if "001e# service=git-upload-pack\n" == line
25
+ f.read(4) # skip "0000"
26
+ next
27
+ end
28
+ print line
29
+ end
30
+ end
31
+ STDOUT.flush
32
+
33
+ input = ''
34
+ while line = STDIN.gets
35
+ input += line
36
+ break if line =~ /0009done\n$/
37
+ end
38
+
39
+ url = URI.parse(url('/git-upload-pack'))
40
+ Net::HTTP.start(url.host, url.port) do |http|
41
+ request = Net::HTTP::Post.new url.path
42
+ request.body = input
43
+ request['Content-Type'] = 'application/x-git-upload-pack-request'
44
+ http.request request do |response|
45
+ response.read_body do |chunk|
46
+ STDOUT.write chunk
47
+ STDOUT.flush
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def receive!
54
+ open(url('/info/refs?service=git-receive-pack')) do |f|
55
+ f.each_line do |line|
56
+ if "001f# service=git-receive-pack\n" == line
57
+ f.read(4) # skip "0000"
58
+ next
59
+ end
60
+ print line
61
+ end
62
+ end
63
+ STDOUT.flush
64
+
65
+ input = STDIN.read
66
+ url = URI.parse(url('/git-receive-pack'))
67
+ http = Net::HTTP.new(url.host, url.port)
68
+ request = Net::HTTP::Post.new(url.path)
69
+ request.body = input
70
+ request['Content-Type'] = 'application/x-git-receive-pack-request'
71
+ response = http.request(request)
72
+ print response.body
73
+ STDOUT.flush
74
+ end
75
+
76
+ def cmd
77
+ @cmds[0]
78
+ end
79
+
80
+ def key
81
+ @cmds[1].gsub(/['"]/, '')
82
+ end
83
+
84
+ def url(part)
85
+ "#{@destination}#{key}#{part}"
86
+ end
87
+
88
+ def debug
89
+ var('@cmds')
90
+ var('@destination')
91
+ var('RUBY_VERSION')
92
+ var('::Ssh2http::VERSION')
93
+ ENV.each do |k,v|
94
+ var("ENV[#{k.inspect}]")
8
95
  end
9
- # Your code goes here...
10
- true
96
+ end
97
+
98
+ def var(var)
99
+ STDERR.puts "#{var}=#{eval(var).inspect}"
100
+ end
101
+
102
+ def die(msg)
103
+ self.class.die("#{@destination} #{@cmds} #{msg}")
104
+ end
105
+
106
+ def self.die(msg)
107
+ STDERR.puts msg
108
+ exit 1
11
109
  end
12
110
  end
@@ -1,3 +1,3 @@
1
- module Ssh2http
2
- VERSION = "0.0.1"
1
+ class Ssh2http
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssh2http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - P.S.V.R
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,7 +56,8 @@ description: A restricted login shell for Git-only SSH access, which delegates g
56
56
  pull/push requests to a git http backend.
57
57
  email:
58
58
  - pmq2001@gmail.com
59
- executables: []
59
+ executables:
60
+ - ssh2http
60
61
  extensions: []
61
62
  extra_rdoc_files: []
62
63
  files:
@@ -67,6 +68,7 @@ files:
67
68
  - LICENSE
68
69
  - README.md
69
70
  - Rakefile
71
+ - exe/ssh2http
70
72
  - lib/ssh2http.rb
71
73
  - lib/ssh2http/version.rb
72
74
  - ssh2http.gemspec
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  version: '0'
91
93
  requirements: []
92
94
  rubyforge_project:
93
- rubygems_version: 2.5.1
95
+ rubygems_version: 2.6.3
94
96
  signing_key:
95
97
  specification_version: 4
96
98
  summary: delegating git ssh requests to git http backends