forked from deploymenttheory/go-api-sdk-jamfpro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csa.go
84 lines (68 loc) · 2.11 KB
/
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
package jamfpro
import (
"fmt"
)
const uriCSATokenExchange = "/api/v1/csa/token"
// ResponseCSAToken represents the structure of the response when requesting
// a CSA token from the Jamf Pro API.
type ResponseCSAToken struct {
RefreshExpiration int `json:"refreshExpiration"`
Scopes []string `json:"scopes"`
}
// CSAToken is used to provide the email and password when requesting
// a CSA token from the Jamf Pro API.
type CSAToken struct {
EmailAddress string `json:"emailAddress"`
Password string `json:"password"`
}
// GetCSAToken retrieves a CSA token from the Jamf Pro API.
func (c *Client) GetCSAToken() (*ResponseCSAToken, error) {
uri := uriCSATokenExchange
var out ResponseCSAToken
err := c.DoRequest("GET", uri, nil, nil, &out)
if err != nil {
return nil, fmt.Errorf("failed to get CSA token: %v", err)
}
return &out, nil
}
// CreateCSAToken creates a new CSA token in the Jamf Pro API using the provided email and password.
func (c *Client) CreateCSAToken(email string, password string) (*ResponseCSAToken, error) {
uri := uriCSATokenExchange
in := &CSAToken{
EmailAddress: email,
Password: password,
}
var out ResponseCSAToken
err := c.DoRequest("POST", uri, in, nil, &out)
if err != nil {
return nil, fmt.Errorf("failed to create CSA token: %v", err)
}
return &out, nil
}
// UpdateCSAToken updates an existing CSA token in the Jamf Pro API using the provided email and password.
func (c *Client) UpdateCSAToken(email string, password string) (*ResponseCSAToken, error) {
uri := uriCSATokenExchange
reqBody := &struct {
*CSAToken
}{
CSAToken: &CSAToken{
EmailAddress: email,
Password: password,
},
}
var out ResponseCSAToken
err := c.DoRequest("PUT", uri, reqBody, nil, &out)
if err != nil {
return nil, fmt.Errorf("failed to update CSA token: %v", err)
}
return &out, nil
}
// DeleteCSAToken deletes an existing CSA token in the Jamf Pro API.
func (c *Client) DeleteCSAToken() error {
uri := uriCSATokenExchange
err := c.DoRequest("DELETE", uri, nil, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete CSA token: %v", err)
}
return nil
}