Skip to content
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
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ linters:
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. [fast: false, auto-fix: false]
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. [auto-fix]
- forbidigo # Forbids identifiers [fast: true, auto-fix: false]
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
Expand Down Expand Up @@ -48,6 +49,7 @@ linters:
- musttag # enforce field tags in (un)marshaled structs [fast: false, auto-fix: false]
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
- nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false]
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: true]
- noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false]
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false]
Expand All @@ -74,6 +76,7 @@ linters:
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
- unused #(megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false]
- usetesting # Reports uses of functions with replacement inside the testing package. [auto-fix]
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false]
Expand All @@ -97,7 +100,6 @@ linters:
- mnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false]
- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false]
- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
- wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]

Expand Down
2 changes: 2 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func extractGeneratedNamePrefix(name string) string {
// ^
dashIndex = strings.LastIndex(name, "-")
name = name[:dashIndex]

return name
}

Expand Down Expand Up @@ -155,6 +156,7 @@ func compareJSONBodies(expected, actual map[string]interface{}) bool {
return false
}
}

return true
}

Expand Down
6 changes: 6 additions & 0 deletions internal/acctest/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func CheckResourceIDChanged(resourceName string, resourceID *string) resource.Te
return errors.New("resource ID persisted when it should have changed")
}
*resourceID = rs.Primary.ID

return nil
}
}
Expand All @@ -42,6 +43,7 @@ func CheckResourceIDPersisted(resourceName string, resourceID *string) resource.
return errors.New("resource ID changed when it should have persisted")
}
*resourceID = rs.Primary.ID

return nil
}
}
Expand Down Expand Up @@ -90,6 +92,7 @@ func CheckResourceAttrFunc(name string, key string, test func(string) error) res
if err != nil {
return fmt.Errorf("test for %s %s did not pass test: %s", name, key, err)
}

return nil
}
}
Expand All @@ -100,6 +103,7 @@ func CheckResourceAttrIPv4(name string, key string) resource.TestCheckFunc {
if ip.To4() == nil {
return fmt.Errorf("%s is not a valid IPv4", value)
}

return nil
})
}
Expand All @@ -110,6 +114,7 @@ func CheckResourceAttrIPv6(name string, key string) resource.TestCheckFunc {
if ip.To16() == nil {
return fmt.Errorf("%s is not a valid IPv6", value)
}

return nil
})
}
Expand All @@ -120,6 +125,7 @@ func CheckResourceAttrIP(name string, key string) resource.TestCheckFunc {
if ip == nil {
return fmt.Errorf("%s is not a valid IP", value)
}

return nil
})
}
2 changes: 2 additions & 0 deletions internal/acctest/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ func init() {
for _, reservedDomain := range reservedDomains {
if reservedDomain.MatchString(TestDomain) {
isReserved = true

break
}
}

if isReserved {
logging.L.Warningf("TF_TEST_DOMAIN cannot be a Scaleway required domain. Please use another one.")

return
}

Expand Down
4 changes: 4 additions & 0 deletions internal/acctest/sweepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func Sweep(f func(scwClient *scw.Client) error) error {
if err != nil {
return err
}

return f(m.ScwClient())
}

Expand All @@ -30,6 +31,7 @@ func SweepZones(zones []scw.Zone, f func(scwClient *scw.Client, zone scw.Zone) e
logging.L.Warningf("error running sweepZones, ignoring: %s", err)
}
}

return nil
}

Expand All @@ -41,6 +43,7 @@ func SweepRegions(regions []scw.Region, f func(scwClient *scw.Client, region scw

return SweepZones(zones, func(scwClient *scw.Client, zone scw.Zone) error {
r, _ := zone.Region()

return f(scwClient, r)
})
}
Expand All @@ -56,5 +59,6 @@ func sharedClientForZone(zone scw.Zone) (*scw.Client, error) {
if err != nil {
return nil, err
}

return m.ScwClient(), nil
}
3 changes: 3 additions & 0 deletions internal/acctest/validate_cassettes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func getTestFiles() (map[string]struct{}, error) {
if isCassette && !isException {
filesMap[fileNameWithoutExtSuffix(path)] = struct{}{}
}

return nil
})
if err != nil {
Expand Down Expand Up @@ -87,8 +88,10 @@ func checkErrCodeExcept(i *cassette.Interaction, c *cassette.Cassette, codes ...
return true
}
}

return false
}

return true
}

Expand Down
4 changes: 4 additions & 0 deletions internal/acctest/vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func compareJSONFields(expected, actualI interface{}) bool {
if _, isString := expected.(string); !isString {
return false
}

return compareJSONFieldsStrings(expected.(string), actual)
default:
// Consider equality when not handled
Expand Down Expand Up @@ -116,6 +117,7 @@ func cassetteBodyMatcher(actualRequest *http.Request, cassetteRequest cassette.R
} else if _, isFile := actualRequest.Body.(*os.File); isFile {
return true // Body match if request is sending a file, maybe do more check here
}

return false
}

Expand Down Expand Up @@ -243,6 +245,7 @@ func cassetteSensitiveFieldsAnonymizer(i *cassette.Interaction) error {
return fmt.Errorf("failed to marshal anonymized body: %w", err)
}
i.Response.Body = string(anonymizedBody)

return nil
}

Expand Down Expand Up @@ -290,6 +293,7 @@ func getHTTPRecoder(t *testing.T, pkgFolder string, update bool) (client *http.C
delete(i.Request.Headers, "x-auth-token")
delete(i.Request.Headers, "X-Auth-Token")
delete(i.Request.Headers, "Authorization")

return nil
}, recorder.BeforeSaveHook)

Expand Down
2 changes: 2 additions & 0 deletions internal/cdf/locality.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func getLocality(diff *schema.ResourceDiff, m interface{}) string {
region, _ := meta.ExtractRegion(diff, m)
loc = region.String()
}

return loc
}

Expand Down Expand Up @@ -91,6 +92,7 @@ func LocalityCheck(keys ...string) schema.CustomizeDiffFunc {
}
}
}

return nil
}
}
2 changes: 2 additions & 0 deletions internal/datasource/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func SchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.S
switch v.Type {
case schema.TypeSet:
dv.Set = v.Set

fallthrough
case schema.TypeList:
// List & Set types are generally used for 2 cases:
Expand All @@ -70,6 +71,7 @@ func SchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.S
}
ds[k] = dv
}

return ds
}

Expand Down
4 changes: 4 additions & 0 deletions internal/datasource/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, err
if foundFlag {
// More than one element found with the same search name
var zero T

return zero, fmt.Errorf("multiple elements found with the name %s", searchName)
}
found = elem
Expand All @@ -27,6 +28,7 @@ func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, err

if !foundFlag {
var zero T

return zero, fmt.Errorf("no element found with the name %s", searchName)
}

Expand All @@ -51,6 +53,7 @@ func SingularDataSourceFindError(resourceType string, err error) error {
// retry.NotFoundError.
func notFound(err error) bool {
var e *retry.NotFoundError // nosemgrep:ci.is-not-found-error

return errors.As(err, &e)
}

Expand All @@ -65,6 +68,7 @@ func (e *TooManyResultsError) Error() string {

func (e *TooManyResultsError) Is(err error) bool {
_, ok := err.(*TooManyResultsError) //nolint:errorlint // Explicitly does *not* match down the error tree

return ok
}

Expand Down
2 changes: 2 additions & 0 deletions internal/dsf/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func Duration(_, oldValue, newValue string, _ *schema.ResourceData) bool {
if err1 != nil || err2 != nil {
return false
}

return d1 == d2
}

Expand All @@ -27,5 +28,6 @@ func TimeRFC3339(_, oldValue, newValue string, _ *schema.ResourceData) bool {
if err1 != nil || err2 != nil {
return false
}

return t1.Equal(t2)
}
5 changes: 5 additions & 0 deletions internal/httperrors/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,35 @@ func IsHTTPCodeError(err error, statusCode int) bool {
if errors.As(err, &responseError) && responseError.StatusCode == statusCode {
return true
}

return false
}

// Is404 returns true if err is an HTTP 404 error
func Is404(err error) bool {
notFoundError := &scw.ResourceNotFoundError{}

return IsHTTPCodeError(err, http.StatusNotFound) || errors.As(err, &notFoundError)
}

func Is412(err error) bool {
preConditionFailedError := &scw.PreconditionFailedError{}

return IsHTTPCodeError(err, http.StatusPreconditionFailed) || errors.As(err, &preConditionFailedError)
}

// Is403 returns true if err is an HTTP 403 error
func Is403(err error) bool {
permissionsDeniedError := &scw.PermissionsDeniedError{}

return IsHTTPCodeError(err, http.StatusForbidden) || errors.As(err, &permissionsDeniedError)
}

// Is409 return true is err is an HTTP 409 error
func Is409(err error) bool {
// check transient error
transientStateError := &scw.TransientStateError{}

return IsHTTPCodeError(err, http.StatusConflict) || errors.As(err, &transientStateError)
}

Expand Down
2 changes: 2 additions & 0 deletions internal/locality/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ func ExpandID(id interface{}) string {
if err != nil {
return id.(string)
}

return ID
}

Expand All @@ -18,5 +19,6 @@ func ExpandIDs(data interface{}) []string {
expandedID := ExpandID(s.(string))
expandedIDs = append(expandedIDs, expandedID)
}

return expandedIDs
}
3 changes: 3 additions & 0 deletions internal/locality/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func ParseLocalizedID(localizedID string) (locality, id string, err error) {
if len(tab) != 2 {
return "", localizedID, fmt.Errorf("cant parse localized id: %s", localizedID)
}

return tab[0], tab[1], nil
}

Expand All @@ -20,6 +21,7 @@ func ParseLocalizedNestedID(localizedID string) (locality string, innerID, outer
if len(tab) < 3 {
return "", "", localizedID, fmt.Errorf("cant parse localized id: %s", localizedID)
}

return tab[0], tab[1], strings.Join(tab[2:], "/"), nil
}

Expand Down Expand Up @@ -53,5 +55,6 @@ func CompareLocalities(loc1, loc2 string) bool {
if strings.HasPrefix(loc1, loc2) || strings.HasPrefix(loc2, loc1) {
return true
}

return false
}
3 changes: 3 additions & 0 deletions internal/locality/regional/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func ParseNestedID(regionalNestedID string) (region scw.Region, outerID, innerID
}

region, err = scw.ParseRegion(loc)

return
}

Expand All @@ -63,6 +64,7 @@ func ParseID(regionalID string) (region scw.Region, id string, err error) {
}

region, err = scw.ParseRegion(loc)

return
}

Expand All @@ -74,5 +76,6 @@ func NewRegionalIDs(region scw.Region, ids []string) []string {
for i, id := range ids {
flattenedIDs[i] = NewIDString(region, id)
}

return flattenedIDs
}
1 change: 1 addition & 0 deletions internal/locality/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func ValidateStringInSliceWithWarning(correctValues []string, field string) sche
AttributePath: path,
})
}

return res
}
}
2 changes: 2 additions & 0 deletions internal/locality/zonal/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func ParseID(zonedID string) (zone scw.Zone, id string, err error) {
}

zone, err = scw.ParseZone(rawZone)

return
}

Expand All @@ -68,5 +69,6 @@ func ParseNestedID(zonedNestedID string) (zone scw.Zone, outerID, innerID string
}

zone, err = scw.ParseZone(rawZone)

return
}
Loading
Loading