-
Notifications
You must be signed in to change notification settings - Fork 0
/
ziaActivator.go
47 lines (43 loc) · 1.26 KB
/
ziaActivator.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
package main
import (
"fmt"
"log"
"os"
"runtime"
client "github.com/SecurityGeekIO/zscaler-sdk-go/zia"
"github.com/SecurityGeekIO/zscaler-sdk-go/zia/services/activation"
"github.com/zscaler/terraform-provider-zia/v2/zia"
)
func getEnvVarOrFail(k string) string {
if v := os.Getenv(k); v != "" {
return v
}
log.Fatalf("[ERROR] Couldn't find environment variable %s\n", k)
return ""
}
func main() {
log.Printf("[INFO] Initializing ZIA client\n")
c := zia.Config{
Username: getEnvVarOrFail("ZIA_USERNAME"),
Password: getEnvVarOrFail("ZIA_PASSWORD"),
APIKey: getEnvVarOrFail("ZIA_API_KEY"),
ZIABaseURL: getEnvVarOrFail("ZIA_CLOUD"),
UserAgent: fmt.Sprintf("(%s %s) cli/ziaActivator", runtime.GOOS, runtime.GOARCH),
}
cli, err := client.NewClient(c.Username, c.Password, c.APIKey, c.ZIABaseURL, c.UserAgent)
if err != nil {
log.Fatalf("[ERROR] Failed Initializing ZIA client: %v\n", err)
}
activationService := activation.New(cli)
resp, err := activationService.CreateActivation(activation.Activation{
Status: "active",
})
if err != nil {
log.Printf("[ERROR] Activation Failed: %v\n", err)
} else {
log.Printf("[INFO] Activation succeded: %#v\n", resp)
}
log.Printf("[INFO] Destroying session: %#v\n", resp)
_ = cli.Logout()
os.Exit(0)
}