diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index a5a90d5..95b98db 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,10 +3,10 @@ id: b81e5def-5b1e-4753-ae7c-0efccc2e6f61 management: docChecksum: 621f79fe092199d80a95ca5aa0238ebc docVersion: 0.0.1 - speakeasyVersion: 1.441.0 - generationVersion: 2.460.1 - releaseVersion: 0.1.7 - configChecksum: db304f60e3a64fc47b514a7de5d55c5b + speakeasyVersion: 1.444.4 + generationVersion: 2.461.4 + releaseVersion: 0.1.8 + configChecksum: df33a88d43c66b96ed2dbd72421eaee2 features: go: additionalDependencies: 0.1.0 @@ -25,7 +25,7 @@ features: nameOverrides: 2.81.2 nullables: 0.1.0 responseFormat: 0.1.2 - retries: 2.83.0 + retries: 2.83.1 sdkHooks: 0.1.0 tests: 0.6.0 unions: 2.85.10 diff --git a/acls.go b/acls.go index e9c3347..97b4d21 100644 --- a/acls.go +++ b/acls.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -109,7 +109,11 @@ func (s *ACLs) ListACL(ctx context.Context, request operations.ListACLRequest, o req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -317,7 +321,11 @@ func (s *ACLs) ListACLWithConsumer(ctx context.Context, request operations.ListA req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -506,7 +514,11 @@ func (s *ACLs) CreateACLWithConsumer(ctx context.Context, request operations.Cre req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -689,7 +701,11 @@ func (s *ACLs) DeleteACLWithConsumer(ctx context.Context, request operations.Del req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -852,7 +868,11 @@ func (s *ACLs) GetACLWithConsumer(ctx context.Context, request operations.GetACL req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1043,7 +1063,11 @@ func (s *ACLs) UpsertACLWithConsumer(ctx context.Context, request operations.Ups req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/apikeys.go b/apikeys.go index 0babb90..20868f1 100644 --- a/apikeys.go +++ b/apikeys.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -109,7 +109,11 @@ func (s *APIKeys) ListKeyAuthWithConsumer(ctx context.Context, request operation req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -298,7 +302,11 @@ func (s *APIKeys) CreateKeyAuthWithConsumer(ctx context.Context, request operati req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -481,7 +489,11 @@ func (s *APIKeys) DeleteKeyAuthWithConsumer(ctx context.Context, request operati req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -644,7 +656,11 @@ func (s *APIKeys) GetKeyAuthWithConsumer(ctx context.Context, request operations req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -835,7 +851,11 @@ func (s *APIKeys) UpsertKeyAuthWithConsumer(ctx context.Context, request operati req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1022,7 +1042,11 @@ func (s *APIKeys) ListKeyAuth(ctx context.Context, request operations.ListKeyAut req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/authentication.go b/authentication.go index 2c254d4..ac3c7a1 100644 --- a/authentication.go +++ b/authentication.go @@ -10,7 +10,7 @@ import ( "github.com/Kong/sdk-konnect-go/internal/utils" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -118,7 +118,11 @@ func (s *Authentication) AuthenticateSso(ctx context.Context, organizationLoginP req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/authsettings.go b/authsettings.go index 0100d48..b4b5e9e 100644 --- a/authsettings.go +++ b/authsettings.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -111,7 +111,11 @@ func (s *AuthSettings) GetAuthenticationSettings(ctx context.Context, opts ...op req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -326,7 +330,11 @@ func (s *AuthSettings) UpdateAuthenticationSettings(ctx context.Context, request req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -558,7 +566,11 @@ func (s *AuthSettings) GetIdpConfiguration(ctx context.Context, opts ...operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -836,7 +848,11 @@ func (s *AuthSettings) UpdateIdpConfiguration(ctx context.Context, request *comp req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1078,7 +1094,11 @@ func (s *AuthSettings) GetTeamGroupMappings(ctx context.Context, pageSize *int64 req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1340,7 +1360,11 @@ func (s *AuthSettings) PatchTeamGroupMappings(ctx context.Context, request *comp req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1597,7 +1621,11 @@ func (s *AuthSettings) UpdateIdpTeamMappings(ctx context.Context, request *compo req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1878,7 +1906,11 @@ func (s *AuthSettings) GetIdpTeamMappings(ctx context.Context, pageSize *int64, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/basicauthcredentials.go b/basicauthcredentials.go index 06e0ba8..8491ad4 100644 --- a/basicauthcredentials.go +++ b/basicauthcredentials.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -109,7 +109,11 @@ func (s *BasicAuthCredentials) ListBasicAuth(ctx context.Context, request operat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -317,7 +321,11 @@ func (s *BasicAuthCredentials) ListBasicAuthWithConsumer(ctx context.Context, re req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -506,7 +514,11 @@ func (s *BasicAuthCredentials) CreateBasicAuthWithConsumer(ctx context.Context, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -689,7 +701,11 @@ func (s *BasicAuthCredentials) DeleteBasicAuthWithConsumer(ctx context.Context, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -852,7 +868,11 @@ func (s *BasicAuthCredentials) GetBasicAuthWithConsumer(ctx context.Context, req req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1043,7 +1063,11 @@ func (s *BasicAuthCredentials) UpsertBasicAuthWithConsumer(ctx context.Context, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/cacertificates.go b/cacertificates.go index 5c3595d..242d681 100644 --- a/cacertificates.go +++ b/cacertificates.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -111,7 +111,11 @@ func (s *CACertificates) ListCaCertificate(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -326,7 +330,11 @@ func (s *CACertificates) CreateCaCertificate(ctx context.Context, controlPlaneID req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -535,7 +543,11 @@ func (s *CACertificates) DeleteCaCertificate(ctx context.Context, controlPlaneID req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -724,7 +736,11 @@ func (s *CACertificates) GetCaCertificate(ctx context.Context, caCertificateID s req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -936,7 +952,11 @@ func (s *CACertificates) UpsertCaCertificate(ctx context.Context, request operat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/certificates.go b/certificates.go index e027f07..5ceb2d8 100644 --- a/certificates.go +++ b/certificates.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -114,7 +114,11 @@ func (s *Certificates) ListCertificate(ctx context.Context, request operations.L req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -329,7 +333,11 @@ func (s *Certificates) CreateCertificate(ctx context.Context, controlPlaneID str req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -538,7 +546,11 @@ func (s *Certificates) DeleteCertificate(ctx context.Context, controlPlaneID str req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -727,7 +739,11 @@ func (s *Certificates) GetCertificate(ctx context.Context, certificateID string, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -939,7 +955,11 @@ func (s *Certificates) UpsertCertificate(ctx context.Context, request operations req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/consumergroups.go b/consumergroups.go index e6b3a4f..f6fc337 100644 --- a/consumergroups.go +++ b/consumergroups.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -111,7 +111,11 @@ func (s *ConsumerGroups) ListConsumerGroup(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -326,7 +330,11 @@ func (s *ConsumerGroups) CreateConsumerGroup(ctx context.Context, controlPlaneID req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -535,7 +543,11 @@ func (s *ConsumerGroups) DeleteConsumerGroup(ctx context.Context, controlPlaneID req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -724,7 +736,11 @@ func (s *ConsumerGroups) GetConsumerGroup(ctx context.Context, consumerGroupID s req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -936,7 +952,11 @@ func (s *ConsumerGroups) UpsertConsumerGroup(ctx context.Context, request operat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1144,7 +1164,11 @@ func (s *ConsumerGroups) ListConsumersForConsumerGroup(ctx context.Context, requ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1333,7 +1357,11 @@ func (s *ConsumerGroups) AddConsumerToGroup(ctx context.Context, request operati req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1516,7 +1544,11 @@ func (s *ConsumerGroups) RemoveConsumerFromGroup(ctx context.Context, request op req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1683,7 +1715,11 @@ func (s *ConsumerGroups) ListConsumerGroupsForConsumer(ctx context.Context, requ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1872,7 +1908,11 @@ func (s *ConsumerGroups) AddConsumerToSpecificConsumerGroup(ctx context.Context, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -2055,7 +2095,11 @@ func (s *ConsumerGroups) RemoveConsumerFromConsumerGroup(ctx context.Context, re req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/consumers.go b/consumers.go index f00f5df..a924d3e 100644 --- a/consumers.go +++ b/consumers.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -111,7 +111,11 @@ func (s *Consumers) ListConsumer(ctx context.Context, request operations.ListCon req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -326,7 +330,11 @@ func (s *Consumers) CreateConsumer(ctx context.Context, controlPlaneID string, c req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -535,7 +543,11 @@ func (s *Consumers) DeleteConsumer(ctx context.Context, controlPlaneID string, c req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -724,7 +736,11 @@ func (s *Consumers) GetConsumer(ctx context.Context, consumerID string, controlP req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -936,7 +952,11 @@ func (s *Consumers) UpsertConsumer(ctx context.Context, request operations.Upser req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/controlplanegroups.go b/controlplanegroups.go index 3fb9888..df9f264 100644 --- a/controlplanegroups.go +++ b/controlplanegroups.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -109,7 +109,11 @@ func (s *ControlPlaneGroups) GetControlPlanesIDGroupMemberStatus(ctx context.Con req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -401,7 +405,11 @@ func (s *ControlPlaneGroups) GetControlPlanesIDGroupMemberships(ctx context.Cont req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -700,7 +708,11 @@ func (s *ControlPlaneGroups) PutControlPlanesIDGroupMemberships(ctx context.Cont req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -979,7 +991,11 @@ func (s *ControlPlaneGroups) PostControlPlanesIDGroupMembershipsAdd(ctx context. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1258,7 +1274,11 @@ func (s *ControlPlaneGroups) PostControlPlanesIDGroupMembershipsRemove(ctx conte req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1530,7 +1550,11 @@ func (s *ControlPlaneGroups) GetControlPlanesIDGroupStatus(ctx context.Context, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/controlplanes.go b/controlplanes.go index 0cf9fb2..2fb92fe 100644 --- a/controlplanes.go +++ b/controlplanes.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -110,7 +110,11 @@ func (s *ControlPlanes) ListControlPlanes(ctx context.Context, request operation req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -383,7 +387,11 @@ func (s *ControlPlanes) CreateControlPlane(ctx context.Context, request componen req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -696,7 +704,11 @@ func (s *ControlPlanes) GetControlPlane(ctx context.Context, id string, opts ... req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -995,7 +1007,11 @@ func (s *ControlPlanes) UpdateControlPlane(ctx context.Context, id string, updat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1308,7 +1324,11 @@ func (s *ControlPlanes) DeleteControlPlane(ctx context.Context, id string, opts req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/custompluginschemas.go b/custompluginschemas.go index 12e7b6b..15a9051 100644 --- a/custompluginschemas.go +++ b/custompluginschemas.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -110,7 +110,11 @@ func (s *CustomPluginSchemas) ListPluginSchemas(ctx context.Context, request ope req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -367,7 +371,11 @@ func (s *CustomPluginSchemas) CreatePluginSchemas(ctx context.Context, controlPl req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -639,7 +647,11 @@ func (s *CustomPluginSchemas) GetPluginSchema(ctx context.Context, controlPlaneI req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -890,7 +902,11 @@ func (s *CustomPluginSchemas) DeletePluginSchemas(ctx context.Context, controlPl req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1122,7 +1138,11 @@ func (s *CustomPluginSchemas) UpdatePluginSchemas(ctx context.Context, request o req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/dpcertificates.go b/dpcertificates.go index 053935f..5d2a9a2 100644 --- a/dpcertificates.go +++ b/dpcertificates.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -110,7 +110,11 @@ func (s *DPCertificates) ListDpClientCertificates(ctx context.Context, controlPl req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -304,7 +308,11 @@ func (s *DPCertificates) CreateDataplaneCertificate(ctx context.Context, control req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -492,7 +500,11 @@ func (s *DPCertificates) GetDataplaneCertificate(ctx context.Context, controlPla req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -680,7 +692,11 @@ func (s *DPCertificates) DeleteDataplaneCertificate(ctx context.Context, control req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/dpnodes.go b/dpnodes.go index 2d15258..ee3dcd6 100644 --- a/dpnodes.go +++ b/dpnodes.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -110,7 +110,11 @@ func (s *DPNodes) GetExpectedConfigHash(ctx context.Context, controlPlaneID stri req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -297,7 +301,11 @@ func (s *DPNodes) ListDataplaneNodes(ctx context.Context, request operations.Lis req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -484,7 +492,11 @@ func (s *DPNodes) GetNodesNodeID(ctx context.Context, request operations.GetNode req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -672,7 +684,11 @@ func (s *DPNodes) DeleteNodesNodeID(ctx context.Context, nodeID string, controlP req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -839,7 +855,11 @@ func (s *DPNodes) GetNodesEol(ctx context.Context, request operations.GetNodesEo req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/go.mod b/go.mod index 8442e3b..43de157 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/Kong/sdk-konnect-go go 1.20 require ( - github.com/cenkalti/backoff/v4 v4.2.0 github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 github.com/stretchr/testify v1.10.0 ) diff --git a/go.sum b/go.sum index 7f63c8a..ed814a8 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= -github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw= diff --git a/hmacauthcredentials.go b/hmacauthcredentials.go index f97535f..5faba39 100644 --- a/hmacauthcredentials.go +++ b/hmacauthcredentials.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -109,7 +109,11 @@ func (s *HMACAuthCredentials) ListHmacAuthWithConsumer(ctx context.Context, requ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -298,7 +302,11 @@ func (s *HMACAuthCredentials) CreateHmacAuthWithConsumer(ctx context.Context, re req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -481,7 +489,11 @@ func (s *HMACAuthCredentials) DeleteHmacAuthWithConsumer(ctx context.Context, re req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -644,7 +656,11 @@ func (s *HMACAuthCredentials) GetHmacAuthWithConsumer(ctx context.Context, reque req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -835,7 +851,11 @@ func (s *HMACAuthCredentials) UpsertHmacAuthWithConsumer(ctx context.Context, re req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1022,7 +1042,11 @@ func (s *HMACAuthCredentials) ListHmacAuth(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/impersonationsettings.go b/impersonationsettings.go index 2e992a3..bb79d9e 100644 --- a/impersonationsettings.go +++ b/impersonationsettings.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -111,7 +111,11 @@ func (s *ImpersonationSettings) GetImpersonationSettings(ctx context.Context, op req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -347,7 +351,11 @@ func (s *ImpersonationSettings) UpdateImpersonationSettings(ctx context.Context, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/internal/utils/retries.go b/internal/utils/retries.go index 033b82a..4901096 100644 --- a/internal/utils/retries.go +++ b/internal/utils/retries.go @@ -7,7 +7,8 @@ import ( "errors" "fmt" "github.com/Kong/sdk-konnect-go/retry" - "github.com/cenkalti/backoff/v4" + "math" + "math/rand" "net/http" "net/url" "strconv" @@ -15,8 +16,6 @@ import ( "time" ) -var errRequestFailed = errors.New("request failed") - // Deprecated: Use retry.BackoffStrategy instead. type BackoffStrategy = retry.BackoffStrategy @@ -28,34 +27,27 @@ type Retries struct { StatusCodes []string } -func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)) (*http.Response, error) { +func Retry(ctx context.Context, r Retries, operation func() (*http.Response, error)) (*http.Response, error) { switch r.Config.Strategy { case "backoff": if r.Config.Backoff == nil { - return action() + return operation() } - config := backoff.NewExponentialBackOff() - config.InitialInterval = time.Duration(r.Config.Backoff.InitialInterval) * time.Millisecond - config.MaxInterval = time.Duration(r.Config.Backoff.MaxInterval) * time.Millisecond - config.Multiplier = r.Config.Backoff.Exponent - config.MaxElapsedTime = time.Duration(r.Config.Backoff.MaxElapsedTime) * time.Millisecond - config.Reset() - var resp *http.Response - err := backoff.Retry(func() error { + err := retryWithBackoff(ctx, r.Config.Backoff, func() error { if resp != nil { resp.Body.Close() } select { case <-ctx.Done(): - return backoff.Permanent(ctx.Err()) + return retry.Permanent(ctx.Err()) default: } - res, err := action() + res, err := operation() if err != nil { urlError := new(url.Error) if errors.As(err, &urlError) { @@ -64,7 +56,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) } } - return backoff.Permanent(err) + return retry.Permanent(err) } resp = res if res == nil { @@ -81,7 +73,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) s := res.StatusCode / 100 if s >= codeRange && s < codeRange+1 { - return errRequestFailed + return retry.TemporaryFromResponse("request failed", res) } } else { parsedCode, err := strconv.Atoi(code) @@ -90,7 +82,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) } if res.StatusCode == parsedCode { - return errRequestFailed + return retry.TemporaryFromResponse("request failed", res) } } } @@ -98,13 +90,131 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) resp = res return nil - }, config) - if err != nil && !errors.Is(err, errRequestFailed) { + }) + + var tempErr *retry.TemporaryError + if err != nil && !errors.As(err, &tempErr) { return nil, err } return resp, nil default: - return action() + return operation() + } +} + +func retryWithBackoff(ctx context.Context, s *retry.BackoffStrategy, operation func() error) error { + var ( + err error + next time.Duration + attempt int + start = time.Now() + maxElapsedTime = time.Duration(s.MaxElapsedTime) * time.Millisecond + ) + + timer := &defaultTimer{} + defer func() { + timer.Stop() + }() + + for { + err = operation() + if err == nil { + return nil + } + + var permanent *retry.PermanentError + if errors.As(err, &permanent) { + return permanent.Unwrap() + } + + if time.Since(start) >= maxElapsedTime { + return err + } + + var temporary *retry.TemporaryError + if errors.As(err, &temporary) { + next = temporary.RetryAfter() + } + + if next <= 0 { + next = nextInterval(s, attempt) + } + + timer.Start(next) + + select { + case <-ctx.Done(): + return ctx.Err() + case <-timer.C(): + } + + attempt += 1 } } + +type Timer interface { + Start(duration time.Duration) + Stop() + C() <-chan time.Time +} + +// defaultTimer implements Timer interface using time.Timer +type defaultTimer struct { + timer *time.Timer +} + +// C returns the timers channel which receives the current time when the timer fires. +func (t *defaultTimer) C() <-chan time.Time { + return t.timer.C +} + +// Start starts the timer to fire after the given duration +func (t *defaultTimer) Start(duration time.Duration) { + if t.timer == nil { + t.timer = time.NewTimer(duration) + return + } + + if !t.timer.Stop() { + select { + case <-t.timer.C: + default: + } + } + + t.timer.Reset(duration) +} + +// Stop is called when the timer is not used anymore and resources may be freed. +func (t *defaultTimer) Stop() { + if t.timer != nil { + t.timer.Stop() + } +} + +func nextInterval(s *retry.BackoffStrategy, attempt int) time.Duration { + initialInterval := float64(time.Duration(s.InitialInterval) * time.Millisecond) + maxInterval := float64(time.Duration(s.MaxInterval) * time.Millisecond) + exponent := s.Exponent + jitterFactor := float64(0.25) + + interval := initialInterval * math.Pow(float64(attempt+1), exponent) + + jitter := rand.Float64() * jitterFactor * interval + if rand.Float64() < 0.5 { + jitter = -1 * jitter + } + + interval = interval + jitter + + if interval <= 0 { + interval = initialInterval + } + + if interval > maxInterval { + interval = maxInterval + } + + return time.Duration(interval) +} diff --git a/invites.go b/invites.go index 6d030f2..0021ba7 100644 --- a/invites.go +++ b/invites.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -117,7 +117,11 @@ func (s *Invites) InviteUser(ctx context.Context, request *components.InviteUser req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/jwts.go b/jwts.go index 4d8e858..42bce8c 100644 --- a/jwts.go +++ b/jwts.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -109,7 +109,11 @@ func (s *JWTs) ListJwtWithConsumer(ctx context.Context, request operations.ListJ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -298,7 +302,11 @@ func (s *JWTs) CreateJwtWithConsumer(ctx context.Context, request operations.Cre req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -481,7 +489,11 @@ func (s *JWTs) DeleteJwtWithConsumer(ctx context.Context, request operations.Del req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -644,7 +656,11 @@ func (s *JWTs) GetJwtWithConsumer(ctx context.Context, request operations.GetJwt req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -835,7 +851,11 @@ func (s *JWTs) UpsertJwtWithConsumer(ctx context.Context, request operations.Ups req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1022,7 +1042,11 @@ func (s *JWTs) ListJwt(ctx context.Context, request operations.ListJwtRequest, o req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/keys.go b/keys.go index 5033a31..7006d43 100644 --- a/keys.go +++ b/keys.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -110,7 +110,11 @@ func (s *Keys) ListKeyWithKeySet(ctx context.Context, request operations.ListKey req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -299,7 +303,11 @@ func (s *Keys) CreateKeyWithKeySet(ctx context.Context, request operations.Creat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -482,7 +490,11 @@ func (s *Keys) DeleteKeyWithKeySet(ctx context.Context, request operations.Delet req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -645,7 +657,11 @@ func (s *Keys) GetKeyWithKeySet(ctx context.Context, request operations.GetKeyWi req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -836,7 +852,11 @@ func (s *Keys) UpsertKeyWithKeySet(ctx context.Context, request operations.Upser req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1023,7 +1043,11 @@ func (s *Keys) ListKey(ctx context.Context, request operations.ListKeyRequest, o req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1238,7 +1262,11 @@ func (s *Keys) CreateKey(ctx context.Context, controlPlaneID string, key compone req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1447,7 +1475,11 @@ func (s *Keys) DeleteKey(ctx context.Context, controlPlaneID string, keyID strin req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1636,7 +1668,11 @@ func (s *Keys) GetKey(ctx context.Context, keyID string, controlPlaneID string, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1848,7 +1884,11 @@ func (s *Keys) UpsertKey(ctx context.Context, request operations.UpsertKeyReques req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/keysets.go b/keysets.go index 1339496..4845f40 100644 --- a/keysets.go +++ b/keysets.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -110,7 +110,11 @@ func (s *KeySets) ListKeySet(ctx context.Context, request operations.ListKeySetR req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -325,7 +329,11 @@ func (s *KeySets) CreateKeySet(ctx context.Context, controlPlaneID string, keySe req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -534,7 +542,11 @@ func (s *KeySets) DeleteKeySet(ctx context.Context, controlPlaneID string, keySe req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -723,7 +735,11 @@ func (s *KeySets) GetKeySet(ctx context.Context, keySetID string, controlPlaneID req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -935,7 +951,11 @@ func (s *KeySets) UpsertKeySet(ctx context.Context, request operations.UpsertKey req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/me.go b/me.go index c46e58b..faf92d0 100644 --- a/me.go +++ b/me.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -111,7 +111,11 @@ func (s *Me) GetOrganizationsMe(ctx context.Context, opts ...operations.Option) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -320,7 +324,11 @@ func (s *Me) GetUsersMe(ctx context.Context, opts ...operations.Option) (*operat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/mtlsauthcredentials.go b/mtlsauthcredentials.go index 4ef73d4..edd3892 100644 --- a/mtlsauthcredentials.go +++ b/mtlsauthcredentials.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -109,7 +109,11 @@ func (s *MTLSAuthCredentials) ListMtlsAuthWithConsumer(ctx context.Context, requ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -298,7 +302,11 @@ func (s *MTLSAuthCredentials) CreateMtlsAuthWithConsumer(ctx context.Context, re req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -481,7 +489,11 @@ func (s *MTLSAuthCredentials) DeleteMtlsAuthWithConsumer(ctx context.Context, re req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -644,7 +656,11 @@ func (s *MTLSAuthCredentials) GetMtlsAuthWithConsumer(ctx context.Context, reque req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -835,7 +851,11 @@ func (s *MTLSAuthCredentials) UpsertMtlsAuthWithConsumer(ctx context.Context, re req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1022,7 +1042,11 @@ func (s *MTLSAuthCredentials) ListMtlsAuth(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/plugins.go b/plugins.go index ed4376e..0afd9db 100644 --- a/plugins.go +++ b/plugins.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -115,7 +115,11 @@ func (s *Plugins) ListPluginWithConsumerGroup(ctx context.Context, request opera req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -304,7 +308,11 @@ func (s *Plugins) CreatePluginWithConsumerGroup(ctx context.Context, request ope req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -487,7 +495,11 @@ func (s *Plugins) DeletePluginWithConsumerGroup(ctx context.Context, request ope req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -650,7 +662,11 @@ func (s *Plugins) GetPluginWithConsumerGroup(ctx context.Context, request operat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -841,7 +857,11 @@ func (s *Plugins) UpsertPluginWithConsumerGroup(ctx context.Context, request ope req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1028,7 +1048,11 @@ func (s *Plugins) ListPluginWithConsumer(ctx context.Context, request operations req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1217,7 +1241,11 @@ func (s *Plugins) CreatePluginWithConsumer(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1400,7 +1428,11 @@ func (s *Plugins) DeletePluginWithConsumer(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1563,7 +1595,11 @@ func (s *Plugins) GetPluginWithConsumer(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1754,7 +1790,11 @@ func (s *Plugins) UpsertPluginWithConsumer(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1941,7 +1981,11 @@ func (s *Plugins) ListPlugin(ctx context.Context, request operations.ListPluginR req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -2156,7 +2200,11 @@ func (s *Plugins) CreatePlugin(ctx context.Context, controlPlaneID string, plugi req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -2365,7 +2413,11 @@ func (s *Plugins) DeletePlugin(ctx context.Context, controlPlaneID string, plugi req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -2554,7 +2606,11 @@ func (s *Plugins) GetPlugin(ctx context.Context, pluginID string, controlPlaneID req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -2766,7 +2822,11 @@ func (s *Plugins) UpsertPlugin(ctx context.Context, request operations.UpsertPlu req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -2974,7 +3034,11 @@ func (s *Plugins) ListPluginWithRoute(ctx context.Context, request operations.Li req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -3163,7 +3227,11 @@ func (s *Plugins) CreatePluginWithRoute(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -3346,7 +3414,11 @@ func (s *Plugins) DeletePluginWithRoute(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -3509,7 +3581,11 @@ func (s *Plugins) GetPluginWithRoute(ctx context.Context, request operations.Get req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -3700,7 +3776,11 @@ func (s *Plugins) UpsertPluginWithRoute(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -3888,7 +3968,11 @@ func (s *Plugins) FetchPluginSchema(ctx context.Context, pluginName string, cont req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -4075,7 +4159,11 @@ func (s *Plugins) ListPluginWithService(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -4264,7 +4352,11 @@ func (s *Plugins) CreatePluginWithService(ctx context.Context, request operation req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -4447,7 +4539,11 @@ func (s *Plugins) DeletePluginWithService(ctx context.Context, request operation req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -4610,7 +4706,11 @@ func (s *Plugins) GetPluginWithService(ctx context.Context, request operations.G req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -4801,7 +4901,11 @@ func (s *Plugins) UpsertPluginWithService(ctx context.Context, request operation req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/retry/config.go b/retry/config.go index c051b0a..aa4b334 100644 --- a/retry/config.go +++ b/retry/config.go @@ -2,6 +2,15 @@ package retry +import ( + "errors" + "net/http" + "strconv" + "time" +) + +// BackoffStrategy defines the parameters for exponential backoff. This can be +// used to drive a retry loop for example. type BackoffStrategy struct { InitialInterval int MaxInterval int @@ -9,8 +18,128 @@ type BackoffStrategy struct { MaxElapsedTime int } +// Config configures a retry policy. type Config struct { Strategy string Backoff *BackoffStrategy RetryConnectionErrors bool } + +// PermanentError is an error that signals that some operation has terminally +// failed and should not be retried. +type PermanentError struct { + cause error +} + +// Permanent creates a PermanentError that signals to a retry loop that it +// should stop retrying an operation and return the underlying error. +func Permanent(cause error) error { + if IsPermanentError(cause) { + return cause + } + + return &PermanentError{ + cause: cause, + } +} + +func (e *PermanentError) Error() string { + return e.cause.Error() +} + +func (e *PermanentError) Unwrap() error { + return e.cause +} + +// TemporaryError represents a retryable error and signals to a retry loop that +// an operation may be retried with an optional wait interval. +type TemporaryError struct { + wait time.Duration + message string +} + +// Temporary creates a TemporaryError that signals to a retry loop that an +// operation can be retried. The error may also carry details about how long to +// wait before retrying. This wait interval may be used to override the retry +// policy in use. +func Temporary(message string) error { + return &TemporaryError{ + message: message, + } +} + +// TemporaryFromResponse creates a TemporaryError similar to Temporary but +// additionally parses the Retry-After header from a response to determine the +// wait interval before the next retry attempt. +func TemporaryFromResponse(message string, res *http.Response) error { + return &TemporaryError{ + wait: retryIntervalFromResponse(res), + message: message, + } +} + +func (e *TemporaryError) Error() string { + return e.message +} + +// RetryAfter returns the time to wait before retrying the request. The zero +// value should be interpreted by retry loops to mean they should fallback on +// their default policy whether expenonential, constant backoff or something +// else. It does not mean that an operation should be retried immediately. +func (e *TemporaryError) RetryAfter() time.Duration { + return e.wait +} + +func retryIntervalFromResponse(res *http.Response) time.Duration { + if res == nil { + return 0 + } + + retryVal := res.Header.Get("retry-after") + if retryVal == "" { + return 0 + } + + parsedNumber, err := strconv.ParseInt(retryVal, 10, 64) + if err == nil { + if parsedNumber < 0 { + return 0 + } else { + return time.Duration(parsedNumber) * time.Second + } + } + + parsedDate, err := time.Parse(time.RFC1123, retryVal) + if err == nil { + delta := parsedDate.Sub(time.Now()) + if delta < 0 { + return 0 + } else { + return delta + } + } + + return 0 +} + +// IsPermanentError returns true if an error value is or contains a +// PermanentError in its chain of errors. +func IsPermanentError(err error) bool { + if err == nil { + return false + } + + var pe *PermanentError + return errors.As(err, &pe) +} + +// IsTemporaryError returns true if an error value is or contains a +// TemporaryError in its chain of errors. +func IsTemporaryError(err error) bool { + if err == nil { + return false + } + + var pe *TemporaryError + return errors.As(err, &pe) +} diff --git a/roles.go b/roles.go index 1a61265..5c5859d 100644 --- a/roles.go +++ b/roles.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -111,7 +111,11 @@ func (s *Roles) GetPredefinedRoles(ctx context.Context, opts ...operations.Optio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -350,7 +354,11 @@ func (s *Roles) ListTeamRoles(ctx context.Context, teamID string, filter *operat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -633,7 +641,11 @@ func (s *Roles) TeamsAssignRole(ctx context.Context, teamID string, assignRole * req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -931,7 +943,11 @@ func (s *Roles) TeamsRemoveRole(ctx context.Context, teamID string, roleID strin req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1192,7 +1208,11 @@ func (s *Roles) ListUserRoles(ctx context.Context, userID string, filter *operat req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1433,7 +1453,11 @@ func (s *Roles) UsersAssignRole(ctx context.Context, userID string, assignRole * req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1731,7 +1755,11 @@ func (s *Roles) UsersRemoveRole(ctx context.Context, userID string, roleID strin req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/routes.go b/routes.go index 9a4610b..1a16cbb 100644 --- a/routes.go +++ b/routes.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -131,7 +131,11 @@ func (s *Routes) ListRoute(ctx context.Context, request operations.ListRouteRequ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -346,7 +350,11 @@ func (s *Routes) CreateRoute(ctx context.Context, controlPlaneID string, route c req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -555,7 +563,11 @@ func (s *Routes) DeleteRoute(ctx context.Context, controlPlaneID string, routeID req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -744,7 +756,11 @@ func (s *Routes) GetRoute(ctx context.Context, routeID string, controlPlaneID st req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -956,7 +972,11 @@ func (s *Routes) UpsertRoute(ctx context.Context, request operations.UpsertRoute req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1164,7 +1184,11 @@ func (s *Routes) ListRouteWithService(ctx context.Context, request operations.Li req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1353,7 +1377,11 @@ func (s *Routes) CreateRouteWithService(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1536,7 +1564,11 @@ func (s *Routes) DeleteRouteWithService(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1699,7 +1731,11 @@ func (s *Routes) GetRouteWithService(ctx context.Context, request operations.Get req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1890,7 +1926,11 @@ func (s *Routes) UpsertRouteWithService(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/sdk.go b/sdk.go index 08fce1c..887d11a 100644 --- a/sdk.go +++ b/sdk.go @@ -261,9 +261,9 @@ func New(opts ...SDKOption) *SDK { sdkConfiguration: sdkConfiguration{ Language: "go", OpenAPIDocVersion: "0.0.1", - SDKVersion: "0.1.7", - GenVersion: "2.460.1", - UserAgent: "speakeasy-sdk/go 0.1.7 2.460.1 0.0.1 github.com/Kong/sdk-konnect-go", + SDKVersion: "0.1.8", + GenVersion: "2.461.4", + UserAgent: "speakeasy-sdk/go 0.1.8 2.461.4 0.0.1 github.com/Kong/sdk-konnect-go", Hooks: hooks.New(), }, } diff --git a/services.go b/services.go index e2a7f82..dd0a12c 100644 --- a/services.go +++ b/services.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -116,7 +116,11 @@ func (s *Services) ListService(ctx context.Context, request operations.ListServi req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -331,7 +335,11 @@ func (s *Services) CreateService(ctx context.Context, controlPlaneID string, ser req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -540,7 +548,11 @@ func (s *Services) DeleteService(ctx context.Context, controlPlaneID string, ser req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -729,7 +741,11 @@ func (s *Services) GetService(ctx context.Context, serviceID string, controlPlan req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -941,7 +957,11 @@ func (s *Services) UpsertService(ctx context.Context, request operations.UpsertS req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/snis.go b/snis.go index 65af3a0..11d8681 100644 --- a/snis.go +++ b/snis.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -112,7 +112,11 @@ func (s *SNIs) ListSniWithCertificate(ctx context.Context, request operations.Li req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -301,7 +305,11 @@ func (s *SNIs) CreateSniWithCertificate(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -484,7 +492,11 @@ func (s *SNIs) DeleteSniWithCertificate(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -647,7 +659,11 @@ func (s *SNIs) GetSniWithCertificate(ctx context.Context, request operations.Get req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -838,7 +854,11 @@ func (s *SNIs) UpsertSniWithCertificate(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1025,7 +1045,11 @@ func (s *SNIs) ListSni(ctx context.Context, request operations.ListSniRequest, o req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1240,7 +1264,11 @@ func (s *SNIs) CreateSni(ctx context.Context, controlPlaneID string, sni compone req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1449,7 +1477,11 @@ func (s *SNIs) DeleteSni(ctx context.Context, controlPlaneID string, sniID strin req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1638,7 +1670,11 @@ func (s *SNIs) GetSni(ctx context.Context, sniID string, controlPlaneID string, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1850,7 +1886,11 @@ func (s *SNIs) UpsertSni(ctx context.Context, request operations.UpsertSniReques req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/systemaccounts.go b/systemaccounts.go index 7048aee..274c34e 100644 --- a/systemaccounts.go +++ b/systemaccounts.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -115,7 +115,11 @@ func (s *SystemAccounts) GetSystemAccounts(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -353,7 +357,11 @@ func (s *SystemAccounts) PostSystemAccounts(ctx context.Context, request *compon req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -589,7 +597,11 @@ func (s *SystemAccounts) GetSystemAccountsID(ctx context.Context, accountID stri req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -832,7 +844,11 @@ func (s *SystemAccounts) PatchSystemAccountsID(ctx context.Context, accountID st req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1089,7 +1105,11 @@ func (s *SystemAccounts) DeleteSystemAccountsID(ctx context.Context, accountID s req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/systemaccountsaccesstokens.go b/systemaccountsaccesstokens.go index d2d68a5..5ab037c 100644 --- a/systemaccountsaccesstokens.go +++ b/systemaccountsaccesstokens.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -114,7 +114,11 @@ func (s *SystemAccountsAccessTokens) GetSystemAccountIDAccessTokens(ctx context. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -378,7 +382,11 @@ func (s *SystemAccountsAccessTokens) PostSystemAccountsIDAccessTokens(ctx contex req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -636,7 +644,11 @@ func (s *SystemAccountsAccessTokens) GetSystemAccountsIDAccessTokensID(ctx conte req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -874,7 +886,11 @@ func (s *SystemAccountsAccessTokens) PatchSystemAccountsIDAccessTokensID(ctx con req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1132,7 +1148,11 @@ func (s *SystemAccountsAccessTokens) DeleteSystemAccountsIDAccessTokensID(ctx co req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/systemaccountsroles.go b/systemaccountsroles.go index c9f5e42..458acd6 100644 --- a/systemaccountsroles.go +++ b/systemaccountsroles.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -119,7 +119,11 @@ func (s *SystemAccountsRoles) GetSystemAccountsAccountIDAssignedRoles(ctx contex req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -383,7 +387,11 @@ func (s *SystemAccountsRoles) PostSystemAccountsAccountIDAssignedRoles(ctx conte req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -641,7 +649,11 @@ func (s *SystemAccountsRoles) DeleteSystemAccountsAccountIDAssignedRolesRoleID(c req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/systemaccountsteammembership.go b/systemaccountsteammembership.go index 713bbb2..95eef2d 100644 --- a/systemaccountsteammembership.go +++ b/systemaccountsteammembership.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -114,7 +114,11 @@ func (s *SystemAccountsTeamMembership) GetSystemAccountsAccountIDTeams(ctx conte req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -350,7 +354,11 @@ func (s *SystemAccountsTeamMembership) GetTeamsTeamIDSystemAccounts(ctx context. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -593,7 +601,11 @@ func (s *SystemAccountsTeamMembership) PostTeamsTeamIDSystemAccounts(ctx context req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -831,7 +843,11 @@ func (s *SystemAccountsTeamMembership) DeleteTeamsTeamIDSystemAccountsAccountID( req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/targets.go b/targets.go index 26800c7..a81f382 100644 --- a/targets.go +++ b/targets.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -109,7 +109,11 @@ func (s *Targets) ListTargetWithUpstream(ctx context.Context, request operations req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -298,7 +302,11 @@ func (s *Targets) CreateTargetWithUpstream(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -481,7 +489,11 @@ func (s *Targets) DeleteTargetWithUpstream(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -644,7 +656,11 @@ func (s *Targets) GetTargetWithUpstream(ctx context.Context, request operations. req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -835,7 +851,11 @@ func (s *Targets) UpsertTargetWithUpstream(ctx context.Context, request operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/teammembership.go b/teammembership.go index d0b5dda..5d71d91 100644 --- a/teammembership.go +++ b/teammembership.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -114,7 +114,11 @@ func (s *TeamMembership) ListTeamUsers(ctx context.Context, request operations.L req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -355,7 +359,11 @@ func (s *TeamMembership) AddUserToTeam(ctx context.Context, teamID string, addUs req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -592,7 +600,11 @@ func (s *TeamMembership) RemoveUserFromTeam(ctx context.Context, userID string, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -806,7 +818,11 @@ func (s *TeamMembership) ListUserTeams(ctx context.Context, request operations.L req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/teams.go b/teams.go index 72699d9..b1ec343 100644 --- a/teams.go +++ b/teams.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -115,7 +115,11 @@ func (s *Teams) ListTeams(ctx context.Context, request operations.ListTeamsReque req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -351,7 +355,11 @@ func (s *Teams) CreateTeam(ctx context.Context, request *components.CreateTeam, req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -585,7 +593,11 @@ func (s *Teams) GetTeam(ctx context.Context, teamID string, opts ...operations.O req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -826,7 +838,11 @@ func (s *Teams) UpdateTeam(ctx context.Context, teamID string, updateTeam *compo req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -1060,7 +1076,11 @@ func (s *Teams) DeleteTeam(ctx context.Context, teamID string, opts ...operation req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/upstreams.go b/upstreams.go index 17408b8..6c55b24 100644 --- a/upstreams.go +++ b/upstreams.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -113,7 +113,11 @@ func (s *Upstreams) ListUpstream(ctx context.Context, request operations.ListUps req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -328,7 +332,11 @@ func (s *Upstreams) CreateUpstream(ctx context.Context, controlPlaneID string, u req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -537,7 +545,11 @@ func (s *Upstreams) DeleteUpstream(ctx context.Context, controlPlaneID string, u req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -726,7 +738,11 @@ func (s *Upstreams) GetUpstream(ctx context.Context, upstreamID string, controlP req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -938,7 +954,11 @@ func (s *Upstreams) UpsertUpstream(ctx context.Context, request operations.Upser req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/users.go b/users.go index 580857e..e656c1c 100644 --- a/users.go +++ b/users.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" "net/url" ) @@ -115,7 +115,11 @@ func (s *Users) ListUsers(ctx context.Context, request operations.ListUsersReque req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -328,7 +332,11 @@ func (s *Users) GetUser(ctx context.Context, userID string, opts ...operations.O req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -569,7 +577,11 @@ func (s *Users) UpdateUser(ctx context.Context, userID string, updateUser *compo req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -824,7 +836,11 @@ func (s *Users) DeleteUser(ctx context.Context, userID string, opts ...operation req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) diff --git a/vaults.go b/vaults.go index b4342da..4d63461 100644 --- a/vaults.go +++ b/vaults.go @@ -11,7 +11,7 @@ import ( "github.com/Kong/sdk-konnect-go/models/components" "github.com/Kong/sdk-konnect-go/models/operations" "github.com/Kong/sdk-konnect-go/models/sdkerrors" - "github.com/cenkalti/backoff/v4" + "github.com/Kong/sdk-konnect-go/retry" "net/http" ) @@ -116,7 +116,11 @@ func (s *Vaults) ListVault(ctx context.Context, request operations.ListVaultRequ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -331,7 +335,11 @@ func (s *Vaults) CreateVault(ctx context.Context, controlPlaneID string, vault c req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -540,7 +548,11 @@ func (s *Vaults) DeleteVault(ctx context.Context, controlPlaneID string, vaultID req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -729,7 +741,11 @@ func (s *Vaults) GetVault(ctx context.Context, vaultID string, controlPlaneID st req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -941,7 +957,11 @@ func (s *Vaults) UpsertVault(ctx context.Context, request operations.UpsertVault req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req)