ref: b1757dc4f6693dd5f531696214c76690b0206f60 cisco/sdk/user.go -rw-r--r-- 953 bytes View raw
                                                                                
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
package cisco

import (
	"encoding/json"
	"time"
)

type User struct {
	Username string    `json:"username"`
	Email    string    `json:"email"`
	Role     string    `json:"role"`
	Created  time.Time `json:"created"`
}

func ListUser() ([]User, error) {
	var result []User

	data, err := SendRequest(AdminUserListRoute, Request{})
	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(data.([]byte), &result)
	return result, err
}

type UserInfo struct {
	User      User       `json:"user"`
	Tokens    []Token    `json:"tokens"`
	Keys      []SSHKey   `json:"ssh_keys"`
	Instances []Instance `json:"instances"`
	Ipv4s     []Ipv4     `json:"ipv4s"`
	Invites   []Invite   `json:"invites"`
}

func GetUserInfoAdmin(name string) (UserInfo, error) {
	var result UserInfo

	data, err := SendRequest(AdminUserGetRoute, Request{
		Arg: name,
	})

	if err != nil {
		return result, err
	}

	err = json.Unmarshal(data.([]byte), &result)
	return result, err
}