diff --git a/api/client/client.go b/api/client/client.go index 737f62d1f..d7d317156 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -18,6 +18,7 @@ package client import ( "context" + "errors" "fmt" "net/http" @@ -55,17 +56,17 @@ func (c *Client) GetAssetScan(ctx context.Context, assetScanID string, params ty switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return assetScans, newGetExistingError(fmt.Errorf("empty body")) + return assetScans, newGetExistingError(errors.New("empty body")) } return *resp.JSON200, nil case http.StatusNotFound: if resp.JSON404 == nil { - return assetScans, newGetExistingError(fmt.Errorf("empty body on not found")) + return assetScans, newGetExistingError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return assetScans, newGetExistingError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return assetScans, newGetExistingError(fmt.Errorf("not found")) + return assetScans, newGetExistingError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return assetScans, newGetExistingError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -88,7 +89,7 @@ func (c *Client) GetAssetScans(ctx context.Context, params types.GetAssetScansPa switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return assetScans, newGetAssetScansError(fmt.Errorf("empty body")) + return assetScans, newGetAssetScansError(errors.New("empty body")) } return *resp.JSON200, nil default: @@ -113,7 +114,7 @@ func (c *Client) PatchAssetScan(ctx context.Context, assetScan types.AssetScan, switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return newUpdateAssetScanError(fmt.Errorf("empty body")) + return newUpdateAssetScanError(errors.New("empty body")) } return nil case http.StatusBadRequest: @@ -123,12 +124,12 @@ func (c *Client) PatchAssetScan(ctx context.Context, assetScan types.AssetScan, return newUpdateAssetScanError(fmt.Errorf("status code=%v", resp.StatusCode())) case http.StatusNotFound: if resp.JSON404 == nil { - return newUpdateAssetScanError(fmt.Errorf("empty body on not found")) + return newUpdateAssetScanError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return newUpdateAssetScanError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return newUpdateAssetScanError(fmt.Errorf("not found")) + return newUpdateAssetScanError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return newUpdateAssetScanError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -216,7 +217,7 @@ func (c *Client) PatchScan(ctx context.Context, scanID types.ScanID, scan *types switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return fmt.Errorf("failed to update a scan: empty body") + return errors.New("failed to update a scan: empty body") } return nil case http.StatusBadRequest: @@ -226,12 +227,12 @@ func (c *Client) PatchScan(ctx context.Context, scanID types.ScanID, scan *types return fmt.Errorf("failed to update a scan. status code=%v", resp.StatusCode()) case http.StatusNotFound: if resp.JSON404 == nil { - return fmt.Errorf("failed to update a scan: empty body on not found") + return errors.New("failed to update a scan: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return fmt.Errorf("failed to update a scan, not found: %v", *resp.JSON404.Message) } - return fmt.Errorf("failed to update a scan, not found") + return errors.New("failed to update a scan, not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return fmt.Errorf("failed to update scan. status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message) @@ -274,7 +275,7 @@ func (c *Client) PatchAssetScanStatus(ctx context.Context, assetScanID string, s switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return fmt.Errorf("failed to update an asset scan status: empty body") + return errors.New("failed to update an asset scan status: empty body") } return nil case http.StatusBadRequest: @@ -284,12 +285,12 @@ func (c *Client) PatchAssetScanStatus(ctx context.Context, assetScanID string, s return fmt.Errorf("failed to update asset scan status. status code=%v", resp.StatusCode()) case http.StatusNotFound: if resp.JSON404 == nil { - return fmt.Errorf("failed to update an asset scan status: empty body on not found") + return errors.New("failed to update an asset scan status: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return fmt.Errorf("failed to update asset scan status, not found: %v", *resp.JSON404.Message) } - return fmt.Errorf("failed to update asset scan status, not found") + return errors.New("failed to update asset scan status, not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return fmt.Errorf("failed to update asset scan status. status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message) @@ -306,17 +307,17 @@ func (c *Client) GetScan(ctx context.Context, scanID string, params types.GetSca switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("failed to get a scan: empty body") + return nil, errors.New("failed to get a scan: empty body") } return resp.JSON200, nil case http.StatusNotFound: if resp.JSON404 == nil { - return nil, fmt.Errorf("failed to get a scan: empty body on not found") + return nil, errors.New("failed to get a scan: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return nil, fmt.Errorf("failed to get a scan, not found: %v", *resp.JSON404.Message) } - return nil, fmt.Errorf("failed to get a scan, not found") + return nil, errors.New("failed to get a scan, not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return nil, fmt.Errorf("failed to get a scan status. status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message) @@ -368,17 +369,17 @@ func (c *Client) GetScanEstimation(ctx context.Context, scanEstimationID string, switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("failed to get a scan estimation: empty body") + return nil, errors.New("failed to get a scan estimation: empty body") } return resp.JSON200, nil case http.StatusNotFound: if resp.JSON404 == nil { - return nil, fmt.Errorf("failed to get a scan estimation: empty body on not found") + return nil, errors.New("failed to get a scan estimation: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return nil, fmt.Errorf("failed to get a scan estimation, not found: %v", *resp.JSON404.Message) } - return nil, fmt.Errorf("failed to get a scan estimation, not found") + return nil, errors.New("failed to get a scan estimation, not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return nil, fmt.Errorf("failed to get a scan estimation status. status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message) @@ -395,7 +396,7 @@ func (c *Client) GetScanEstimations(ctx context.Context, params types.GetScanEst switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("no scanEstimations: empty body") + return nil, errors.New("no scanEstimations: empty body") } return resp.JSON200, nil default: @@ -415,7 +416,7 @@ func (c *Client) PatchScanEstimation(ctx context.Context, scanEstimationID types switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return fmt.Errorf("failed to update a scan estimation: empty body") + return errors.New("failed to update a scan estimation: empty body") } return nil case http.StatusBadRequest: @@ -425,12 +426,12 @@ func (c *Client) PatchScanEstimation(ctx context.Context, scanEstimationID types return fmt.Errorf("failed to update a scan estimation. status code=%v", resp.StatusCode()) case http.StatusNotFound: if resp.JSON404 == nil { - return fmt.Errorf("failed to update a scan estimation: empty body on not found") + return errors.New("failed to update a scan estimation: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return fmt.Errorf("failed to update a scan estimation, not found: %v", *resp.JSON404.Message) } - return fmt.Errorf("failed to update a scan estimation, not found") + return errors.New("failed to update a scan estimation, not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return fmt.Errorf("failed to update scan estimation. status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message) @@ -447,17 +448,17 @@ func (c *Client) DeleteScanEstimation(ctx context.Context, scanEstimationID type switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return fmt.Errorf("failed to delete a scan estimation: empty body") + return errors.New("failed to delete a scan estimation: empty body") } return nil case http.StatusNotFound: if resp.JSON404 == nil { - return fmt.Errorf("failed to delete a scan estimation: empty body on not found") + return errors.New("failed to delete a scan estimation: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return fmt.Errorf("failed to delete a scan estimation, not found: %v", *resp.JSON404.Message) } - return fmt.Errorf("failed to delete a scan estimation, not found") + return errors.New("failed to delete a scan estimation, not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return fmt.Errorf("failed to delete scan estimation. status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message) @@ -509,17 +510,17 @@ func (c *Client) DeleteAssetScanEstimation(ctx context.Context, assetScanEstimat switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return fmt.Errorf("failed to delete asset scan estimation: empty body") + return errors.New("failed to delete asset scan estimation: empty body") } return nil case http.StatusNotFound: if resp.JSON404 == nil { - return fmt.Errorf("failed to delete asset scan estimation: empty body on not found") + return errors.New("failed to delete asset scan estimation: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return fmt.Errorf("failed to delete asset scan estimation, not found: %v", *resp.JSON404.Message) } - return fmt.Errorf("failed to delete asset scan estimation, not found") + return errors.New("failed to delete asset scan estimation, not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return fmt.Errorf("failed to delete asset scan estimation. status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message) @@ -542,7 +543,7 @@ func (c *Client) GetAssetScanEstimations(ctx context.Context, params types.GetAs switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return assetScanEstimations, newGetAssetScanEstimationsError(fmt.Errorf("empty body")) + return assetScanEstimations, newGetAssetScanEstimationsError(errors.New("empty body")) } return *resp.JSON200, nil default: @@ -567,17 +568,17 @@ func (c *Client) GetAssetScanEstimation(ctx context.Context, assetScanEstimation switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return assetScanEstimations, newGetExistingError(fmt.Errorf("empty body")) + return assetScanEstimations, newGetExistingError(errors.New("empty body")) } return *resp.JSON200, nil case http.StatusNotFound: if resp.JSON404 == nil { - return assetScanEstimations, newGetExistingError(fmt.Errorf("empty body on not found")) + return assetScanEstimations, newGetExistingError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return assetScanEstimations, newGetExistingError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return assetScanEstimations, newGetExistingError(fmt.Errorf("not found")) + return assetScanEstimations, newGetExistingError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return assetScanEstimations, newGetExistingError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -600,7 +601,7 @@ func (c *Client) PatchAssetScanEstimation(ctx context.Context, assetScanEstimati switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return newUpdateAssetScanEstimationError(fmt.Errorf("empty body")) + return newUpdateAssetScanEstimationError(errors.New("empty body")) } return nil case http.StatusBadRequest: @@ -610,12 +611,12 @@ func (c *Client) PatchAssetScanEstimation(ctx context.Context, assetScanEstimati return newUpdateAssetScanEstimationError(fmt.Errorf("status code=%v", resp.StatusCode())) case http.StatusNotFound: if resp.JSON404 == nil { - return newUpdateAssetScanEstimationError(fmt.Errorf("empty body on not found")) + return newUpdateAssetScanEstimationError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return newUpdateAssetScanEstimationError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return newUpdateAssetScanEstimationError(fmt.Errorf("not found")) + return newUpdateAssetScanEstimationError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return newUpdateAssetScanEstimationError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -632,7 +633,7 @@ func (c *Client) GetScanConfigs(ctx context.Context, params types.GetScanConfigs switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("no scan configs: empty body") + return nil, errors.New("no scan configs: empty body") } return resp.JSON200, nil default: @@ -651,17 +652,17 @@ func (c *Client) GetScanConfig(ctx context.Context, scanConfigID string, params switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("failed to get scan config: empty body") + return nil, errors.New("failed to get scan config: empty body") } return resp.JSON200, nil case http.StatusNotFound: if resp.JSON404 == nil { - return nil, fmt.Errorf("failed to get a scan config: empty body on not found") + return nil, errors.New("failed to get a scan config: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return nil, fmt.Errorf("failed to get a scan config, not found: %v", *resp.JSON404.Message) } - return nil, fmt.Errorf("failed to get a scan config, not found") + return nil, errors.New("failed to get a scan config, not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return nil, fmt.Errorf("failed to get a scan config. status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message) @@ -684,7 +685,7 @@ func (c *Client) PatchScanConfig(ctx context.Context, scanConfigID string, scanC switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return newPatchScanConfigResultError(fmt.Errorf("empty body")) + return newPatchScanConfigResultError(errors.New("empty body")) } return nil case http.StatusBadRequest: @@ -694,12 +695,12 @@ func (c *Client) PatchScanConfig(ctx context.Context, scanConfigID string, scanC return newPatchScanConfigResultError(fmt.Errorf("status code=%v", resp.StatusCode())) case http.StatusNotFound: if resp.JSON404 == nil { - return newPatchScanConfigResultError(fmt.Errorf("empty body on not found")) + return newPatchScanConfigResultError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return newPatchScanConfigResultError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return newPatchScanConfigResultError(fmt.Errorf("not found")) + return newPatchScanConfigResultError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return newPatchScanConfigResultError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -716,7 +717,7 @@ func (c *Client) GetScans(ctx context.Context, params types.GetScansParams) (*ty switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("no scans: empty body") + return nil, errors.New("no scans: empty body") } return resp.JSON200, nil default: @@ -778,17 +779,17 @@ func (c *Client) PatchAsset(ctx context.Context, asset types.Asset, assetID stri switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return newUpdateAssetError(fmt.Errorf("empty body")) + return newUpdateAssetError(errors.New("empty body")) } return nil case http.StatusNotFound: if resp.JSON404 == nil { - return newUpdateAssetError(fmt.Errorf("empty body on not found")) + return newUpdateAssetError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return newUpdateAssetError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return newUpdateAssetError(fmt.Errorf("not found")) + return newUpdateAssetError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return newUpdateAssetError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -812,17 +813,17 @@ func (c *Client) GetAsset(ctx context.Context, assetID string, params types.GetA switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return asset, newGetExistingError(fmt.Errorf("empty body")) + return asset, newGetExistingError(errors.New("empty body")) } return *resp.JSON200, nil case http.StatusNotFound: if resp.JSON404 == nil { - return asset, newGetExistingError(fmt.Errorf("empty body on not found")) + return asset, newGetExistingError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return asset, newGetExistingError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return asset, newGetExistingError(fmt.Errorf("not found")) + return asset, newGetExistingError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return asset, newGetExistingError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -839,7 +840,7 @@ func (c *Client) GetAssets(ctx context.Context, params types.GetAssetsParams) (* switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("no assets: empty body") + return nil, errors.New("no assets: empty body") } return resp.JSON200, nil default: @@ -858,7 +859,7 @@ func (c *Client) GetFindings(ctx context.Context, params types.GetFindingsParams switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("no findings: empty body") + return nil, errors.New("no findings: empty body") } return resp.JSON200, nil default: @@ -877,7 +878,7 @@ func (c *Client) PatchFinding(ctx context.Context, findingID types.FindingID, fi switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return fmt.Errorf("failed to update a finding: empty body") + return errors.New("failed to update a finding: empty body") } return nil case http.StatusBadRequest: @@ -887,12 +888,12 @@ func (c *Client) PatchFinding(ctx context.Context, findingID types.FindingID, fi return fmt.Errorf("failed to update a finding: status code=%v", resp.StatusCode()) case http.StatusNotFound: if resp.JSON404 == nil { - return fmt.Errorf("failed to update a finding: empty body on not found") + return errors.New("failed to update a finding: empty body on not found") } if resp.JSON404 != nil && resp.JSON404.Message != nil { return fmt.Errorf("failed to update a finding: not found: %v", *resp.JSON404.Message) } - return fmt.Errorf("failed to update a finding: not found") + return errors.New("failed to update a finding: not found") default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return fmt.Errorf("failed to update a finding: status code=%v: %v", resp.StatusCode(), resp.JSONDefault.Message) @@ -982,17 +983,17 @@ func (c *Client) PatchProvider(ctx context.Context, provider types.Provider, pro switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return newUpdateProviderError(fmt.Errorf("empty body")) + return newUpdateProviderError(errors.New("empty body")) } return nil case http.StatusNotFound: if resp.JSON404 == nil { - return newUpdateProviderError(fmt.Errorf("empty body on not found")) + return newUpdateProviderError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return newUpdateProviderError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return newUpdateProviderError(fmt.Errorf("not found")) + return newUpdateProviderError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return newUpdateProviderError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -1016,17 +1017,17 @@ func (c *Client) GetProvider(ctx context.Context, providerID string, params type switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return provider, newGetExistingError(fmt.Errorf("empty body")) + return provider, newGetExistingError(errors.New("empty body")) } return *resp.JSON200, nil case http.StatusNotFound: if resp.JSON404 == nil { - return provider, newGetExistingError(fmt.Errorf("empty body on not found")) + return provider, newGetExistingError(errors.New("empty body on not found")) } if resp.JSON404 != nil && resp.JSON404.Message != nil { return provider, newGetExistingError(fmt.Errorf("not found: %v", *resp.JSON404.Message)) } - return provider, newGetExistingError(fmt.Errorf("not found")) + return provider, newGetExistingError(errors.New("not found")) default: if resp.JSONDefault != nil && resp.JSONDefault.Message != nil { return provider, newGetExistingError(fmt.Errorf("status code=%v: %v", resp.StatusCode(), *resp.JSONDefault.Message)) @@ -1043,7 +1044,7 @@ func (c *Client) GetProviders(ctx context.Context, params types.GetProvidersPara switch resp.StatusCode() { case http.StatusOK: if resp.JSON200 == nil { - return nil, fmt.Errorf("no providers: empty body") + return nil, errors.New("no providers: empty body") } return resp.JSON200, nil default: diff --git a/api/server/database/gorm/asset.go b/api/server/database/gorm/asset.go index 3ae1ebdcf..d0cb4a778 100644 --- a/api/server/database/gorm/asset.go +++ b/api/server/database/gorm/asset.go @@ -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 diff --git a/api/server/database/gorm/provider.go b/api/server/database/gorm/provider.go index da1c0d126..36512895d 100644 --- a/api/server/database/gorm/provider.go +++ b/api/server/database/gorm/provider.go @@ -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() { diff --git a/api/server/database/gorm/scan_config.go b/api/server/database/gorm/scan_config.go index e66880d7b..ed4ee0c82 100644 --- a/api/server/database/gorm/scan_config.go +++ b/api/server/database/gorm/scan_config.go @@ -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 { @@ -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 diff --git a/api/server/database/odatasql/query.go b/api/server/database/odatasql/query.go index 58f0271da..c9c1b5880 100644 --- a/api/server/database/odatasql/query.go +++ b/api/server/database/odatasql/query.go @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// nolint:perfsprint package odatasql import ( diff --git a/api/server/database/odatasql/query_test.go b/api/server/database/odatasql/query_test.go index ddaf3035e..3d7d3b914 100644 --- a/api/server/database/odatasql/query_test.go +++ b/api/server/database/odatasql/query_test.go @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// nolint:perfsprint package odatasql import ( diff --git a/api/server/database/odatasql/selectTree.go b/api/server/database/odatasql/selectTree.go index b733e359f..892547790 100644 --- a/api/server/database/odatasql/selectTree.go +++ b/api/server/database/odatasql/selectTree.go @@ -17,6 +17,7 @@ package odatasql import ( "context" + "errors" "fmt" "github.com/CiscoM31/godata" @@ -56,12 +57,12 @@ 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 @@ -69,7 +70,7 @@ func (st *selectNode) insert(path []*godata.Token, filter *godata.GoDataFilterQu 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 @@ -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 { diff --git a/api/server/database/types/database.go b/api/server/database/types/database.go index 54a2b5ebc..54c2f51a5 100644 --- a/api/server/database/types/database.go +++ b/api/server/database/types/database.go @@ -17,7 +17,6 @@ package types import ( "errors" - "fmt" "github.com/openclarity/vmclarity/api/types" ) @@ -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 { diff --git a/api/types/assetrelationship.go b/api/types/assetrelationship.go index 2b2d42b0a..b79c94b6b 100644 --- a/api/types/assetrelationship.go +++ b/api/types/assetrelationship.go @@ -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) diff --git a/cli/analyzer/syft/syft.go b/cli/analyzer/syft/syft.go index 64024dd2c..f514deef1 100644 --- a/cli/analyzer/syft/syft.go +++ b/cli/analyzer/syft/syft.go @@ -16,6 +16,7 @@ package syft import ( + "errors" "fmt" "github.com/anchore/syft/syft" @@ -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") } } diff --git a/cli/analyzer/trivy/trivy.go b/cli/analyzer/trivy/trivy.go index 5549e56b9..04b1b0766 100644 --- a/cli/analyzer/trivy/trivy.go +++ b/cli/analyzer/trivy/trivy.go @@ -17,6 +17,7 @@ package trivy import ( "context" + "errors" "fmt" "os" @@ -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 diff --git a/cli/converter/cyclonedx.go b/cli/converter/cyclonedx.go index 3807340b3..98993e2f5 100644 --- a/cli/converter/cyclonedx.go +++ b/cli/converter/cyclonedx.go @@ -17,6 +17,7 @@ package converter import ( "bytes" + "errors" "fmt" cdx "github.com/CycloneDX/cyclonedx-go" @@ -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 diff --git a/cli/families/exploits/exploitdb/utils.go b/cli/families/exploits/exploitdb/utils.go index 9e22f7342..eeea8d543 100644 --- a/cli/families/exploits/exploitdb/utils.go +++ b/cli/families/exploits/exploitdb/utils.go @@ -18,6 +18,7 @@ package exploitdb import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -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 { diff --git a/cli/families/malware/clam/clam.go b/cli/families/malware/clam/clam.go index df7309245..02c62be04 100644 --- a/cli/families/malware/clam/clam.go +++ b/cli/families/malware/clam/clam.go @@ -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) @@ -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 } } diff --git a/cli/families/malware/yara/util/util.go b/cli/families/malware/yara/util/util.go index 983f4250b..d2132fe71 100644 --- a/cli/families/malware/yara/util/util.go +++ b/cli/families/malware/yara/util/util.go @@ -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 { diff --git a/cli/families/manager.go b/cli/families/manager.go index 9b2d2dd8a..eea6175d0 100644 --- a/cli/families/manager.go +++ b/cli/families/manager.go @@ -17,6 +17,7 @@ package families import ( "context" + "errors" "fmt" "github.com/openclarity/vmclarity/cli/families/exploits" @@ -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) @@ -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 } @@ -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) @@ -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 } diff --git a/cli/families/misconfiguration/lynis/reportParser.go b/cli/families/misconfiguration/lynis/reportParser.go index d70b4acd4..1e7e51694 100644 --- a/cli/families/misconfiguration/lynis/reportParser.go +++ b/cli/families/misconfiguration/lynis/reportParser.go @@ -17,6 +17,7 @@ package lynis import ( "bufio" + "errors" "fmt" "os" "strings" @@ -84,7 +85,7 @@ func (a *ReportParser) parseLynisReportLine(scanPath string, line string) (bool, // Everything else should be in the "option" format,