-
Notifications
You must be signed in to change notification settings - Fork 1
/
users.go
67 lines (57 loc) · 1.99 KB
/
users.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
package users
import (
"fmt"
"net/http"
"github.com/zscaler/zscaler-sdk-go/v2/zdx/services"
)
const (
usersEndpoint = "v1/users"
)
type User struct {
ID int `json:"id"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Devices []Devices `json:"devices,omitempty"`
}
type Devices struct {
ID int `json:"id"`
Name string `json:"name,omitempty"`
UserLocation []UserLocation `json:"geo_loc,omitempty"`
ZSLocation []ZSLocation `json:"zs_loc,omitempty"`
}
type UserLocation struct {
ID string `json:"id"`
City string `json:"city,omitempty"`
State string `json:"state,omitempty"`
Country string `json:"country,omitempty"`
GeoLat float32 `json:"geo_lat,omitempty"`
GeoLong float32 `json:"geo_long,omitempty"`
GeoDetection string `json:"geo_detection,omitempty"`
}
type ZSLocation struct {
ID int `json:"id"`
Name string `json:"name,omitempty"`
}
// Gets user details including the device information, active geolocations, and Zscaler locations. If the time range is not specified, the endpoint defaults to the last 2 hours.
func GetUser(service *services.Service, userID string) (*User, *http.Response, error) {
v := new(User)
path := fmt.Sprintf("%v/%v", usersEndpoint, userID)
resp, err := service.Client.NewRequestDo("GET", path, nil, nil, v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
// Gets the list of all active users, their devices, active geolocations, and Zscaler locations. If the time range is not specified, the endpoint defaults to the last 2 hours.
func GetAllUsers(service *services.Service, filters GetUsersFilters) ([]User, *http.Response, error) {
var v struct {
NextOffSet interface{} `json:"next_offset"`
List []User `json:"users"`
}
relativeURL := usersEndpoint
resp, err := service.Client.NewRequestDo("GET", relativeURL, filters, nil, &v)
if err != nil {
return nil, nil, err
}
return v.List, resp, nil
}