Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-shell
Commits
02f4cb52
Commit
02f4cb52
authored
Feb 05, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gitlab net
parent
43bdc5da
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
13 deletions
+47
-13
lib/gitlab_net.rb
lib/gitlab_net.rb
+32
-0
lib/gitlab_shell.rb
lib/gitlab_shell.rb
+12
-10
spec/gitlab_shell_spec.rb
spec/gitlab_shell_spec.rb
+3
-3
No files found.
lib/gitlab_net.rb
0 → 100644
View file @
02f4cb52
require
'net/http'
require
'json'
class
GitlabNet
def
allowed?
(
cmd
,
repo
,
key
,
ref
)
project_name
=
repo
.
gsub
(
"'"
,
""
)
project_name
=
project_name
.
gsub
(
/\.git$/
,
""
)
key_id
=
key
.
gsub
(
"key-"
,
""
)
url
=
"
#{
host
}
/allowed?project=
#{
project_name
}
&key_id=
#{
key_id
}
&action=
#{
cmd
}
&ref=
#{
ref
}
"
resp
=
get
(
url
)
!!
(
resp
.
code
==
'200'
&&
resp
.
body
==
'true'
)
end
def
discover
(
key
)
key_id
=
key
.
gsub
(
"key-"
,
""
)
resp
=
get
(
"
#{
host
}
/discover?key_id=
#{
key_id
}
"
)
JSON
.
parse
(
resp
.
body
)
end
protected
def
host
"http://127.0.0.1:3000/api/v3/internal"
end
def
get
(
url
)
Net
::
HTTP
.
get_response
(
URI
.
parse
(
url
))
end
end
lib/gitlab_shell.rb
View file @
02f4cb52
require
'open3'
require
'net/http'
require_relative
'gitlab_config'
require_relative
'gitlab_net'
class
GitlabShell
attr_accessor
:
username
,
:repo_name
,
:git_cmd
,
:repos_path
,
:repo_name
attr_accessor
:
key_id
,
:repo_name
,
:git_cmd
,
:repos_path
,
:repo_name
def
initialize
@
username
=
ARGV
.
shift
@
key_id
=
ARGV
.
shift
@origin_cmd
=
ENV
[
'SSH_ORIGINAL_COMMAND'
]
@repos_path
=
GitlabConfig
.
new
.
repos_path
end
...
...
@@ -17,7 +17,7 @@ class GitlabShell
parse_cmd
if
git_cmds
.
include?
(
@git_cmd
)
ENV
[
'GL_USER'
]
=
@
username
ENV
[
'GL_USER'
]
=
@
key_id
if
validate_access
process_cmd
...
...
@@ -26,7 +26,8 @@ class GitlabShell
puts
'Not allowed command'
end
else
puts
"Welcome
#{
@username
}
!"
user
=
api
.
discover
(
@key_id
)
puts
"Welcome to GitLab,
#{
user
[
'name'
]
}
!"
end
end
...
...
@@ -49,10 +50,11 @@ class GitlabShell
def
validate_access
@ref_name
=
'master'
# just hardcode it cause we dont know ref
project_name
=
@repo_name
.
gsub
(
"'"
,
""
)
project_name
=
project_name
.
gsub
(
/\.git$/
,
""
)
url
=
"http://127.0.0.1:3000/api/v3/allowed?project=
#{
project_name
}
&username=
#{
@username
}
&action=
#{
@git_cmd
}
&ref=
#{
@ref_name
}
"
resp
=
Net
::
HTTP
.
get_response
(
URI
.
parse
(
url
))
resp
.
code
==
'200'
&&
resp
.
body
==
'true'
api
.
allowed?
(
@git_cmd
,
@repo_name
,
@key_id
,
@ref_name
)
end
def
api
GitlabNet
.
new
end
end
spec/gitlab_shell_spec.rb
View file @
02f4cb52
...
...
@@ -5,11 +5,11 @@ describe GitlabShell do
describe
:initialize
do
before
do
ssh_cmd
'git-receive-pack'
ARGV
[
0
]
=
'
dzaporozhets
'
ARGV
[
0
]
=
'
key-56
'
@shell
=
GitlabShell
.
new
end
it
{
@shell
.
username
.
should
==
'dzaporozhets
'
}
it
{
@shell
.
key_id
.
should
==
'key-56
'
}
it
{
@shell
.
repos_path
.
should
==
"/home/git/repositories"
}
end
...
...
@@ -62,7 +62,7 @@ describe GitlabShell do
end
def
stubbed_shell
ARGV
[
0
]
=
'
dzaporozhets
'
ARGV
[
0
]
=
'
key-56
'
@shell
=
GitlabShell
.
new
@shell
.
stub
(
validate_access:
true
)
@shell
.
stub
(
process_cmd:
true
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment