-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.go
54 lines (43 loc) · 1.23 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"github.com/lacework/go-sdk/api"
)
func main() {
lacework, err := api.NewClient(os.Getenv("LW_ACCOUNT"),
api.WithSubaccount(os.Getenv("LW_SUBACCOUNT")),
api.WithApiKeys(os.Getenv("LW_API_KEY"), os.Getenv("LW_API_SECRET")),
)
if err != nil {
log.Fatal(err)
}
policyID := "lacework-global-39"
res, err := lacework.V2.Policy.Exceptions.List(policyID)
if err != nil {
log.Fatal(err)
}
for _, exception := range res.Data {
switch exception.ExceptionID {
}
// Output: ExceptionID: [ID]
fmt.Printf("ExceptionID:%s\n", exception.ExceptionID)
}
myPolicyException := api.PolicyException{
Description: "Exception created by the go-sdk",
Constraints: []api.PolicyExceptionConstraint{{FieldKey: "accountIds", FieldValues: []any{"*"}}},
}
response, err := lacework.V2.Policy.Exceptions.Create(policyID, myPolicyException)
if err != nil {
log.Fatal(err)
}
// Output: Policy Exception created: ID
fmt.Printf("Policy Exception created: %s", response.Data)
err = lacework.V2.Policy.Exceptions.Delete(policyID, response.Data.ExceptionID)
if err != nil {
log.Fatal(err)
}
// Output: Policy Exception deleted: ID
fmt.Printf("Policy Exception deleted: %s", response.Data.ExceptionID)
}