mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-03 15:02:35 +02:00
chore(vault): custom retry check function (#4475)
* vault retry check function --------- Co-authored-by: I557621 <jordi.van.liempt@sap.com>
This commit is contained in:
parent
4c9dd41cbc
commit
2ab1e2a1bc
@ -1,8 +1,10 @@
|
||||
package vault
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -41,6 +43,25 @@ func NewClient(config *Config, token string) (Client, error) {
|
||||
return Client{}, err
|
||||
}
|
||||
|
||||
client.SetMinRetryWait(time.Second * 3)
|
||||
client.SetMaxRetryWait(time.Second * 5)
|
||||
client.SetCheckRetry(func(ctx context.Context, resp *http.Response, err error) (bool, error) {
|
||||
if resp != nil {
|
||||
log.Entry().Infoln("Vault retry: ", resp.Status, resp.StatusCode, err)
|
||||
} else {
|
||||
log.Entry().Infoln("Vault retry: ", err)
|
||||
}
|
||||
|
||||
retry, err := api.DefaultRetryPolicy(ctx, resp, err)
|
||||
if err != nil || retry {
|
||||
return true, nil
|
||||
}
|
||||
if resp != nil && resp.StatusCode >= 400 {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
|
||||
if config.Namespace != "" {
|
||||
client.SetNamespace(config.Namespace)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user