-
Notifications
You must be signed in to change notification settings - Fork 7
/
prefix.go
122 lines (100 loc) · 2.64 KB
/
prefix.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
118
119
120
121
122
package aws
import (
"github.com/paloaltonetworks/cloud-ngfw-aws-go/api/prefix"
"context"
"net/http"
)
// List returns a list of objects.
func (c *Client) ListPrefixList(ctx context.Context, input prefix.ListInput) (prefix.ListOutput, error) {
perm, permErr := GetPermission(input.Scope)
if permErr != nil {
return prefix.ListOutput{}, permErr
}
c.Log(http.MethodGet, "list rulestack %q prefix lists", input.Rulestack)
var ans prefix.ListOutput
_, err := c.Communicate(
ctx,
perm,
http.MethodGet,
[]string{"v1", "config", "rulestacks", input.Rulestack, "prefixlists"},
nil,
input,
&ans,
)
return ans, err
}
// Create creates an object.
func (c *Client) CreatePrefixList(ctx context.Context, input prefix.Info) error {
perm, permErr := GetPermission(input.Scope)
if permErr != nil {
return permErr
}
c.Log(http.MethodPost, "create rulestack %q prefix list: %s", input.Rulestack, input.Name)
_, err := c.Communicate(
ctx,
perm,
http.MethodPost,
[]string{"v1", "config", "rulestacks", input.Rulestack, "prefixlists"},
nil,
input,
nil,
)
return err
}
// Read returns information on the given object.
func (c *Client) ReadPrefixList(ctx context.Context, input prefix.ReadInput) (prefix.ReadOutput, error) {
perm, permErr := GetPermission(input.Scope)
if permErr != nil {
return prefix.ReadOutput{}, permErr
}
c.Log(http.MethodGet, "describe rulestack %q prefix list: %s", input.Rulestack, input.Name)
var ans prefix.ReadOutput
_, err := c.Communicate(
ctx,
perm,
http.MethodGet,
[]string{"v1", "config", "rulestacks", input.Rulestack, "prefixlists", input.Name},
nil,
input,
&ans,
)
return ans, err
}
// Update updates the given object.
func (c *Client) UpdatePrefixList(ctx context.Context, input prefix.Info) error {
perm, permErr := GetPermission(input.Scope)
if permErr != nil {
return permErr
}
name := input.Name
input.Name = ""
c.Log(http.MethodPut, "updating rulestack %q prefix list: %s", input.Rulestack, name)
_, err := c.Communicate(
ctx,
perm,
http.MethodPut,
[]string{"v1", "config", "rulestacks", input.Rulestack, "prefixlists", name},
nil,
input,
nil,
)
return err
}
// Delete removes the given object from the config.
func (c *Client) DeletePrefixList(ctx context.Context, input prefix.DeleteInput) error {
perm, permErr := GetPermission(input.Scope)
if permErr != nil {
return permErr
}
c.Log(http.MethodDelete, "delete rulestack %q prefix list: %s", input.Rulestack, input.Name)
_, err := c.Communicate(
ctx,
perm,
http.MethodDelete,
[]string{"v1", "config", "rulestacks", input.Rulestack, "prefixlists", input.Name},
nil,
nil,
nil,
)
return err
}