As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Unverified Commit dd0822a9 authored by Ash McKenzie's avatar Ash McKenzie
Browse files

Apply suggestions to enhance readability

parent 5e2e6a49
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -110,7 +110,9 @@ func Build(args *commandargs.Shell, config *config.Config, readWriter *readwrite
case commandargs.LfsAuthenticate:
return &lfsauthenticate.Command{Config: config, Args: args, ReadWriter: readWriter}
case commandargs.LfsTransfer:
return &lfstransfer.Command{Config: config, Args: args, ReadWriter: readWriter}
if config.LFSConfig.PureSSHProtocol {
return &lfstransfer.Command{Config: config, Args: args, ReadWriter: readWriter}
}
case commandargs.ReceivePack:
return &receivepack.Command{Config: config, Args: args, ReadWriter: readWriter}
case commandargs.UploadPack:
Loading
Loading
Loading
Loading
@@ -9,6 +9,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/discover"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/lfsauthenticate"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/lfstransfer"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/personalaccesstoken"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/receivepack"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/shared/disallowedcommand"
Loading
Loading
@@ -103,6 +104,45 @@ func TestNew(t *testing.T) {
}
}
func TestLFSTransferCommands(t *testing.T) {
testCases := []struct {
desc string
executable *executable.Executable
env sshenv.Env
arguments []string
config *config.Config
expectedType interface{}
errorString string
}{
{
desc: "it returns an Lfstransfer command",
executable: gitlabShellExec,
env: buildEnv("git-lfs-transfer"),
config: &config.Config{GitlabUrl: "http+unix://gitlab.socket", LFSConfig: config.LFSConfig{PureSSHProtocol: true}},
expectedType: &lfstransfer.Command{},
errorString: "",
},
{
desc: "it does not return an Lfstransfer command when config disallows pureSSH",
executable: gitlabShellExec,
env: buildEnv("git-lfs-transfer"),
config: &config.Config{GitlabUrl: "http+unix://gitlab.socket", LFSConfig: config.LFSConfig{PureSSHProtocol: false}},
expectedType: nil,
errorString: "Disallowed command",
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
command, err := cmd.New(tc.arguments, tc.env, tc.config, nil)
if len(tc.errorString) > 0 {
require.Equal(t, err.Error(), tc.errorString)
}
require.IsType(t, tc.expectedType, command)
})
}
}
func TestFailingNew(t *testing.T) {
testCases := []struct {
desc string
Loading
Loading
@@ -253,6 +293,13 @@ func TestParseSuccess(t *testing.T) {
arguments: []string{},
expectedArgs: &commandargs.Shell{Arguments: []string{}, SshArgs: []string{"git-lfs-authenticate", "group/repo", "download"}, CommandType: commandargs.LfsAuthenticate, Env: sshenv.Env{IsSSHConnection: true, OriginalCommand: "git-lfs-authenticate 'group/repo' download"}},
},
{
desc: "It parses git-lfs-transfer command",
executable: &executable.Executable{Name: executable.GitlabShell},
env: sshenv.Env{IsSSHConnection: true, OriginalCommand: "git-lfs-transfer 'group/repo' download"},
arguments: []string{},
expectedArgs: &commandargs.Shell{Arguments: []string{}, SshArgs: []string{"git-lfs-transfer", "group/repo", "download"}, CommandType: commandargs.LfsTransfer, Env: sshenv.Env{IsSSHConnection: true, OriginalCommand: "git-lfs-transfer 'group/repo' download"}},
},
}
for _, tc := range testCases {
Loading
Loading
Loading
Loading
@@ -87,8 +87,10 @@ func (b *GitlabBackend) issueBatchArgs(op string, oid string, href string, heade
if err != nil {
return "", "", err
}
id = base64.StdEncoding.EncodeToString(dataBinary)
token = base64.StdEncoding.EncodeToString(h.Sum(nil))
return id, token, nil
}
Loading
Loading
@@ -98,6 +100,7 @@ func (b *GitlabBackend) Batch(op string, pointers []transfer.BatchItem, args tra
}
reqObjects := make([]*lfstransfer.BatchObject, 0)
for _, pointer := range pointers {
reqObject := &lfstransfer.BatchObject{
Oid: pointer.Oid,
Loading
Loading
@@ -105,31 +108,38 @@ func (b *GitlabBackend) Batch(op string, pointers []transfer.BatchItem, args tra
}
reqObjects = append(reqObjects, reqObject)
}
refName := args["refname"]
hashAlgo := args["hash-algo"]
res, err := b.client.Batch(op, reqObjects, refName, hashAlgo)
if err != nil {
return nil, err
}
items := make([]transfer.BatchItem, 0)
for _, retObject := range res.Objects {
var present bool
var action *lfstransfer.BatchAction
var args transfer.Args
if action, present = retObject.Actions[op]; present {
id, token, err := b.issueBatchArgs(op, retObject.Oid, action.Href, action.Header)
if err != nil {
return nil, err
}
args = transfer.Args{
"id": id,
"token": token,
}
}
if op == "upload" {
present = !present
}
batchItem := transfer.BatchItem{
Pointer: transfer.Pointer{
Oid: retObject.Oid,
Loading
Loading
Loading
Loading
@@ -55,15 +55,18 @@ func NewClient(config *config.Config, args *commandargs.Shell, href string, auth
func (c *Client) Batch(operation string, reqObjects []*BatchObject, ref string, reqHashAlgo string) (*BatchResponse, error) {
var bref *batchRef
if ref != "" {
bref = &batchRef{Name: ref}
}
body := batchRequest{
Operation: operation,
Objects: reqObjects,
Ref: bref,
HashAlgorithm: reqHashAlgo,
}
jsonData, err := json.Marshal(body)
if err != nil {
return nil, err
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment