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
f0a6e62d
Commit
f0a6e62d
authored
Nov 28, 2019
by
Ash McKenzie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use correct LFS download or upload operation names
parent
0afa8ec5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
40 deletions
+62
-40
internal/command/lfsauthenticate/lfsauthenticate.go
internal/command/lfsauthenticate/lfsauthenticate.go
+18
-14
internal/gitlabnet/lfsauthenticate/client.go
internal/gitlabnet/lfsauthenticate/client.go
+6
-6
internal/gitlabnet/lfsauthenticate/client_test.go
internal/gitlabnet/lfsauthenticate/client_test.go
+38
-20
No files found.
internal/command/lfsauthenticate/lfsauthenticate.go
View file @
f0a6e62d
...
@@ -14,8 +14,8 @@ import (
...
@@ -14,8 +14,8 @@ import (
)
)
const
(
const
(
download
Ac
tion
=
"download"
download
Opera
tion
=
"download"
upload
Ac
tion
=
"upload"
upload
Opera
tion
=
"upload"
)
)
type
Command
struct
{
type
Command
struct
{
...
@@ -40,8 +40,11 @@ func (c *Command) Execute() error {
...
@@ -40,8 +40,11 @@ func (c *Command) Execute() error {
return
disallowedcommand
.
Error
return
disallowedcommand
.
Error
}
}
// e.g. git-lfs-authenticate user/repo.git download
repo
:=
args
[
1
]
repo
:=
args
[
1
]
action
,
err
:=
actionToCommandType
(
args
[
2
])
operation
:=
args
[
2
]
action
,
err
:=
actionFromOperation
(
operation
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -51,7 +54,7 @@ func (c *Command) Execute() error {
...
@@ -51,7 +54,7 @@ func (c *Command) Execute() error {
return
err
return
err
}
}
payload
,
err
:=
c
.
authenticate
(
ac
tion
,
repo
,
accessResponse
.
UserId
)
payload
,
err
:=
c
.
authenticate
(
opera
tion
,
repo
,
accessResponse
.
UserId
)
if
err
!=
nil
{
if
err
!=
nil
{
// return nothing just like Ruby's GitlabShell#lfs_authenticate does
// return nothing just like Ruby's GitlabShell#lfs_authenticate does
return
nil
return
nil
...
@@ -62,18 +65,19 @@ func (c *Command) Execute() error {
...
@@ -62,18 +65,19 @@ func (c *Command) Execute() error {
return
nil
return
nil
}
}
func
actionToCommandType
(
action
string
)
(
commandargs
.
CommandType
,
error
)
{
func
actionFromOperation
(
operation
string
)
(
commandargs
.
CommandType
,
error
)
{
var
accessAction
commandargs
.
CommandType
var
action
commandargs
.
CommandType
switch
action
{
case
downloadAction
:
switch
operation
{
accessAction
=
commandargs
.
UploadPack
case
downloadOperation
:
case
uploadAction
:
action
=
commandargs
.
UploadPack
accessAction
=
commandargs
.
ReceivePack
case
uploadOperation
:
action
=
commandargs
.
ReceivePack
default
:
default
:
return
""
,
disallowedcommand
.
Error
return
""
,
disallowedcommand
.
Error
}
}
return
ac
cessAc
tion
,
nil
return
action
,
nil
}
}
func
(
c
*
Command
)
verifyAccess
(
action
commandargs
.
CommandType
,
repo
string
)
(
*
accessverifier
.
Response
,
error
)
{
func
(
c
*
Command
)
verifyAccess
(
action
commandargs
.
CommandType
,
repo
string
)
(
*
accessverifier
.
Response
,
error
)
{
...
@@ -82,13 +86,13 @@ func (c *Command) verifyAccess(action commandargs.CommandType, repo string) (*ac
...
@@ -82,13 +86,13 @@ func (c *Command) verifyAccess(action commandargs.CommandType, repo string) (*ac
return
cmd
.
Verify
(
action
,
repo
)
return
cmd
.
Verify
(
action
,
repo
)
}
}
func
(
c
*
Command
)
authenticate
(
action
commandargs
.
CommandType
,
repo
,
userId
string
)
([]
byte
,
error
)
{
func
(
c
*
Command
)
authenticate
(
operation
string
,
repo
,
userId
string
)
([]
byte
,
error
)
{
client
,
err
:=
lfsauthenticate
.
NewClient
(
c
.
Config
,
c
.
Args
)
client
,
err
:=
lfsauthenticate
.
NewClient
(
c
.
Config
,
c
.
Args
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
response
,
err
:=
client
.
Authenticate
(
ac
tion
,
repo
,
userId
)
response
,
err
:=
client
.
Authenticate
(
opera
tion
,
repo
,
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
internal/gitlabnet/lfsauthenticate/client.go
View file @
f0a6e62d
...
@@ -17,7 +17,7 @@ type Client struct {
...
@@ -17,7 +17,7 @@ type Client struct {
}
}
type
Request
struct
{
type
Request
struct
{
Action
commandargs
.
CommandType
`json:"operation"`
Operation
string
`json:"operation"`
Repo
string
`json:"project"`
Repo
string
`json:"project"`
KeyId
string
`json:"key_id,omitempty"`
KeyId
string
`json:"key_id,omitempty"`
UserId
string
`json:"user_id,omitempty"`
UserId
string
`json:"user_id,omitempty"`
...
@@ -39,8 +39,8 @@ func NewClient(config *config.Config, args *commandargs.Shell) (*Client, error)
...
@@ -39,8 +39,8 @@ func NewClient(config *config.Config, args *commandargs.Shell) (*Client, error)
return
&
Client
{
config
:
config
,
client
:
client
,
args
:
args
},
nil
return
&
Client
{
config
:
config
,
client
:
client
,
args
:
args
},
nil
}
}
func
(
c
*
Client
)
Authenticate
(
action
commandargs
.
CommandType
,
repo
,
userId
string
)
(
*
Response
,
error
)
{
func
(
c
*
Client
)
Authenticate
(
operation
,
repo
,
userId
string
)
(
*
Response
,
error
)
{
request
:=
&
Request
{
Action
:
ac
tion
,
Repo
:
repo
}
request
:=
&
Request
{
Operation
:
opera
tion
,
Repo
:
repo
}
if
c
.
args
.
GitlabKeyId
!=
""
{
if
c
.
args
.
GitlabKeyId
!=
""
{
request
.
KeyId
=
c
.
args
.
GitlabKeyId
request
.
KeyId
=
c
.
args
.
GitlabKeyId
}
else
{
}
else
{
...
...
internal/gitlabnet/lfsauthenticate/client_test.go
View file @
f0a6e62d
...
@@ -16,7 +16,6 @@ import (
...
@@ -16,7 +16,6 @@ import (
const
(
const
(
keyId
=
"123"
keyId
=
"123"
repo
=
"group/repo"
repo
=
"group/repo"
action
=
commandargs
.
UploadPack
)
)
func
setup
(
t
*
testing
.
T
)
[]
testserver
.
TestRequestHandler
{
func
setup
(
t
*
testing
.
T
)
[]
testserver
.
TestRequestHandler
{
...
@@ -64,17 +63,17 @@ func TestFailedRequests(t *testing.T) {
...
@@ -64,17 +63,17 @@ func TestFailedRequests(t *testing.T) {
}{
}{
{
{
desc
:
"With bad response"
,
desc
:
"With bad response"
,
args
:
&
commandargs
.
Shell
{
GitlabKeyId
:
"-1"
,
CommandType
:
commandargs
.
UploadPack
},
args
:
&
commandargs
.
Shell
{
GitlabKeyId
:
"-1"
,
CommandType
:
commandargs
.
LfsAuthenticate
,
SshArgs
:
[]
string
{
"git-lfs-authenticate"
,
repo
,
"download"
}
},
expectedOutput
:
"Parsing failed"
,
expectedOutput
:
"Parsing failed"
,
},
},
{
{
desc
:
"With API returns an error"
,
desc
:
"With API returns an error"
,
args
:
&
commandargs
.
Shell
{
GitlabKeyId
:
"forbidden"
,
CommandType
:
commandargs
.
UploadPack
},
args
:
&
commandargs
.
Shell
{
GitlabKeyId
:
"forbidden"
,
CommandType
:
commandargs
.
LfsAuthenticate
,
SshArgs
:
[]
string
{
"git-lfs-authenticate"
,
repo
,
"download"
}
},
expectedOutput
:
"Internal API error (403)"
,
expectedOutput
:
"Internal API error (403)"
,
},
},
{
{
desc
:
"With API fails"
,
desc
:
"With API fails"
,
args
:
&
commandargs
.
Shell
{
GitlabKeyId
:
"broken"
,
CommandType
:
commandargs
.
UploadPack
},
args
:
&
commandargs
.
Shell
{
GitlabKeyId
:
"broken"
,
CommandType
:
commandargs
.
LfsAuthenticate
,
SshArgs
:
[]
string
{
"git-lfs-authenticate"
,
repo
,
"download"
}
},
expectedOutput
:
"Internal API error (500)"
,
expectedOutput
:
"Internal API error (500)"
,
},
},
}
}
...
@@ -84,9 +83,9 @@ func TestFailedRequests(t *testing.T) {
...
@@ -84,9 +83,9 @@ func TestFailedRequests(t *testing.T) {
client
,
err
:=
NewClient
(
&
config
.
Config
{
GitlabUrl
:
url
},
tc
.
args
)
client
,
err
:=
NewClient
(
&
config
.
Config
{
GitlabUrl
:
url
},
tc
.
args
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
repo
:=
"group/repo"
operation
:=
tc
.
args
.
SshArgs
[
2
]
_
,
err
=
client
.
Authenticate
(
tc
.
args
.
CommandType
,
repo
,
""
)
_
,
err
=
client
.
Authenticate
(
operation
,
repo
,
""
)
require
.
Error
(
t
,
err
)
require
.
Error
(
t
,
err
)
require
.
Equal
(
t
,
tc
.
expectedOutput
,
err
.
Error
())
require
.
Equal
(
t
,
tc
.
expectedOutput
,
err
.
Error
())
...
@@ -99,11 +98,28 @@ func TestSuccessfulRequests(t *testing.T) {
...
@@ -99,11 +98,28 @@ func TestSuccessfulRequests(t *testing.T) {
url
,
cleanup
:=
testserver
.
StartHttpServer
(
t
,
requests
)
url
,
cleanup
:=
testserver
.
StartHttpServer
(
t
,
requests
)
defer
cleanup
()
defer
cleanup
()
args
:=
&
commandargs
.
Shell
{
GitlabKeyId
:
keyId
,
CommandType
:
commandargs
.
LfsAuthenticate
}
testCases
:=
[]
struct
{
desc
string
operation
string
}{
{
desc
:
"For download"
,
operation
:
"download"
,
},
{
desc
:
"For upload"
,
operation
:
"upload"
,
},
}
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
desc
,
func
(
t
*
testing
.
T
)
{
operation
:=
tc
.
operation
args
:=
&
commandargs
.
Shell
{
GitlabKeyId
:
keyId
,
CommandType
:
commandargs
.
LfsAuthenticate
,
SshArgs
:
[]
string
{
"git-lfs-authenticate"
,
repo
,
operation
}}
client
,
err
:=
NewClient
(
&
config
.
Config
{
GitlabUrl
:
url
},
args
)
client
,
err
:=
NewClient
(
&
config
.
Config
{
GitlabUrl
:
url
},
args
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
response
,
err
:=
client
.
Authenticate
(
ac
tion
,
repo
,
""
)
response
,
err
:=
client
.
Authenticate
(
opera
tion
,
repo
,
""
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
expectedResponse
:=
&
Response
{
expectedResponse
:=
&
Response
{
...
@@ -114,4 +130,6 @@ func TestSuccessfulRequests(t *testing.T) {
...
@@ -114,4 +130,6 @@ func TestSuccessfulRequests(t *testing.T) {
}
}
require
.
Equal
(
t
,
expectedResponse
,
response
)
require
.
Equal
(
t
,
expectedResponse
,
response
)
})
}
}
}
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