zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/pkg/extensions/scrub/scrub.go (about) 1 //go:build scrub 2 // +build scrub 3 4 package scrub 5 6 import ( 7 "context" 8 "fmt" 9 "path" 10 11 "zotregistry.io/zot/pkg/log" 12 "zotregistry.io/zot/pkg/storage" 13 storageTypes "zotregistry.io/zot/pkg/storage/types" 14 ) 15 16 // Scrub Extension for repo... 17 func RunScrubRepo(ctx context.Context, imgStore storageTypes.ImageStore, repo string, log log.Logger) error { 18 execMsg := fmt.Sprintf("executing scrub to check manifest/blob integrity for %s", path.Join(imgStore.RootDir(), repo)) 19 log.Info().Msg(execMsg) 20 21 results, err := storage.CheckRepo(ctx, repo, imgStore) 22 if err != nil { 23 errMessage := fmt.Sprintf("error while running scrub for %s", path.Join(imgStore.RootDir(), repo)) 24 log.Error().Err(err).Msg(errMessage) 25 log.Info().Msg(fmt.Sprintf("scrub unsuccessfully completed for %s", path.Join(imgStore.RootDir(), repo))) 26 27 return err 28 } 29 30 for _, result := range results { 31 if result.Status == "ok" { 32 log.Info(). 33 Str("image", result.ImageName). 34 Str("tag", result.Tag). 35 Str("status", result.Status). 36 Msg("scrub: blobs/manifest ok") 37 } else { 38 log.Warn(). 39 Str("image", result.ImageName). 40 Str("tag", result.Tag). 41 Str("status", result.Status). 42 Str("affected blob", result.AffectedBlob). 43 Str("error", result.Error). 44 Msg("scrub: blobs/manifest affected") 45 } 46 } 47 48 log.Info().Msg(fmt.Sprintf("scrub successfully completed for %s", path.Join(imgStore.RootDir(), repo))) 49 50 return nil 51 } 52 53 type Task struct { 54 imgStore storageTypes.ImageStore 55 repo string 56 log log.Logger 57 } 58 59 func NewTask(imgStore storageTypes.ImageStore, repo string, log log.Logger) *Task { 60 return &Task{imgStore, repo, log} 61 } 62 63 func (scrubT *Task) DoWork(ctx context.Context) error { 64 return RunScrubRepo(ctx, scrubT.imgStore, scrubT.repo, scrubT.log) //nolint: contextcheck 65 }