mirror of
https://github.com/hauler-dev/hauler.git
synced 2026-05-08 10:17:02 +00:00
* remove oras from hauler Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * remove cosign fork and use upstream cosign for verification Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * added support for oci referrers Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * updated README.md projects list Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * updates for copilot PR review Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * bug fix for unsafe type assertions Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * bug fix for http getter and dead code Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * fixes for more clarity and better error handling Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * bug fix for resource leaks and unchecked errors Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * bug fix for rewrite logic for docker.io images due to cosign removal Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * bug fix for sigs and referrers Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * bug fix for index.json missing mediatype Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * bug fix to make sure manifest.json doesnt include anything other than actual container images Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> --------- Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com>
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package retry
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"hauler.dev/go/hauler/internal/flags"
|
|
"hauler.dev/go/hauler/pkg/consts"
|
|
"hauler.dev/go/hauler/pkg/log"
|
|
)
|
|
|
|
// Operation retries the given operation according to the retry settings in rso/ro.
|
|
func Operation(ctx context.Context, rso *flags.StoreRootOpts, ro *flags.CliRootOpts, operation func() error) error {
|
|
l := log.FromContext(ctx)
|
|
|
|
if !ro.IgnoreErrors {
|
|
if os.Getenv(consts.HaulerIgnoreErrors) == "true" {
|
|
ro.IgnoreErrors = true
|
|
}
|
|
}
|
|
|
|
retries := rso.Retries
|
|
if retries <= 0 {
|
|
retries = consts.DefaultRetries
|
|
}
|
|
|
|
for attempt := 1; attempt <= retries; attempt++ {
|
|
err := operation()
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
|
|
isTlogErr := strings.HasPrefix(err.Error(), "function execution failed: no matching signatures: rekor client not provided for online verification")
|
|
if ro.IgnoreErrors {
|
|
if isTlogErr {
|
|
l.Warnf("warning (attempt %d/%d)... failed tlog verification", attempt, retries)
|
|
} else {
|
|
l.Warnf("warning (attempt %d/%d)... %v", attempt, retries, err)
|
|
}
|
|
} else {
|
|
if isTlogErr {
|
|
l.Errorf("error (attempt %d/%d)... failed tlog verification", attempt, retries)
|
|
} else {
|
|
l.Errorf("error (attempt %d/%d)... %v", attempt, retries, err)
|
|
}
|
|
}
|
|
|
|
if attempt < retries {
|
|
time.Sleep(time.Second * consts.RetriesInterval)
|
|
}
|
|
}
|
|
|
|
return fmt.Errorf("operation unsuccessful after %d attempts", retries)
|
|
}
|