-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdevice_posture.go
109 lines (90 loc) · 4.09 KB
/
device_posture.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
106
107
108
109
// Copyright (c) David Bond, Tailscale Inc, & Contributors
// SPDX-License-Identifier: MIT
package tailscale
import (
"context"
"net/http"
)
// DevicePostureResource provides access to https://tailscale.com/api#tag/deviceposture.
type DevicePostureResource struct {
*Client
}
const (
PostureIntegrationProviderFalcon PostureIntegrationProvider = "falcon"
PostureIntegrationProviderIntune PostureIntegrationProvider = "intune"
PostureIntegrationProviderJamfPro PostureIntegrationProvider = "jamfpro"
PostureIntegrationProviderKandji PostureIntegrationProvider = "kandji"
PostureIntegrationProviderKolide PostureIntegrationProvider = "kolide"
PostureIntegrationProviderSentinelOne PostureIntegrationProvider = "sentinelone"
)
// PostureIntegrationProvider identifies a supported posture integration data provider.
type PostureIntegrationProvider string
// PostureIntegration is a configured posture integration.
type PostureIntegration struct {
ID string `json:"id,omitempty"`
Provider PostureIntegrationProvider `json:"provider,omitempty"`
CloudID string `json:"cloudId,omitempty"`
ClientID string `json:"clientId,omitempty"`
TenantID string `json:"tenantId,omitempty"`
}
// CreatePostureIntegrationRequest is a request to create a posture integration.
type CreatePostureIntegrationRequest struct {
Provider PostureIntegrationProvider `json:"provider,omitempty"`
CloudID string `json:"cloudId,omitempty"`
ClientID string `json:"clientId,omitempty"`
TenantID string `json:"tenantId,omitempty"`
ClientSecret string `json:"clientSecret,omitempty"`
}
// UpdatePostureIntegrationRequest is a request to update a posture integration.
type UpdatePostureIntegrationRequest struct {
CloudID string `json:"cloudId,omitempty"`
ClientID string `json:"clientId,omitempty"`
TenantID string `json:"tenantId,omitempty"`
// ClientSecret may be omitted to preserve the existing value
ClientSecret *string `json:"clientSecret,omitempty"`
}
// List lists every configured [PostureIntegration].
func (pr *DevicePostureResource) ListIntegrations(ctx context.Context) ([]PostureIntegration, error) {
req, err := pr.buildRequest(ctx, http.MethodGet, pr.buildTailnetURL("posture", "integrations"))
if err != nil {
return nil, err
}
m := make(map[string][]PostureIntegration)
err = pr.do(req, &m)
if err != nil {
return nil, err
}
return m["integrations"], nil
}
// CreateIntegration creates a new posture integration, returning the resulting [PostureIntegration].
func (pr *DevicePostureResource) CreateIntegration(ctx context.Context, intg CreatePostureIntegrationRequest) (*PostureIntegration, error) {
req, err := pr.buildRequest(ctx, http.MethodPost, pr.buildTailnetURL("posture", "integrations"), requestBody(intg))
if err != nil {
return nil, err
}
return body[PostureIntegration](pr, req)
}
// UpdateIntegration updates the existing posture integration identified by id, returning the resulting [PostureIntegration].
func (pr *DevicePostureResource) UpdateIntegration(ctx context.Context, id string, intg UpdatePostureIntegrationRequest) (*PostureIntegration, error) {
req, err := pr.buildRequest(ctx, http.MethodPatch, pr.buildURL("posture", "integrations", id), requestBody(intg))
if err != nil {
return nil, err
}
return body[PostureIntegration](pr, req)
}
// DeleteIntegration deletes the posture integration identified by id.
func (pr *DevicePostureResource) DeleteIntegration(ctx context.Context, id string) error {
req, err := pr.buildRequest(ctx, http.MethodDelete, pr.buildURL("posture", "integrations", id))
if err != nil {
return err
}
return pr.do(req, nil)
}
// GetIntegration gets the posture integration identified by id.
func (pr *DevicePostureResource) GetIntegration(ctx context.Context, id string) (*PostureIntegration, error) {
req, err := pr.buildRequest(ctx, http.MethodGet, pr.buildURL("posture", "integrations", id))
if err != nil {
return nil, err
}
return body[PostureIntegration](pr, req)
}