From a8623f8b91c0894d2d15b7375ca6491aedbff795 Mon Sep 17 00:00:00 2001 From: "Ivan Kuchin (ikuchin)" Date: Sat, 9 Mar 2024 11:09:50 -0500 Subject: [PATCH] code cleanup and add few more checks --- .vscode/launch.json | 1 + internal/cli/get.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 6ba9fb5..0bb4eae 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "get cisco-dhcp", "type": "go", diff --git a/internal/cli/get.go b/internal/cli/get.go index b9e0758..1f2ff21 100644 --- a/internal/cli/get.go +++ b/internal/cli/get.go @@ -55,6 +55,10 @@ func getIPAddressesBelongsToSubnets(client api_client.Authenticator, cfg *config addresses := IPAddresses{} + if len(cfg.Ipam_subnets) == 0 { + return addresses, fmt.Errorf("no subnets defined in config file") + } + for _, subnet := range cfg.Ipam_subnets { subnet_id, err := getSubnetID(client, config_reader.Cfg, subnet) @@ -196,6 +200,10 @@ func getCiscoDHCPOutputBySubnet(addresses IPAddresses, subnet string) (string, e func getCiscoDHCPOutput(client api_client.Authenticator, cfg *config_reader.Config) (string, error) { output := "" + if len(cfg.Ipam_subnets) == 0 { + return "", fmt.Errorf("no subnets defined in config file") + } + for _, subnet := range cfg.Ipam_subnets { subnet_id, err := getSubnetID(client, config_reader.Cfg, subnet)