pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/knf/validators/system/validators_linux.go (about) 1 // Package system provides KNF validators for checking system items (user, groups, 2 // network interfaces) 3 package system 4 5 // ////////////////////////////////////////////////////////////////////////////////// // 6 // // 7 // Copyright (c) 2022 ESSENTIAL KAOS // 8 // Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // 9 // // 10 // ////////////////////////////////////////////////////////////////////////////////// // 11 12 import ( 13 "fmt" 14 15 "pkg.re/essentialkaos/ek.v12/knf" 16 "pkg.re/essentialkaos/ek.v12/system" 17 ) 18 19 // ////////////////////////////////////////////////////////////////////////////////// // 20 21 var ( 22 // Interface returns error if config property contains name of network interface 23 // which not present on the system 24 Interface = validateInterface 25 ) 26 27 // ////////////////////////////////////////////////////////////////////////////////// // 28 29 func validateInterface(config *knf.Config, prop string, value interface{}) error { 30 interfaceName := config.GetS(prop) 31 32 if interfaceName == "" { 33 return nil 34 } 35 36 stats, err := system.GetInterfacesStats() 37 38 if err != nil { 39 return fmt.Errorf("Can't get interfaces info: %v", err) 40 } 41 42 _, isPresent := stats[interfaceName] 43 44 if !isPresent { 45 return fmt.Errorf("Interface %s is not present on the system", interfaceName) 46 } 47 48 return nil 49 }