-
Notifications
You must be signed in to change notification settings - Fork 5
/
jamfproapi_csa.go
98 lines (74 loc) · 2.19 KB
/
jamfproapi_csa.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
// jamfproapi_csa.go
// Jamf Pro Api - CSA Tokens
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v1-csa-token
// Jamf Pro API requires the structs to support a JSON data structure.
package jamfpro
import "fmt"
const uriCSATokenExchange = "/api/v1/csa/token"
// Structs
type ResourceCSATokenExchange struct {
RefreshExpiration int `json:"refreshExpiration"`
Scopes []string `json:"scopes"`
}
// CRUD
func (c *Client) GetCSATokenExchangeInfo() (*ResourceCSATokenExchange, error) {
endpoint := uriCSATokenExchange
var out ResourceCSATokenExchange
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "csa token exchange info", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &out, nil
}
func (c *Client) RefreshCSATokenExchange(username, password string) (*ResourceCSATokenExchange, error) {
endpoint := uriCSATokenExchange
var out ResourceCSATokenExchange
payload := struct {
Username string
Password string
}{
Username: username,
Password: password,
}
resp, err := c.HTTP.DoRequest("PUT", endpoint, payload, &out)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdate, "csa token exchange", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &out, nil
}
func (c *Client) InitializeCSATokenExchange(username, password string) (*ResourceCSATokenExchange, error) {
endpoint := uriCSATokenExchange
var out ResourceCSATokenExchange
payload := struct {
Username string
Password string
}{
Username: username,
Password: password,
}
resp, err := c.HTTP.DoRequest("POST", endpoint, payload, &out)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdate, "csa token exchange", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &out, nil
}
func (c *Client) DeleteCSATokenExchange() error {
endpoint := uriCSATokenExchange
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDelete, "csa token exchange", err)
}
if resp.StatusCode != 204 {
return fmt.Errorf(errMsgFailedDelete, "csa token exchange", err)
}
return nil
}