Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

build(deps): update module github.com/golangci/golangci-lint to v1.56.1 #1209

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 63 additions & 62 deletions api/client/client.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/server/database/gorm/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (t *AssetsTableHandler) SaveAsset(asset types.Asset, params types.PutAssets
// nolint:cyclop
func (t *AssetsTableHandler) UpdateAsset(asset types.Asset, params types.PatchAssetsAssetIDParams) (types.Asset, error) {
if asset.Id == nil || *asset.Id == "" {
return types.Asset{}, fmt.Errorf("ID is required to update asset in DB")
return types.Asset{}, errors.New("ID is required to update asset in DB")
}

var dbObj Asset
Expand Down
2 changes: 1 addition & 1 deletion api/server/database/gorm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (t *ProvidersTableHandler) SaveProvider(provider types.Provider, params typ
// nolint:cyclop
func (t *ProvidersTableHandler) UpdateProvider(provider types.Provider, params types.PatchProvidersProviderIDParams) (types.Provider, error) {
if provider.Id == nil || *provider.Id == "" {
return types.Provider{}, fmt.Errorf("ID is required to update provider in DB")
return types.Provider{}, errors.New("ID is required to update provider in DB")
}

if provider.Status.State == "" || provider.Status.Reason == "" || provider.Status.LastTransitionTime.IsZero() {
Expand Down
7 changes: 3 additions & 4 deletions api/server/database/gorm/scan_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,11 @@ func (s *ScanConfigsTableHandler) CreateScanConfig(scanConfig types.ScanConfig)

func validateRuntimeScheduleScanConfig(scheduled *types.RuntimeScheduleScanConfig) error {
if scheduled == nil {
return fmt.Errorf("scheduled must be configured")
return errors.New("scheduled must be configured")
}

if scheduled.CronLine == nil && isEmptyOperationTime(scheduled.OperationTime) {
return fmt.Errorf("both operationTime and cronLine are not set, " +
"at least one should be set")
return errors.New("both operationTime and cronLine are not set, at least one should be set")
}

if scheduled.CronLine != nil {
Expand Down Expand Up @@ -356,7 +355,7 @@ func (s *ScanConfigsTableHandler) checkUniqueness(scanConfig types.ScanConfig) (
}
// In the case of updating a scan config, needs to be checked whether other scan config exists with same name.
return sc, &common.ConflictError{
Reason: fmt.Sprintf("Scan config exists with name=%s", *sc.Name),
Reason: "Scan config exists with name=" + *sc.Name,
}
}
return types.ScanConfig{}, nil
Expand Down
1 change: 1 addition & 0 deletions api/server/database/odatasql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:perfsprint
package odatasql

import (
Expand Down
1 change: 1 addition & 0 deletions api/server/database/odatasql/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:perfsprint
package odatasql

import (
Expand Down
9 changes: 5 additions & 4 deletions api/server/database/odatasql/selectTree.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package odatasql

import (
"context"
"errors"
"fmt"

"github.com/CiscoM31/godata"
Expand Down Expand Up @@ -56,20 +57,20 @@ func (st *selectNode) insert(path []*godata.Token, filter *godata.GoDataFilterQu
// need to save the filter/select and process any sub selects/expands
if len(path) == 0 {
if st.filter != nil {
return fmt.Errorf("filter for field specified twice")
return errors.New("filter for field specified twice")
}
st.filter = filter

if st.orderby != nil {
return fmt.Errorf("orderby for field specified twice")
return errors.New("orderby for field specified twice")
}
st.orderby = orderby

st.expand = expand

if sel != nil {
if len(st.children) > 0 {
return fmt.Errorf("can not specify selection for field in multiple places")
return errors.New("can not specify selection for field in multiple places")
}

// Parse $select using ParseExpandString because godata.ParseSelectString
Expand All @@ -81,7 +82,7 @@ func (st *selectNode) insert(path []*godata.Token, filter *godata.GoDataFilterQu

for _, s := range childSelections.ExpandItems {
if s.Expand != nil {
return fmt.Errorf("expand can not be specified inside of select")
return errors.New("expand can not be specified inside of select")
}
err := st.insert(s.Path, s.Filter, s.OrderBy, s.Select, nil, false)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions api/server/database/types/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package types

import (
"errors"
"fmt"

"github.com/openclarity/vmclarity/api/types"
)
Expand All @@ -34,7 +33,7 @@ type PreconditionFailedError struct {
}

func (e *PreconditionFailedError) Error() string {
return fmt.Sprintf("Precondition failed: %s", e.Reason)
return "Precondition failed: " + e.Reason
}

type DBConfig struct {
Expand Down
3 changes: 2 additions & 1 deletion api/types/assetrelationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package types

import (
"encoding/json"
"errors"
"fmt"
)

func (a *AssetRelationship) ToAsset() (*Asset, error) {
if a == nil {
return nil, fmt.Errorf("asset relationship is nil")
return nil, errors.New("asset relationship is nil")
}

B, err := json.Marshal(a)
Expand Down
3 changes: 2 additions & 1 deletion cli/analyzer/syft/syft.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package syft

import (
"errors"
"fmt"

"github.com/anchore/syft/syft"
Expand Down Expand Up @@ -138,6 +139,6 @@ func getImageHash(sbom syft_sbom.SBOM, src string) (string, error) {
}
return hash, nil
default:
return "", fmt.Errorf("failed to get image hash from source metadata")
return "", errors.New("failed to get image hash from source metadata")
}
}
3 changes: 2 additions & 1 deletion cli/analyzer/trivy/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package trivy

import (
"context"
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -189,7 +190,7 @@ func (a *Analyzer) setError(res *analyzer.Results, err error) {

func getImageHash(properties *[]cdx.Property, src string) (string, error) {
if properties == nil {
return "", fmt.Errorf("properties was nil")
return "", errors.New("properties was nil")
}

var repoDigests []string
Expand Down
3 changes: 2 additions & 1 deletion cli/converter/cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package converter

import (
"bytes"
"errors"
"fmt"

cdx "github.com/CycloneDX/cyclonedx-go"
Expand Down Expand Up @@ -72,7 +73,7 @@ func CycloneDxToBytes(sbom *cdx.BOM, format SbomFormat) ([]byte, error) {
case Unknown:
default:
}
return nil, fmt.Errorf("can not convert cyclonedx SBOM to unknown format")
return nil, errors.New("can not convert cyclonedx SBOM to unknown format")
}

// cycloneDxToBytesUsingCycloneDxEncoder supports encoding a cdx.BOM to one of
Expand Down
3 changes: 2 additions & 1 deletion cli/families/exploits/exploitdb/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package exploitdb
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -139,7 +140,7 @@ func getExploitsViaHTTP(cveIDs []string, urlPrefix string) ([]exploitResponse, e
case err := <-errChan:
errs = append(errs, err)
case <-timeout:
return nil, fmt.Errorf("timeout fetching exploits")
return nil, errors.New("timeout fetching exploits")
}
}
if len(errs) != 0 {
Expand Down
4 changes: 2 additions & 2 deletions cli/families/malware/clam/clam.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (s *Scanner) updateFreshclamConf() error {
var confLines []string

mirrorLine := fmt.Sprintf("%s %s", constants.PrivateMirrorConf, s.config.AlternativeFreshclamMirrorURL)
scriptedUpdatesLine := fmt.Sprintf("%s no", constants.ScriptedUpdatesConf)
scriptedUpdatesLine := constants.ScriptedUpdatesConf + " no"

// Attempt to read freshclam.conf file
_, err := os.Stat(constants.FreshclamConfPath)
Expand All @@ -180,7 +180,7 @@ func (s *Scanner) updateFreshclamConf() error {
// Comment out any existing conflicting options
for i, line := range confLines {
if strings.HasPrefix(line, constants.PrivateMirrorConf) || strings.HasPrefix(line, constants.ScriptedUpdatesConf) {
confLines[i] = fmt.Sprintf("# %s", line)
confLines[i] = "# " + line
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/families/malware/yara/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type InvalidLineError struct {
}

func (e *InvalidLineError) Error() string {
return fmt.Sprintf("invalid yara line: %s", e.Line)
return "invalid yara line: " + e.Line
}

func IsErrorThresholdReached(errorCount, allCount uint) bool {
Expand Down
13 changes: 7 additions & 6 deletions cli/families/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package families

import (
"context"
"errors"
"fmt"

"github.com/openclarity/vmclarity/cli/families/exploits"
Expand Down Expand Up @@ -96,7 +97,7 @@ type FamilyNotifier interface {

func (m *Manager) Run(ctx context.Context, notifier FamilyNotifier) []error {
var oneOrMoreFamilyFailed bool
var errors []error
var errs []error
familyResults := results.New()

logger := log.GetLoggerFromContextOrDiscard(ctx)
Expand All @@ -111,7 +112,7 @@ func (m *Manager) Run(ctx context.Context, notifier FamilyNotifier) []error {

for _, family := range m.families {
if err := notifier.FamilyStarted(ctx, family.GetType()); err != nil {
errors = append(errors, fmt.Errorf("family started notification failed: %w", err))
errs = append(errs, fmt.Errorf("family started notification failed: %w", err))
continue
}

Expand All @@ -137,7 +138,7 @@ func (m *Manager) Run(ctx context.Context, notifier FamilyNotifier) []error {
FamilyType: family.GetType(),
Err: fmt.Errorf("failed to run family %v: aborted", family.GetType()),
}); err != nil {
errors = append(errors, fmt.Errorf("family finished notification failed: %w", err))
errs = append(errs, fmt.Errorf("family finished notification failed: %w", err))
}
case r := <-result:
logger.Debugf("received result from family %q: %v", family.GetType(), r)
Expand All @@ -148,14 +149,14 @@ func (m *Manager) Run(ctx context.Context, notifier FamilyNotifier) []error {
familyResults.SetResults(r.Result)
}
if err := notifier.FamilyFinished(ctx, r); err != nil {
errors = append(errors, fmt.Errorf("family finished notification failed: %w", err))
errs = append(errs, fmt.Errorf("family finished notification failed: %w", err))
}
close(result)
}
}

if oneOrMoreFamilyFailed {
errors = append(errors, fmt.Errorf("at least one family failed to run"))
errs = append(errs, errors.New("at least one family failed to run"))
}
return errors
return errs
}
3 changes: 2 additions & 1 deletion cli/families/misconfiguration/lynis/reportParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package lynis

import (
"bufio"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -84,7 +85,7 @@ func (a *ReportParser) parseLynisReportLine(scanPath string, line string) (bool,
// Everything else should be in the "option" format, <option>=<value>
option, value, ok := strings.Cut(line, "=")
if !ok {
return false, types.Misconfiguration{}, fmt.Errorf("line not in option=value format")
return false, types.Misconfiguration{}, errors.New("line not in option=value format")
}

switch option {
Expand Down
4 changes: 2 additions & 2 deletions cli/families/results/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package results

import (
"fmt"
"errors"
)

// Results store slice of results from all families.
Expand All @@ -41,5 +41,5 @@ func GetResult[familyType any](r *Results) (familyType, error) {
}
}
var res familyType
return res, fmt.Errorf("missing result")
return res, errors.New("missing result")
}
3 changes: 2 additions & 1 deletion cli/families/sbom/family.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package sbom

import (
"context"
"errors"
"fmt"
"time"

Expand All @@ -43,7 +44,7 @@ func (s SBOM) Run(ctx context.Context, _ *familiesresults.Results) (interfaces.I
logger.Info("SBOM Run...")

if len(s.conf.Inputs) == 0 {
return nil, fmt.Errorf("inputs list is empty")
return nil, errors.New("inputs list is empty")
}

// TODO: move the logic from cli utils to shared utils
Expand Down
3 changes: 2 additions & 1 deletion cli/families/vulnerabilities/family.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package vulnerabilities

import (
"context"
"errors"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (v Vulnerabilities) Run(ctx context.Context, res *results.Results) (interfa
}

if len(v.conf.Inputs) == 0 {
return nil, fmt.Errorf("inputs list is empty")
return nil, errors.New("inputs list is empty")
}

var vulResults Results
Expand Down
Loading
Loading