-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmd_list.go
117 lines (89 loc) · 3.18 KB
/
cmd_list.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"strings"
common "github.com/apiheat/akamai-cli-common/v4"
service "github.com/apiheat/go-edgegrid/v6/service/netlistv2"
"github.com/urfave/cli/v2"
)
// cmdlistNetLists is used by cli to execute action of listing all network lists
func cmdlistNetLists(c *cli.Context) error {
return listNetLists(c)
}
// cmdlistNetListId is used by cli to execute action of listing specific network list
func cmdlistNetListID(c *cli.Context) error {
return listNetListbyID(c)
}
// cmdlistNetListName is used by cli to execute action of listing specific network list
func cmdlistNetListName(c *cli.Context) error {
return listNetListbyName(c)
}
// cmdlistNetListSyncPoint is used by cli to execute action of listing specific network list
// by given SyncPoint
func cmdlistNetListSyncPoint(c *cli.Context) error {
return listNetListbySyncPoint(c)
}
// listNetLists execute client API call to get all network lists
func listNetLists(c *cli.Context) error {
listNetListOptsv2 := service.ListNetworkListsOptionsv2{}
listNetListOptsv2.IncludeElements = c.Bool("includeElements")
listNetListOptsv2.Extended = c.Bool("extended")
// Since we are listing all we do not filter results
listNetListOptsv2.Search = ""
if c.String("listType") == "ANY" {
} else {
listNetListOptsv2.TypeOflist = c.String("listType")
}
netListsRes, netlistErr := apiClient.ListNetworkLists(listNetListOptsv2)
if netlistErr != nil {
return netlistErr
}
common.OutputJSON(netListsRes)
return nil
}
// listNetLists execute client API call to get specific network list
func listNetListbyID(c *cli.Context) error {
//TODO: fix
// common.VerifyArgumentByName(c, "id")
listNetListOptsv2 := service.ListNetworkListsOptionsv2{}
listNetListOptsv2.IncludeElements = c.Bool("includeElements")
listNetListOptsv2.Extended = c.Bool("extended")
netList, netlistErr := apiClient.GetNetworkList(c.String("id"), listNetListOptsv2)
if netlistErr != nil {
return netlistErr
}
common.OutputJSON(netList)
return nil
}
// listNetLists execute client API call to get specific network list
// it always returns only one list - for more results use search
func listNetListbyName(c *cli.Context) error {
//TODO: fix
// common.VerifyArgumentByName(c, "name")
listNetListOptsv2 := service.ListNetworkListsOptionsv2{}
listNetListOptsv2.IncludeElements = c.Bool("includeElements")
listNetListOptsv2.Extended = c.Bool("extended")
listNetListOptsv2.Search = c.String("name")
listNetListOptsv2.TypeOflist = c.String("listType")
netList, netlistErr := apiClient.ListNetworkLists(listNetListOptsv2)
if netlistErr != nil {
return netlistErr
}
// First match wins
for _, foundNetList := range netList.NetworkLists {
if strings.ToLower(foundNetList.Name) == strings.ToLower(c.String("name")) {
common.OutputJSON(foundNetList)
return nil
}
}
return nil
}
// listNetListbySyncPoint execute client API call to get specific network list
// it always returns only one list - for more results use search
func listNetListbySyncPoint(c *cli.Context) error {
netList, netlistErr := apiClient.GetActivationSnapshot(c.String("id"), c.Int("syncpoint"), true)
if netlistErr != nil {
return netlistErr
}
common.OutputJSON(netList)
return nil
}