Files
kubescape/downloader/main.go
Ruslan Semagin fe7dad4560 Refactor: propagate context from main to avoid redundant context creation
- Introduced a single context in main() to handle interrupt signals (os.Interrupt, syscall.SIGTERM).
- Removed repetitive context creation in the program by reusing the propagated context.
- Improved code readability and maintainability by centralizing context management.
- Ensured consistent handling of graceful shutdown across the program.

Signed-off-by: Ruslan Semagin <pixel.365.24@gmail.com>
2025-02-11 19:52:48 +03:00

25 lines
712 B
Go

package main
import (
"context"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v3/core/core"
metav1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
)
func main() {
ctx := context.TODO()
ks := core.NewKubescape(ctx)
downloads := []metav1.DownloadInfo{
{Target: "artifacts"}, // download all artifacts
{Target: "framework", Identifier: "security"}, // force add the "security" framework
}
for _, download := range downloads {
if err := ks.Download(&download); err != nil {
logger.L().Error("failed to download artifact", helpers.Error(err), helpers.String("target", download.Target))
}
}
}