cisco/sdk/user.go -rw-r--r-- 1.2 KiB 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
}

type UserInfoRole struct {
	Role string `json:"role"`
}

func SetRoleUser(user string, role string) error {
	_, err := SendRequest(AdminUserSetRoleRoute, Request{
		Arg: user,
		Data: &UserInfoRole{
			Role: role,
		},
	})

	return err
}