github.com/datreeio/datree@v1.9.22-rc/pkg/networkValidator/networkValidator.go (about) 1 package networkValidator 2 3 import ( 4 "errors" 5 6 "github.com/datreeio/datree/pkg/utils" 7 ) 8 9 type NetworkValidator struct { 10 isBackendAvailable bool 11 offlineMode string 12 } 13 14 func NewNetworkValidator() *NetworkValidator { 15 return &NetworkValidator{ 16 isBackendAvailable: true, 17 offlineMode: "fail", 18 } 19 } 20 21 func (nv *NetworkValidator) SetOfflineMode(offlineMode string) { 22 nv.offlineMode = offlineMode 23 } 24 25 func (nv *NetworkValidator) IdentifyNetworkError(err error) error { 26 if utils.IsNetworkError(err) { 27 if nv.offlineMode == "fail" { 28 return errors.New("Failed since internet connection refused, you can use the following command to set your config to run offline:\ndatree config set offline local") 29 } 30 nv.isBackendAvailable = false 31 } 32 return nil 33 } 34 35 func (nv *NetworkValidator) IsLocalMode() bool { 36 return nv.offlineMode == "local" 37 }