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 3dba026f authored by Patrick Bajao's avatar Patrick Bajao Committed by GitLab
Browse files

Merge branch '784-auditevent-lint' into 'main'

Lint fixes for audit event packages

Closes #784

See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1140



Merged-by: default avatarPatrick Bajao <ebajao@gitlab.com>
Approved-by: default avatarPatrick Bajao <ebajao@gitlab.com>
Reviewed-by: default avatarPatrick Bajao <ebajao@gitlab.com>
Reviewed-by: default avatarAsh McKenzie <amckenzie@gitlab.com>
Co-authored-by: default avatarAsh McKenzie <amckenzie@gitlab.com>
Co-authored-by: default avatarArchish <archishthakkar@gmail.com>
parents 4ba941ae 920fa8d7
No related branches found
No related tags found
No related merge requests found
// Package gitauditevent handles Git audit events for GitLab.
package gitauditevent
import (
Loading
Loading
Loading
Loading
@@ -7,6 +7,7 @@ import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/commandargs"
Loading
Loading
@@ -30,13 +31,13 @@ func TestGitAudit(t *testing.T) {
called = true
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
assert.NoError(t, err)
defer r.Body.Close()
var request *gitauditevent.Request
require.NoError(t, json.Unmarshal(body, &request))
require.Equal(t, testUsername, request.Username)
require.Equal(t, testRepo, request.Repo)
assert.NoError(t, json.Unmarshal(body, &request))
assert.Equal(t, testUsername, request.Username)
assert.Equal(t, testRepo, request.Repo)
w.WriteHeader(http.StatusOK)
},
Loading
Loading
// Package gitauditevent handles Git audit events for GitLab.
package gitauditevent
import (
Loading
Loading
@@ -13,11 +14,13 @@ import (
const uri = "/api/v4/internal/shellhorse/git_audit_event"
// Client handles communication with the GitLab audit event API.
type Client struct {
config *config.Config
client *client.GitlabNetClient
}
// NewClient creates a new Client for sending audit events.
func NewClient(config *config.Config) (*Client, error) {
client, err := gitlabnet.GetClient(config)
if err != nil {
Loading
Loading
@@ -27,6 +30,7 @@ func NewClient(config *config.Config) (*Client, error) {
return &Client{config: config, client: client}, nil
}
// Request represents the data for a Git audit event.
type Request struct {
Action commandargs.CommandType `json:"action"`
Protocol string `json:"protocol"`
Loading
Loading
@@ -35,6 +39,7 @@ type Request struct {
PackfileStats *pb.PackfileNegotiationStatistics `json:"packfile_stats,omitempty"`
}
// Audit sends an audit event to the GitLab API.
func (c *Client) Audit(ctx context.Context, username string, action commandargs.CommandType, repo string, packfileStats *pb.PackfileNegotiationStatistics) error {
request := &Request{
Action: action,
Loading
Loading
@@ -48,6 +53,7 @@ func (c *Client) Audit(ctx context.Context, username string, action commandargs.
if err != nil {
return err
}
defer response.Body.Close()
defer response.Body.Close() //nolint:errcheck
return nil
}
Loading
Loading
@@ -7,6 +7,7 @@ import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
pb "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
Loading
Loading
@@ -48,17 +49,17 @@ func setup(t *testing.T, responseStatus int) *Client {
Path: uri,
Handler: func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
assert.NoError(t, err)
defer r.Body.Close()
var request *Request
require.NoError(t, json.Unmarshal(body, &request))
require.Equal(t, testUsername, request.Username)
require.Equal(t, testAction, request.Action)
require.Equal(t, testRepo, request.Repo)
require.Equal(t, "ssh", request.Protocol)
require.Equal(t, testPackfileWants, request.PackfileStats.Wants)
require.Equal(t, testPackfileHaves, request.PackfileStats.Haves)
assert.NoError(t, json.Unmarshal(body, &request))
assert.Equal(t, testUsername, request.Username)
assert.Equal(t, testAction, request.Action)
assert.Equal(t, testRepo, request.Repo)
assert.Equal(t, "ssh", request.Protocol)
assert.Equal(t, testPackfileWants, request.PackfileStats.Wants)
assert.Equal(t, testPackfileHaves, request.PackfileStats.Haves)
w.WriteHeader(responseStatus)
},
Loading
Loading
Loading
Loading
@@ -131,11 +131,6 @@ internal/command/discover/discover.go:23:15: ST1005: error strings should not be
internal/command/discover/discover.go:29:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/discover/discover.go:32:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/discover/discover.go:35:20: context-keys-type: should not use basic type string as key in context.WithValue (revive)
internal/command/gitauditevent/audit.go:1:1: package-comments: should have a package comment (revive)
internal/command/gitauditevent/audit_test.go:33:5: go-require: do not use require in http handlers (testifylint)
internal/command/gitauditevent/audit_test.go:37:5: go-require: do not use require in http handlers (testifylint)
internal/command/gitauditevent/audit_test.go:38:5: go-require: do not use require in http handlers (testifylint)
internal/command/gitauditevent/audit_test.go:39:5: go-require: do not use require in http handlers (testifylint)
internal/command/githttp/pull.go:1:1: package-comments: should have a package comment (revive)
internal/command/githttp/pull.go:20:5: var-naming: var uploadPackHttpPrefix should be uploadPackHTTPPrefix (revive)
internal/command/githttp/pull.go:22:6: exported: exported type PullCommand should have comment or be unexported (revive)
Loading
Loading
@@ -365,20 +360,6 @@ internal/gitlabnet/git/client_test.go:204:5: go-require: do not use require in h
internal/gitlabnet/git/client_test.go:213:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/git/client_test.go:214:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/git/client_test.go:217:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/gitauditevent/client.go:1:1: package-comments: should have a package comment (revive)
internal/gitlabnet/gitauditevent/client.go:16:6: exported: exported type Client should have comment or be unexported (revive)
internal/gitlabnet/gitauditevent/client.go:21:1: exported: exported function NewClient should have comment or be unexported (revive)
internal/gitlabnet/gitauditevent/client.go:30:6: exported: exported type Request should have comment or be unexported (revive)
internal/gitlabnet/gitauditevent/client.go:38:1: exported: exported method Client.Audit should have comment or be unexported (revive)
internal/gitlabnet/gitauditevent/client.go:51:27: Error return value of `response.Body.Close` is not checked (errcheck)
internal/gitlabnet/gitauditevent/client_test.go:51:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/gitauditevent/client_test.go:55:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/gitauditevent/client_test.go:56:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/gitauditevent/client_test.go:57:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/gitauditevent/client_test.go:58:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/gitauditevent/client_test.go:59:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/gitauditevent/client_test.go:60:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/gitauditevent/client_test.go:61:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/healthcheck/client_test.go:19:41: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
internal/gitlabnet/lfsauthenticate/client_test.go:29:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/lfsauthenticate/client_test.go:32:5: go-require: do not use require in http handlers (testifylint)
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