-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jwt transport: fix retry on unauthorized from CAPI(#3006)
- Loading branch information
Showing
3 changed files
with
98 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package apiclient | ||
|
||
type StatusCodeConfig struct { | ||
MaxAttempts int | ||
Backoff bool | ||
InvalidateToken bool | ||
} | ||
|
||
type RetryConfig struct { | ||
StatusCodeConfig map[int]StatusCodeConfig | ||
} | ||
|
||
type RetryConfigOption func(*RetryConfig) | ||
|
||
func NewRetryConfig(options ...RetryConfigOption) *RetryConfig { | ||
rc := &RetryConfig{ | ||
StatusCodeConfig: make(map[int]StatusCodeConfig), | ||
} | ||
for _, opt := range options { | ||
opt(rc) | ||
} | ||
return rc | ||
} | ||
|
||
func WithStatusCodeConfig(statusCode int, maxAttempts int, backOff bool, invalidateToken bool) RetryConfigOption { | ||
return func(rc *RetryConfig) { | ||
rc.StatusCodeConfig[statusCode] = StatusCodeConfig{ | ||
MaxAttempts: maxAttempts, | ||
Backoff: backOff, | ||
InvalidateToken: invalidateToken, | ||
} | ||
} | ||
} |