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
f548511c
Commit
f548511c
authored
Mar 20, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'improve-git-update' into 'master'
Improve Git Update
parents
e294b344
84c5f49d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
21 deletions
+23
-21
lib/gitlab_net.rb
lib/gitlab_net.rb
+16
-3
lib/gitlab_update.rb
lib/gitlab_update.rb
+7
-18
No files found.
lib/gitlab_net.rb
View file @
f548511c
...
...
@@ -6,14 +6,27 @@ require_relative 'gitlab_config'
require_relative
'gitlab_logger'
class
GitlabNet
def
allowed?
(
cmd
,
repo
,
key
,
ref
)
def
allowed?
(
cmd
,
repo
,
actor
,
ref
,
oldrev
=
nil
,
newrev
=
nil
)
project_name
=
repo
.
gsub
(
"'"
,
""
)
project_name
=
project_name
.
gsub
(
/\.git\Z/
,
""
)
project_name
=
project_name
.
gsub
(
/\A\//
,
""
)
key_id
=
key
.
gsub
(
"key-"
,
""
)
params
=
{
action:
cmd
,
ref:
ref
,
project:
project_name
,
}
params
.
merge!
(
oldrev:
oldrev
)
if
oldrev
params
.
merge!
(
newrev:
newrev
)
if
newrev
if
actor
=~
/\Akey\-\d+\Z/
params
.
merge!
(
key_id:
actor
.
gsub
(
"key-"
,
""
))
elsif
actor
=~
/\Auser\-\d+\Z/
params
.
merge!
(
user_id:
actor
.
gsub
(
"user-"
,
""
))
end
url
=
"
#{
host
}
/allowed?
key_id=
#{
key_id
}
&action=
#{
cmd
}
&ref=
#{
ref
}
&project=
#{
project_name
}
"
url
=
"
#{
host
}
/allowed?
"
+
URI
.
encode_www_form
(
params
)
resp
=
get
(
url
)
!!
(
resp
.
code
==
'200'
&&
resp
.
body
==
'true'
)
...
...
lib/gitlab_update.rb
View file @
f548511c
...
...
@@ -5,7 +5,7 @@ require 'json'
class
GitlabUpdate
attr_reader
:config
def
initialize
(
repo_path
,
key_id
,
refname
)
def
initialize
(
repo_path
,
actor
,
refname
)
@config
=
GitlabConfig
.
new
@repo_path
=
repo_path
.
strip
...
...
@@ -14,7 +14,7 @@ class GitlabUpdate
@repo_name
.
gsub!
(
/\.git$/
,
""
)
@repo_name
.
gsub!
(
/^\//
,
""
)
@
key_id
=
key_id
@
actor
=
actor
@refname
=
refname
@branch_name
=
/refs\/heads\/([\/\w\.-]+)/
.
match
(
refname
).
to_a
.
last
...
...
@@ -27,19 +27,12 @@ class GitlabUpdate
# get value from it
ENV
[
'GL_ID'
]
=
nil
# If its push over ssh
# we need to check user permission per branch first
if
ssh?
if
api
.
allowed?
(
'git-receive-pack'
,
@repo_name
,
@key_id
,
@branch_name
)
update_redis
exit
0
else
puts
"GitLab: You are not allowed to access
#{
@branch_name
}
!"
exit
1
end
else
if
api
.
allowed?
(
'git-receive-pack'
,
@repo_name
,
@actor
,
@branch_name
,
@oldrev
,
@newrev
)
update_redis
exit
0
else
puts
"GitLab: You are not allowed to access
#{
@branch_name
}
!"
exit
1
end
end
...
...
@@ -49,13 +42,9 @@ class GitlabUpdate
GitlabNet
.
new
end
def
ssh?
@key_id
=~
/\Akey\-\d+\Z/
end
def
update_redis
queue
=
"
#{
config
.
redis_namespace
}
:queue:post_receive"
msg
=
JSON
.
dump
({
'class'
=>
'PostReceive'
,
'args'
=>
[
@repo_path
,
@oldrev
,
@newrev
,
@refname
,
@
key_id
]})
msg
=
JSON
.
dump
({
'class'
=>
'PostReceive'
,
'args'
=>
[
@repo_path
,
@oldrev
,
@newrev
,
@refname
,
@
actor
]})
unless
system
(
*
config
.
redis_command
,
'rpush'
,
queue
,
msg
,
err:
'/dev/null'
,
out:
'/dev/null'
)
puts
"GitLab: An unexpected error occurred (redis-cli returned
#{
$?
.
exitstatus
}
)."
exit
1
...
...
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