github.com/Benchkram/bob@v0.0.0-20220321080157-7c8f3876e225/bobtask/target/verify.go (about) 1 package target 2 3 import ( 4 "github.com/Benchkram/bob/pkg/boblog" 5 ) 6 7 // Verify existence and integrity of targets. 8 // Returns true when no targets defined. 9 func (t *T) Verify() bool { 10 switch t.Type { 11 case Path: 12 return t.verifyFile(t.hash) 13 case Docker: 14 return t.verifyDocker(t.hash) 15 default: 16 return t.verifyFile(t.hash) 17 } 18 } 19 20 func (t *T) verifyFile(groundTruth string) bool { 21 if len(t.Paths) == 0 { 22 return true 23 } 24 25 if t.hash == "" { 26 return true 27 } 28 29 // check plain existence 30 if !t.existsFile() { 31 return false 32 } 33 34 // check integrity by comparing hash 35 hash, err := t.Hash() 36 if err != nil { 37 boblog.Log.Error(err, "Unable to create target hash") 38 return false 39 } 40 41 return hash == groundTruth 42 } 43 44 func (t *T) verifyDocker(groundTruth string) bool { 45 46 if len(t.Paths) == 0 { 47 return true 48 } 49 50 if t.hash == "" { 51 return true 52 } 53 54 // check plain existence 55 if !t.existsDocker() { 56 return false 57 } 58 59 // check integrity by comparing hash 60 hash, err := t.Hash() 61 if err != nil { 62 boblog.Log.Error(err, "Unable to verify target docker image hash") 63 return false 64 } 65 66 return hash == groundTruth 67 }