forked from dilutedev/doppler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudit.go
105 lines (90 loc) · 2.42 KB
/
audit.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package doppler
import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
)
type WorkplaceUsers struct {
WorkplaceUsers []WorkplaceUser `json:"workplace_users"`
Page int64 `json:"page"`
Success bool `json:"success"`
}
type WorkplaceUser struct {
ID string `json:"id"`
Access string `json:"access"`
CreatedAt string `json:"created_at"`
User WUser `json:"user"`
}
type WUser struct {
Email string `json:"email"`
Name string `json:"name"`
Username string `json:"username"`
ProfileImageURL string `json:"profile_image_url"`
MfaEnabled bool `json:"mfa_enabled"`
ThirdpartySsoEnabled bool `json:"thirdparty_sso_enabled"`
SamlSsoEnabled bool `json:"saml_sso_enabled"`
}
type WorkplaceUserResp struct {
WorkplaceUser WorkplaceUser `json:"workplace_user"`
Success bool `json:"success"`
}
/*
Get all users of a workplace
@param settings: bool
If true, the api will return more information if users have e.g. SAML enabled and/or Multi Factor Auth enabled
*/
func (dp *doppler) GetWorkplaceUsers(settings bool, page int32) (*WorkplaceUsers, error) {
// support only audit tokens
if dp.token.Type != "audit" {
return nil, errors.New("audit token required")
}
req, err := http.NewRequest(
http.MethodGet,
fmt.Sprintf("/v3/workplace/users?settings=%v&page=%d", settings, page),
nil)
if err != nil {
log.Println(err)
return nil, err
}
body, err := dp.makeApiRequest(req)
if err != nil {
return nil, err
}
data := new(WorkplaceUsers)
err = json.Unmarshal(body, data)
if err != nil {
return nil, err
}
return data, nil
}
/*
Get a specific user in a workplace
@param settings: bool
If true, the api will return more information if user has e.g. SAML enabled and/or Multi Factor Auth enabled
*/
func (dp *doppler) GetWorkplaceUser(user_id string, settings bool) (*WorkplaceUser, error) {
// support only audit tokens
if dp.token.Type != "audit" {
return nil, errors.New("audit token required")
}
req, err := http.NewRequest(
http.MethodGet,
fmt.Sprintf("/v3/workplace/users/%s?settings=%v", user_id, settings),
nil)
if err != nil {
log.Println(err)
return nil, err
}
body, err := dp.makeApiRequest(req)
if err != nil {
return nil, err
}
data := new(WorkplaceUserResp)
err = json.Unmarshal(body, data)
if err != nil {
return nil, err
}
return &data.WorkplaceUser, nil
}