in plugins/eni/types/types.go [40:72]
func NewConf(args *skel.CmdArgs) (*NetConf, error) {
var conf NetConf
if err := json.Unmarshal(args.StdinData, &conf); err != nil {
return nil, errors.Wrap(err, "newconf types: failed to parse config")
}
// Validate if all the required fields are present
if conf.ENIID == "" {
return nil, errors.Errorf("newconf types: missing required parameter in config: '%s'", "eni")
}
if conf.MACAddress == "" {
return nil, errors.Errorf("newconf types: missing required parameter in config: '%s'", "mac")
}
if len(conf.IPAddresses) == 0 {
return nil, errors.Errorf("newconf types: missing required parameter in config: '%s'", "ip-addresses")
}
// Validate if the mac address in the config is valid
if _, err := net.ParseMAC(conf.MACAddress); err != nil {
return nil, errors.Wrapf(err, "newconf types: malformatted mac address specified")
}
// Validate if the IP addresses in the config are valid
for _, addr := range conf.IPAddresses {
if err := isValidIPAddress(addr); err != nil {
return nil, err
}
}
// Validation complete. Return the parsed config object
log.Debugf("Loaded config: %v", conf)
return &conf, nil
}