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
60e258e3
Commit
60e258e3
authored
Jun 05, 2019
by
Igor
Committed by
Nick Thomas
Jun 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Go implementation for git-upload-archive
parent
f61185b8
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
171 additions
and
0 deletions
+171
-0
go/internal/command/command.go
go/internal/command/command.go
+3
-0
go/internal/command/command_test.go
go/internal/command/command_test.go
+13
-0
go/internal/command/commandargs/command_args.go
go/internal/command/commandargs/command_args.go
+1
-0
go/internal/command/commandargs/command_args_test.go
go/internal/command/commandargs/command_args_test.go
+7
-0
go/internal/command/uploadarchive/gitalycall.go
go/internal/command/uploadarchive/gitalycall.go
+32
-0
go/internal/command/uploadarchive/gitalycall_test.go
go/internal/command/uploadarchive/gitalycall_test.go
+40
-0
go/internal/command/uploadarchive/uploadarchive.go
go/internal/command/uploadarchive/uploadarchive.go
+36
-0
go/internal/command/uploadarchive/uploadarchive_test.go
go/internal/command/uploadarchive/uploadarchive_test.go
+31
-0
go/internal/gitlabnet/testserver/gitalyserver.go
go/internal/gitlabnet/testserver/gitalyserver.go
+8
-0
No files found.
go/internal/command/command.go
View file @
60e258e3
...
...
@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/receivepack"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/twofactorrecover"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/uploadarchive"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/uploadpack"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
)
...
...
@@ -41,6 +42,8 @@ func buildCommand(args *commandargs.CommandArgs, config *config.Config, readWrit
return
&
receivepack
.
Command
{
Config
:
config
,
Args
:
args
,
ReadWriter
:
readWriter
}
case
commandargs
.
UploadPack
:
return
&
uploadpack
.
Command
{
Config
:
config
,
Args
:
args
,
ReadWriter
:
readWriter
}
case
commandargs
.
UploadArchive
:
return
&
uploadarchive
.
Command
{
Config
:
config
,
Args
:
args
,
ReadWriter
:
readWriter
}
}
return
nil
...
...
go/internal/command/command_test.go
View file @
60e258e3
...
...
@@ -9,6 +9,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/fallback"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/receivepack"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/twofactorrecover"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/uploadarchive"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/uploadpack"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/testhelper"
...
...
@@ -81,6 +82,18 @@ func TestNew(t *testing.T) {
},
expectedType
:
&
uploadpack
.
Command
{},
},
{
desc
:
"it returns a UploadArchive command if the feature is enabled"
,
config
:
&
config
.
Config
{
GitlabUrl
:
"http+unix://gitlab.socket"
,
Migration
:
config
.
MigrationConfig
{
Enabled
:
true
,
Features
:
[]
string
{
"git-upload-archive"
}},
},
environment
:
map
[
string
]
string
{
"SSH_CONNECTION"
:
"1"
,
"SSH_ORIGINAL_COMMAND"
:
"git-upload-archive"
,
},
expectedType
:
&
uploadarchive
.
Command
{},
},
{
desc
:
"it returns a Fallback command if the feature is unimplemented"
,
config
:
&
config
.
Config
{
...
...
go/internal/command/commandargs/command_args.go
View file @
60e258e3
...
...
@@ -15,6 +15,7 @@ const (
TwoFactorRecover
CommandType
=
"2fa_recovery_codes"
ReceivePack
CommandType
=
"git-receive-pack"
UploadPack
CommandType
=
"git-upload-pack"
UploadArchive
CommandType
=
"git-upload-archive"
)
var
(
...
...
go/internal/command/commandargs/command_args_test.go
View file @
60e258e3
...
...
@@ -83,6 +83,13 @@ func TestParseSuccess(t *testing.T) {
"SSH_ORIGINAL_COMMAND"
:
`git upload-pack "group/repo"`
,
},
expectedArgs
:
&
CommandArgs
{
SshArgs
:
[]
string
{
"git-upload-pack"
,
"group/repo"
},
CommandType
:
UploadPack
},
},
{
desc
:
"It parses git-upload-archive command"
,
environment
:
map
[
string
]
string
{
"SSH_CONNECTION"
:
"1"
,
"SSH_ORIGINAL_COMMAND"
:
"git-upload-archive 'group/repo'"
,
},
expectedArgs
:
&
CommandArgs
{
SshArgs
:
[]
string
{
"git-upload-archive"
,
"group/repo"
},
CommandType
:
UploadArchive
},
},
}
...
...
go/internal/command/uploadarchive/gitalycall.go
0 → 100644
View file @
60e258e3
package
uploadarchive
import
(
"context"
"google.golang.org/grpc"
pb
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/client"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/accessverifier"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/handler"
)
func
(
c
*
Command
)
performGitalyCall
(
response
*
accessverifier
.
Response
)
error
{
gc
:=
&
handler
.
GitalyCommand
{
Config
:
c
.
Config
,
ServiceName
:
string
(
commandargs
.
UploadArchive
),
Address
:
response
.
Gitaly
.
Address
,
Token
:
response
.
Gitaly
.
Token
,
}
request
:=
&
pb
.
SSHUploadArchiveRequest
{
Repository
:
&
response
.
Gitaly
.
Repo
}
return
gc
.
RunGitalyCommand
(
func
(
ctx
context
.
Context
,
conn
*
grpc
.
ClientConn
)
(
int32
,
error
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
rw
:=
c
.
ReadWriter
return
client
.
UploadArchive
(
ctx
,
conn
,
rw
.
In
,
rw
.
Out
,
rw
.
ErrOut
,
request
)
})
}
go/internal/command/uploadarchive/gitalycall_test.go
0 → 100644
View file @
60e258e3
package
uploadarchive
import
(
"bytes"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/testserver"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/testhelper/requesthandlers"
)
func
TestUploadPack
(
t
*
testing
.
T
)
{
gitalyAddress
,
cleanup
:=
testserver
.
StartGitalyServer
(
t
)
defer
cleanup
()
requests
:=
requesthandlers
.
BuildAllowedWithGitalyHandlers
(
t
,
gitalyAddress
)
url
,
cleanup
:=
testserver
.
StartHttpServer
(
t
,
requests
)
defer
cleanup
()
output
:=
&
bytes
.
Buffer
{}
input
:=
&
bytes
.
Buffer
{}
userId
:=
"1"
repo
:=
"group/repo"
cmd
:=
&
Command
{
Config
:
&
config
.
Config
{
GitlabUrl
:
url
},
Args
:
&
commandargs
.
CommandArgs
{
GitlabKeyId
:
userId
,
CommandType
:
commandargs
.
UploadArchive
,
SshArgs
:
[]
string
{
"git-upload-archive"
,
repo
}},
ReadWriter
:
&
readwriter
.
ReadWriter
{
ErrOut
:
output
,
Out
:
output
,
In
:
input
},
}
err
:=
cmd
.
Execute
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"UploadArchive: "
+
repo
,
output
.
String
())
}
go/internal/command/uploadarchive/uploadarchive.go
0 → 100644
View file @
60e258e3
package
uploadarchive
import
(
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/shared/accessverifier"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/shared/disallowedcommand"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
)
type
Command
struct
{
Config
*
config
.
Config
Args
*
commandargs
.
CommandArgs
ReadWriter
*
readwriter
.
ReadWriter
}
func
(
c
*
Command
)
Execute
()
error
{
args
:=
c
.
Args
.
SshArgs
if
len
(
args
)
!=
2
{
return
disallowedcommand
.
Error
}
repo
:=
args
[
1
]
response
,
err
:=
c
.
verifyAccess
(
repo
)
if
err
!=
nil
{
return
err
}
return
c
.
performGitalyCall
(
response
)
}
func
(
c
*
Command
)
verifyAccess
(
repo
string
)
(
*
accessverifier
.
Response
,
error
)
{
cmd
:=
accessverifier
.
Command
{
c
.
Config
,
c
.
Args
,
c
.
ReadWriter
}
return
cmd
.
Verify
(
c
.
Args
.
CommandType
,
repo
)
}
go/internal/command/uploadarchive/uploadarchive_test.go
0 → 100644
View file @
60e258e3
package
uploadarchive
import
(
"bytes"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/testserver"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/testhelper/requesthandlers"
)
func
TestForbiddenAccess
(
t
*
testing
.
T
)
{
requests
:=
requesthandlers
.
BuildDisallowedByApiHandlers
(
t
)
url
,
cleanup
:=
testserver
.
StartHttpServer
(
t
,
requests
)
defer
cleanup
()
output
:=
&
bytes
.
Buffer
{}
cmd
:=
&
Command
{
Config
:
&
config
.
Config
{
GitlabUrl
:
url
},
Args
:
&
commandargs
.
CommandArgs
{
GitlabKeyId
:
"disallowed"
,
SshArgs
:
[]
string
{
"git-upload-archive"
,
"group/repo"
}},
ReadWriter
:
&
readwriter
.
ReadWriter
{
ErrOut
:
output
,
Out
:
output
},
}
err
:=
cmd
.
Execute
()
require
.
Equal
(
t
,
"Disallowed by API call"
,
err
.
Error
())
}
go/internal/gitlabnet/testserver/gitalyserver.go
View file @
60e258e3
...
...
@@ -41,6 +41,14 @@ func (s *testGitalyServer) SSHUploadPack(stream pb.SSHService_SSHUploadPackServe
}
func
(
s
*
testGitalyServer
)
SSHUploadArchive
(
stream
pb
.
SSHService_SSHUploadArchiveServer
)
error
{
req
,
err
:=
stream
.
Recv
()
if
err
!=
nil
{
return
err
}
response
:=
[]
byte
(
"UploadArchive: "
+
req
.
Repository
.
GlRepository
)
stream
.
Send
(
&
pb
.
SSHUploadArchiveResponse
{
Stdout
:
response
})
return
nil
}
...
...
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