Skip to content

Commit

Permalink
chore: cleanup linter errors found by new version of golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
juggernot325 committed Aug 23, 2024
1 parent 6fa588b commit 34fd8bf
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 35 deletions.
25 changes: 13 additions & 12 deletions cmd/api/src/api/agi.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package api

import (
"errors"
"fmt"
"slices"
"sort"
Expand All @@ -43,7 +44,7 @@ type AssetGroupMembers []AssetGroupMember
func (s AssetGroupMembers) SortBy(columns []string) (AssetGroupMembers, error) {
for _, column := range columns {
if column == "" {
return AssetGroupMembers{}, fmt.Errorf(ErrorResponseEmptySortParameter)
return AssetGroupMembers{}, errors.New(ErrorResponseEmptySortParameter)
}

descending := false
Expand Down Expand Up @@ -78,7 +79,7 @@ func (s AssetGroupMembers) SortBy(columns []string) (AssetGroupMembers, error) {
return s[i].Name < s[j].Name
})
default:
return AssetGroupMembers{}, fmt.Errorf(ErrorResponseDetailsNotSortable)
return AssetGroupMembers{}, errors.New(ErrorResponseDetailsNotSortable)
}

if descending {
Expand Down Expand Up @@ -118,62 +119,62 @@ func (s AssetGroupMembers) BuildFilteringConditional(column string, operator mod
} else if operator == model.NotEquals {
return func(t AssetGroupMember) bool { return t.ObjectID != value }, nil
} else {
return nil, fmt.Errorf(ErrorResponseDetailsFilterPredicateNotSupported)
return nil, errors.New(ErrorResponseDetailsFilterPredicateNotSupported)
}
case "primary_kind":
if operator == model.Equals {
return func(t AssetGroupMember) bool { return t.PrimaryKind == value }, nil
} else if operator == model.NotEquals {
return func(t AssetGroupMember) bool { return t.PrimaryKind != value }, nil
} else {
return nil, fmt.Errorf(ErrorResponseDetailsFilterPredicateNotSupported)
return nil, errors.New(ErrorResponseDetailsFilterPredicateNotSupported)
}
case "environment_id":
if operator == model.Equals {
return func(t AssetGroupMember) bool { return t.EnvironmentID == value }, nil
} else if operator == model.NotEquals {
return func(t AssetGroupMember) bool { return t.EnvironmentID != value }, nil
} else {
return nil, fmt.Errorf(ErrorResponseDetailsFilterPredicateNotSupported)
return nil, errors.New(ErrorResponseDetailsFilterPredicateNotSupported)
}
case "environment_kind":
if operator == model.Equals {
return func(t AssetGroupMember) bool { return t.EnvironmentKind == value }, nil
} else if operator == model.NotEquals {
return func(t AssetGroupMember) bool { return t.EnvironmentKind != value }, nil
} else {
return nil, fmt.Errorf(ErrorResponseDetailsFilterPredicateNotSupported)
return nil, errors.New(ErrorResponseDetailsFilterPredicateNotSupported)
}
case "name":
if operator == model.Equals {
return func(t AssetGroupMember) bool { return t.Name == value }, nil
} else if operator == model.NotEquals {
return func(t AssetGroupMember) bool { return t.Name != value }, nil
} else {
return nil, fmt.Errorf(ErrorResponseDetailsFilterPredicateNotSupported)
return nil, errors.New(ErrorResponseDetailsFilterPredicateNotSupported)
}
case "asset_group_id":
if intValue, err := strconv.Atoi(value); err != nil {
return nil, fmt.Errorf(ErrorResponseDetailsBadQueryParameterFilters)
return nil, errors.New(ErrorResponseDetailsBadQueryParameterFilters)
} else if operator == model.Equals {
return func(t AssetGroupMember) bool { return t.AssetGroupID == intValue }, nil
} else if operator == model.NotEquals {
return func(t AssetGroupMember) bool { return t.AssetGroupID != intValue }, nil
} else {
return nil, fmt.Errorf(ErrorResponseDetailsFilterPredicateNotSupported)
return nil, errors.New(ErrorResponseDetailsFilterPredicateNotSupported)
}
case "custom_member":
if boolValue, err := strconv.ParseBool(value); err != nil {
return nil, fmt.Errorf(ErrorResponseDetailsBadQueryParameterFilters)
return nil, errors.New(ErrorResponseDetailsBadQueryParameterFilters)
} else if operator == model.Equals {
return func(t AssetGroupMember) bool { return t.CustomMember == boolValue }, nil
} else if operator == model.NotEquals {
return func(t AssetGroupMember) bool { return t.CustomMember != boolValue }, nil
} else {
return nil, fmt.Errorf(ErrorResponseDetailsFilterPredicateNotSupported)
return nil, errors.New(ErrorResponseDetailsFilterPredicateNotSupported)
}
default:
return nil, fmt.Errorf(ErrorResponseDetailsColumnNotFilterable)
return nil, errors.New(ErrorResponseDetailsColumnNotFilterable)
}
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/api/src/api/v2/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestManagementResource_PutUserAuthSecret(t *testing.T) {
WithContext(bhCtx).
WithMethod(http.MethodPut).
WithHeader(headers.RequestID.String(), "requestID").
WithURL(fmt.Sprintf(updateUserSecretPathFmt, goodUser.ID.String())).
WithURL(fmt.Sprintf(updateUserSecretPathFmt, goodUser.ID.String())). //nolint:govet // Ignore non-constant format string failure because it's test code
WithURLPathVars(map[string]string{"user_id": goodUser.ID.String()}).
WithBody(v2.SetUserSecretRequest{
CurrentSecret: currentPassword,
Expand All @@ -110,7 +110,7 @@ func TestManagementResource_PutUserAuthSecret(t *testing.T) {
WithContext(bhCtx).
WithMethod(http.MethodPut).
WithHeader(headers.RequestID.String(), "requestID").
WithURL(fmt.Sprintf(updateUserSecretPathFmt, goodUser.ID.String())).
WithURL(fmt.Sprintf(updateUserSecretPathFmt, goodUser.ID.String())). //nolint:govet // Ignore non-constant format string failure because it's test code
WithURLPathVars(map[string]string{"user_id": otherUser.ID.String()}).
WithBody(v2.SetUserSecretRequest{
Secret: "tesT12345!@#$",
Expand All @@ -126,7 +126,7 @@ func TestManagementResource_PutUserAuthSecret(t *testing.T) {
WithContext(bhCtx).
WithMethod(http.MethodPut).
WithHeader(headers.RequestID.String(), "requestID").
WithURL(fmt.Sprintf(updateUserSecretPathFmt, badUser.ID.String())).
WithURL(fmt.Sprintf(updateUserSecretPathFmt, badUser.ID.String())). //nolint:govet // Ignore non-constant format string failure because it's test code
WithURLPathVars(map[string]string{"user_id": badUser.ID.String()}).
WithBody(v2.SetUserSecretRequest{
Secret: "tesT12345!@#$",
Expand All @@ -146,7 +146,7 @@ func TestManagementResource_PutUserAuthSecret(t *testing.T) {
WithContext(bhCtx).
WithMethod(http.MethodPut).
WithHeader(headers.RequestID.String(), "requestID").
WithURL(fmt.Sprintf(updateUserSecretPathFmt, goodUser.ID.String())).
WithURL(fmt.Sprintf(updateUserSecretPathFmt, goodUser.ID.String())). //nolint:govet // Ignore non-constant format string failure because it's test code
WithURLPathVars(map[string]string{"user_id": goodUser.ID.String()}).
WithBody(v2.SetUserSecretRequest{
CurrentSecret: "wrongPassword",
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestManagementResource_EnableUserSAML(t *testing.T) {
// Happy path
test.Request(t).
WithMethod(http.MethodPut).
WithURL(fmt.Sprintf(updateUserPathFmt, goodUserID.String())).
WithURL(fmt.Sprintf(updateUserPathFmt, goodUserID.String())). //nolint:govet // Ignore non-constant format string failure because it's test code
WithURLPathVars(map[string]string{
"user_id": goodUserID.String(),
}).
Expand All @@ -200,7 +200,7 @@ func TestManagementResource_EnableUserSAML(t *testing.T) {
// Negative path where a user already has an auth secret set
test.Request(t).
WithMethod(http.MethodPut).
WithURL(fmt.Sprintf(updateUserPathFmt, badUserID.String())).
WithURL(fmt.Sprintf(updateUserPathFmt, badUserID.String())). //nolint:govet // Ignore non-constant format string failure because it's test code
WithURLPathVars(map[string]string{
"user_id": badUserID.String(),
}).
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestManagementResource_DeleteSAMLProvider(t *testing.T) {
// Happy path
test.Request(t).
WithMethod(http.MethodDelete).
WithURL(fmt.Sprintf(samlProviderPathFmt, goodSAMLProvider.ID)).
WithURL(fmt.Sprintf(samlProviderPathFmt, goodSAMLProvider.ID)). //nolint:govet // Ignore non-constant format string failure because it's test code
WithURLPathVars(map[string]string{
api.URIPathVariableSAMLProviderID: fmt.Sprintf("%d", goodSAMLProvider.ID),
}).
Expand All @@ -262,7 +262,7 @@ func TestManagementResource_DeleteSAMLProvider(t *testing.T) {
// Negative path where a provider has attached users
test.Request(t).
WithMethod(http.MethodDelete).
WithURL(fmt.Sprintf(samlProviderPathFmt, samlProviderWithUsers.ID)).
WithURL(fmt.Sprintf(samlProviderPathFmt, samlProviderWithUsers.ID)). //nolint:govet // Ignore non-constant format string failure because it's test code
WithURLPathVars(map[string]string{
api.URIPathVariableSAMLProviderID: fmt.Sprintf("%d", samlProviderWithUsers.ID),
}).
Expand Down
6 changes: 2 additions & 4 deletions cmd/api/src/model/saved_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package model

import (
"fmt"
)
import "errors"

type SavedQuery struct {
UserID string `json:"user_id" gorm:"index:,unique,composite:compositeIndex"`
Expand Down Expand Up @@ -77,7 +75,7 @@ func (s SavedQueries) GetFilterableColumns() []string {

func (s SavedQueries) GetValidFilterPredicatesAsStrings(column string) ([]string, error) {
if predicates, validColumn := s.ValidFilters()[column]; !validColumn {
return []string{}, fmt.Errorf(ErrorResponseDetailsColumnNotFilterable)
return []string{}, errors.New(ErrorResponseDetailsColumnNotFilterable)
} else {
var stringPredicates = make([]string, 0)
for _, predicate := range predicates {
Expand Down
14 changes: 7 additions & 7 deletions cmd/api/src/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package model

import (
"fmt"
"errors"
"net/http"
"net/url"
"slices"
Expand Down Expand Up @@ -76,7 +76,7 @@ func (s DomainSelectors) GetFilterableColumns() []string {

func (s DomainSelectors) GetValidFilterPredicatesAsStrings(column string) ([]string, error) {
if predicates, validColumn := s.ValidFilters()[column]; !validColumn {
return []string{}, fmt.Errorf(ErrorResponseDetailsColumnNotFilterable)
return []string{}, errors.New(ErrorResponseDetailsColumnNotFilterable)
} else {
var stringPredicates = make([]string, 0)
for _, predicate := range predicates {
Expand Down Expand Up @@ -118,7 +118,7 @@ func (s DomainSelectors) GetOrderCriteria(params url.Values) (OrderCriteria, err
criterion.Property = column

if !s.IsSortable(column) {
return OrderCriteria{}, fmt.Errorf(ErrorResponseDetailsColumnNotSortable)
return OrderCriteria{}, errors.New(ErrorResponseDetailsColumnNotSortable)
}

orderCriteria = append(orderCriteria, criterion)
Expand All @@ -133,18 +133,18 @@ func (s DomainSelectors) GetFilterCriteria(request *http.Request) (graph.Criteri
)

if queryFilters, err := queryParameterFilterParser.ParseQueryParameterFilters(request); err != nil {
return nil, fmt.Errorf(ErrorResponseDetailsBadQueryParameterFilters)
return nil, errors.New(ErrorResponseDetailsBadQueryParameterFilters)
} else {
for name, filters := range queryFilters {
if valid := slices.Contains(s.GetFilterableColumns(), name); !valid {
return nil, fmt.Errorf(ErrorResponseDetailsColumnNotFilterable)
return nil, errors.New(ErrorResponseDetailsColumnNotFilterable)
}
if validPredicates, err := s.GetValidFilterPredicatesAsStrings(name); err != nil {
return nil, fmt.Errorf(ErrorResponseDetailsColumnNotFilterable)
return nil, errors.New(ErrorResponseDetailsColumnNotFilterable)
} else {
for i, filter := range filters {
if !slices.Contains(validPredicates, string(filter.Operator)) {
return nil, fmt.Errorf(ErrorResponseDetailsFilterPredicateNotSupported)
return nil, errors.New(ErrorResponseDetailsFilterPredicateNotSupported)
}
queryFilters[name][i].IsStringData = s.IsString(filter.Name)
}
Expand Down
1 change: 0 additions & 1 deletion packages/go/dawgs/drivers/pg/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type liveQuery struct {
ctx context.Context
tx graph.Transaction
kindMapper KindMapper
parameters map[string]any
queryBuilder *query.Builder
}

Expand Down
2 changes: 0 additions & 2 deletions packages/go/dawgs/graph/path_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ var (
groupKind = StringKind("group")
domainKind = StringKind("domain")
userKind = StringKind("user")
computerKind = StringKind("computer")
permissionKind = StringKind("permission")
membershipKind = StringKind("member")
)

func Test_ComputeAndSetSize(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion packages/go/dawgs/query/neo4j/neo4j_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func assertOneOfQueryResult(rawQuery *cypher.RegularQuery, expectations []QueryO
msg += "\n\t" + expectation.Query
}

t.Fatalf(msg)
t.Fatalf(msg) //nolint:all // Ignore non-constant format string failure because it's test code
} else if matchingExpectation.Parameters != nil {
require.Equal(t, matchingExpectation.Parameters, builder.Parameters)
}
Expand Down

0 comments on commit 34fd8bf

Please sign in to comment.