forked from deploymenttheory/go-api-sdk-jamfpro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditionalAccess.go
88 lines (70 loc) · 2.93 KB
/
conditionalAccess.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
package jamfpro
import (
"fmt"
)
// Constants
const uriAPIConditionalAccess = "/api/v1/conditional-access/device-compliance-information"
// Structures
type ResponseConditionalAccess struct {
TotalCount int `json:"totalCount,omitempty"`
Results []ConditionalAccessDeviceState `json:"results"`
}
type ConditionalAccessDeviceState struct {
DeviceId string `json:"deviceId"`
Applicable bool `json:"applicable"`
ComplianceState string `json:"complianceState"`
ComplianceVendor string `json:"complianceVendor"`
ComplianceVendorDeviceInformation ComplianceVendorDeviceInformation `json:"complianceVendorDeviceInformation"`
}
type ComplianceVendorDeviceInformation struct {
DeviceIds []string `json:"deviceIds"`
}
// Functions
func (c *Client) GetConditionalAccessComplianceStateDeviceIdByName(deviceType string, name string, deviceID int) (string, error) {
var id string
states, err := c.GetConditionalAccessComplianceStateByDeviceTypeAndID(deviceType, deviceID)
if err != nil {
return "", err
}
for _, v := range states.Results {
if v.DeviceId == name {
id = v.DeviceId
break
}
}
return id, err
}
func (c *Client) GetConditionalAccessComplianceStateByDeviceTypeAndDeviceName(deviceType string, deviceName string) (*ConditionalAccessDeviceState, error) {
// First, fetch all devices of the given type
uri := fmt.Sprintf("%s/%s", uriAPIConditionalAccess, deviceType)
var out ResponseConditionalAccess
err := c.DoRequest("GET", uri, nil, nil, &out)
if err != nil {
return nil, fmt.Errorf("failed to get all Conditional Access Device States for %s: %v", deviceType, err)
}
// Iterate through the list to find the one with the desired name
for _, state := range out.Results {
if state.DeviceId == deviceName {
return &state, nil
}
}
return nil, fmt.Errorf("conditional Access Device State with name '%s' not found", deviceName)
}
func (c *Client) GetConditionalAccessComplianceStateByDeviceTypeAndID(deviceType string, deviceID int) (*ResponseConditionalAccess, error) {
uri := fmt.Sprintf("%s/%s/%d", uriAPIConditionalAccess, deviceType, deviceID)
var out ResponseConditionalAccess
err := c.DoRequest("GET", uri, nil, nil, &out)
if err != nil {
return nil, fmt.Errorf("failed to get Conditional Access Device State for %s ID %d: %v", deviceType, deviceID, err)
}
return &out, nil
}
func (c *Client) GetConditionalAccessComplianceStateByDeviceID(deviceType string, deviceID int) (*ConditionalAccessDeviceState, error) {
uri := fmt.Sprintf("%s/%s/%d", uriAPIConditionalAccess, deviceType, deviceID)
var out ConditionalAccessDeviceState
err := c.DoRequest("GET", uri, nil, nil, &out)
if err != nil {
return nil, fmt.Errorf("failed to get Conditional Access Device State by ID: %v", err)
}
return &out, nil
}