Skip to content

Commit

Permalink
add command
Browse files Browse the repository at this point in the history
  • Loading branch information
yuta519 committed May 15, 2022
1 parent f5f964b commit f9d2d2b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/zia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"zscaler_golang/pkg/zia/admin"
"zscaler_golang/pkg/zia/auth"
"zscaler_golang/pkg/zia/config"
"zscaler_golang/pkg/zia/devices"
"zscaler_golang/pkg/zia/firewall"
"zscaler_golang/pkg/zia/network"
"zscaler_golang/pkg/zia/urlcategory"
Expand Down Expand Up @@ -102,6 +103,16 @@ func main() {
if cfg.Args[1] == "exclude" {
fmt.Printf("%+v\n", auth.FetchExemptedUrls())
}
case "device":
if len(cfg.Args) < 2 {
fmt.Fprint(os.Stderr, "device: Please specify sub command")
os.Exit(0)
}
if cfg.Args[1] == "ls" {
if len(cfg.Args) > 2 && cfg.Args[2] == "--group" {
fmt.Printf("%+v\n", devices.FetchDeviceGroups())
}
}
case "adminuser":
if len(cfg.Args) < 2 {
fmt.Fprint(os.Stderr, "adminuser: Please specify sub command")
Expand Down
31 changes: 31 additions & 0 deletions pkg/zia/devices/crud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package devices

import (
"encoding/json"
"net/url"
"zscaler_golang/pkg/infra"
"zscaler_golang/pkg/zia/auth"
"zscaler_golang/pkg/zia/config"
)

type DeviceGroup struct {
Id int `json:"id"`
Name string `json:"name"`
GroupType string `json:"groupType"`
Description string `json:"description"`
OsType string `json:"osType"`
Predefined bool `json:"predefined"`
}

func FetchDeviceGroups() []DeviceGroup {
sessionId := auth.Login()
baseUrl, _ := url.Parse("https://" + config.Config.Hostname)
reference, _ := url.Parse("/api/v1/deviceGroups")
endpoint := baseUrl.ResolveReference(reference).String()
response := infra.GetApi(endpoint, sessionId)
auth.Logout()

var deviceGroups []DeviceGroup
json.Unmarshal(response, &deviceGroups)
return deviceGroups
}

0 comments on commit f9d2d2b

Please sign in to comment.