/
cmd_list_map_addresses.go
78 lines (65 loc) · 1.7 KB
/
cmd_list_map_addresses.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"os"
"sort"
"text/tabwriter"
common "github.com/apiheat/akamai-cli-common"
"github.com/fatih/color"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func cmdAddresses(c *cli.Context) error {
return addresses(c)
}
func addresses(c *cli.Context) error {
id := common.SetIntID(c, "Please provide Map ID")
data, _, err := apiClient.SiteShield.ListMap(id)
common.ErrorCheck(err)
current := data.CurrentCidrs
sort.Strings(current)
proposed := data.ProposedCidrs
sort.Strings(proposed)
if c.Bool("show-changes") {
if len(proposed) == 0 {
log.Println("There are no proposed CIDRs, your current CIDR list is up to date")
return nil
}
if len(common.StringsSlicesDifference(current, proposed)) > 0 {
fmt.Println("Removed:")
for i := range common.StringsSlicesDifference(current, proposed) {
color.Set(color.FgRed)
fmt.Printf("\t-%+v\n", common.StringsSlicesDifference(current, proposed)[i])
color.Unset()
}
}
if len(common.StringsSlicesDifference(proposed, current)) > 0 {
fmt.Println("Added:")
for i := range common.StringsSlicesDifference(proposed, current) {
color.Set(color.FgGreen)
fmt.Printf("\t+%+v\n", common.StringsSlicesDifference(proposed, current)[i])
color.Unset()
}
}
} else {
w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, ' ', 0)
fmt.Fprintln(w, fmt.Sprint("Current\tProposed"))
iter := proposed
if len(current) >= len(proposed) {
iter = current
}
for i := range iter {
cIP := ""
if i < len(current) {
cIP = current[i]
}
pIP := ""
if i < len(proposed) {
pIP = proposed[i]
}
fmt.Fprintln(w, fmt.Sprintf("%s\t%s", cIP, pIP))
}
w.Flush()
}
return nil
}