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
f64e5d4a
Commit
f64e5d4a
authored
Apr 06, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write GitlabShell error to stderr.
parent
8f0f6762
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
21 deletions
+36
-21
bin/gitlab-shell
bin/gitlab-shell
+5
-2
lib/gitlab_shell.rb
lib/gitlab_shell.rb
+30
-18
spec/gitlab_shell_spec.rb
spec/gitlab_shell_spec.rb
+1
-1
No files found.
bin/gitlab-shell
View file @
f64e5d4a
...
...
@@ -13,6 +13,9 @@ require_relative '../lib/gitlab_init'
#
#
require
File
.
join
(
ROOT_PATH
,
'lib'
,
'gitlab_shell'
)
GitlabShell
.
new
.
exec
exit
if
GitlabShell
.
new
.
exec
exit
0
else
exit
1
end
lib/gitlab_shell.rb
View file @
f64e5d4a
...
...
@@ -3,7 +3,9 @@ require 'shellwords'
require_relative
'gitlab_net'
class
GitlabShell
class
AccessDeniedError
<
StandardError
;
end
class
DisallowedCommandError
<
StandardError
;
end
class
InvalidRepositoryPathError
<
StandardError
;
end
attr_accessor
:key_id
,
:repo_name
,
:git_cmd
,
:repos_path
,
:repo_name
...
...
@@ -15,31 +17,41 @@ class GitlabShell
end
def
exec
if
@origin_cmd
parse_cmd
unless
@origin_cmd
puts
"Welcome to GitLab,
#{
username
}
!"
return
true
end
raise
DisallowedCommandError
unless
git_cmds
.
include?
(
@git_cmd
)
parse_cmd
ENV
[
'GL_ID'
]
=
@key_id
raise
DisallowedCommandError
unless
git_cmds
.
include?
(
@git_cmd
)
access
=
api
.
check_access
(
@git_cmd
,
@repo_name
,
@key_id
,
'_any'
)
ENV
[
'GL_ID'
]
=
@key_id
status
=
api
.
check_access
(
@git_cmd
,
@repo_name
,
@key_id
,
'_any'
)
if
access
.
allowed?
process_cmd
else
message
=
"gitlab-shell: Access denied for git command <
#{
@origin_cmd
}
> by
#{
log_username
}
."
$logger
.
warn
message
puts
access
.
message
end
else
puts
"Welcome to GitLab,
#{
username
}
!"
end
raise
AccessDeniedError
,
status
.
message
unless
status
.
allowed?
process_cmd
true
rescue
GitlabNet
::
ApiUnreachableError
=>
ex
puts
"Failed to authorize your Git request: internal API unreachable"
$stderr
.
puts
"GitLab: Failed to authorize your Git request: internal API unreachable"
false
rescue
AccessDeniedError
=>
ex
message
=
"gitlab-shell: Access denied for git command <
#{
@origin_cmd
}
> by
#{
log_username
}
."
$logger
.
warn
message
$stderr
.
puts
"GitLab:
#{
ex
.
message
}
"
false
rescue
DisallowedCommandError
=>
ex
message
=
"gitlab-shell: Attempt to execute disallowed command <
#{
@origin_cmd
}
> by
#{
log_username
}
."
$logger
.
warn
message
puts
'Disallowed command'
$stderr
.
puts
"GitLab: Disallowed command"
false
rescue
InvalidRepositoryPathError
=>
ex
$stderr
.
puts
"GitLab: Invalid repository path"
false
end
protected
...
...
@@ -125,7 +137,7 @@ class GitlabShell
if
File
.
absolute_path
(
full_repo_path
)
==
full_repo_path
path
else
abort
"Wrong repository path"
raise
InvalidRepositoryPathError
end
end
...
...
spec/gitlab_shell_spec.rb
View file @
f64e5d4a
...
...
@@ -241,7 +241,7 @@ describe GitlabShell do
before
{
File
.
stub
(
:absolute_path
)
{
'y'
}
}
subject
{
->
{
shell
.
send
(
:escape_path
,
'z'
)
}
}
it
{
should
raise_error
(
SystemExit
,
"Wrong repository path"
)
}
it
{
should
raise_error
(
GitlabShell
::
InvalidRepositoryPathError
)
}
end
def
ssh_cmd
(
cmd
)
...
...
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