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 e0903318 authored by Ash McKenzie's avatar Ash McKenzie
Browse files

Add missing ctxWithLogMetadata for lfsauthenticate

parent 1c216d02
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -8,6 +8,7 @@ import (
"gitlab.com/gitlab-org/labkit/log"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/shared/accessverifier"
Loading
Loading
@@ -57,6 +58,12 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
return ctx, err
}
metaData := command.NewLogMetadata(
accessResponse.Gitaly.Repo.GlProjectPath,
accessResponse.Username,
)
ctxWithLogMetadata := context.WithValue(ctx, "metaData", metaData)
payload, err := c.authenticate(ctx, operation, repo, accessResponse.UserId)
if err != nil {
// return nothing just like Ruby's GitlabShell#lfs_authenticate does
Loading
Loading
@@ -65,12 +72,12 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
log.Fields{"operation": operation, "repo": repo, "user_id": accessResponse.UserId},
).WithError(err).Debug("lfsauthenticate: execute: LFS authentication failed")
return ctx, nil
return ctxWithLogMetadata, nil
}
fmt.Fprintf(c.ReadWriter.Out, "%s\n", payload)
return ctx, nil
return ctxWithLogMetadata, nil
}
func actionFromOperation(operation string) (commandargs.CommandType, error) {
Loading
Loading
Loading
Loading
@@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
Loading
Loading
@@ -109,8 +110,14 @@ func TestLfsAuthenticateRequests(t *testing.T) {
}
body := map[string]interface{}{
"gl_id": glId,
"status": true,
"gl_id": glId,
"status": true,
"gl_username": "alex-doe",
"gitaly": map[string]interface{}{
"repository": map[string]interface{}{
"gl_project_path": "group/project-path",
},
},
}
require.NoError(t, json.NewEncoder(w).Encode(body))
},
Loading
Loading
@@ -145,10 +152,15 @@ func TestLfsAuthenticateRequests(t *testing.T) {
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output},
}
_, err := cmd.Execute(context.Background())
require.NoError(t, err)
ctxWithLogMetadata, err := cmd.Execute(context.Background())
require.NoError(t, err)
require.Equal(t, tc.expectedOutput, output.String())
metaData := ctxWithLogMetadata.Value("metaData").(command.LogMetadata)
require.Equal(t, "alex-doe", metaData.Username)
require.Equal(t, "group/project-path", metaData.Project)
require.Equal(t, "group", metaData.RootNamespace)
})
}
}
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