1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * Update a device posture rule |
8 | * Updates a device posture rule. |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | uuid: string, |
13 | identifier: string, |
14 | body: { |
15 | description?: string; |
16 | expiration?: string; |
17 | input?: |
18 | | { |
19 | exists?: boolean; |
20 | operating_system: "windows" | "linux" | "mac"; |
21 | path: string; |
22 | sha256?: string; |
23 | thumbprint?: string; |
24 | [k: string]: unknown; |
25 | } |
26 | | { |
27 | id: string; |
28 | operating_system: "android" | "ios" | "chromeos"; |
29 | [k: string]: unknown; |
30 | } |
31 | | { domain?: string; operating_system: "windows"; [k: string]: unknown } |
32 | | { |
33 | operating_system: "windows"; |
34 | operator: "<" | "<=" | ">" | ">=" | "=="; |
35 | os_distro_name?: string; |
36 | os_distro_revision?: string; |
37 | os_version_extra?: string; |
38 | version: string; |
39 | [k: string]: unknown; |
40 | } |
41 | | { |
42 | enabled: boolean; |
43 | operating_system: "windows" | "mac"; |
44 | [k: string]: unknown; |
45 | } |
46 | | { |
47 | operating_system: "windows" | "linux" | "mac"; |
48 | path: string; |
49 | sha256?: string; |
50 | thumbprint?: string; |
51 | [k: string]: unknown; |
52 | } |
53 | | { |
54 | operating_system: "windows" | "linux" | "mac"; |
55 | path: string; |
56 | sha256?: string; |
57 | thumbprint?: string; |
58 | [k: string]: unknown; |
59 | } |
60 | | { checkDisks?: string[]; requireAll?: boolean; [k: string]: unknown } |
61 | | { |
62 | operating_system: "windows" | "linux" | "mac"; |
63 | path: string; |
64 | sha256?: string; |
65 | thumbprint?: string; |
66 | [k: string]: unknown; |
67 | } |
68 | | { certificate_id: string; cn: string; [k: string]: unknown } |
69 | | { |
70 | compliance_status: "compliant" | "noncompliant" | "unknown"; |
71 | connection_id: string; |
72 | [k: string]: unknown; |
73 | } |
74 | | { |
75 | connection_id: string; |
76 | operator?: "<" | "<=" | ">" | ">=" | "=="; |
77 | os?: string; |
78 | overall?: string; |
79 | sensor_config?: string; |
80 | version?: string; |
81 | versionOperator?: "<" | "<=" | ">" | ">=" | "=="; |
82 | [k: string]: unknown; |
83 | } |
84 | | { |
85 | compliance_status: |
86 | | "compliant" |
87 | | "noncompliant" |
88 | | "unknown" |
89 | | "notapplicable" |
90 | | "ingraceperiod" |
91 | | "error"; |
92 | connection_id: string; |
93 | [k: string]: unknown; |
94 | } |
95 | | { |
96 | connection_id: string; |
97 | countOperator: "<" | "<=" | ">" | ">=" | "=="; |
98 | issue_count: string; |
99 | [k: string]: unknown; |
100 | } |
101 | | { |
102 | connection_id: string; |
103 | eid_last_seen?: string; |
104 | operator?: "<" | "<=" | ">" | ">=" | "=="; |
105 | risk_level?: "low" | "medium" | "high" | "critical"; |
106 | scoreOperator?: "<" | "<=" | ">" | ">=" | "=="; |
107 | total_score?: number; |
108 | [k: string]: unknown; |
109 | } |
110 | | { |
111 | active_threats?: number; |
112 | connection_id: string; |
113 | infected?: boolean; |
114 | is_active?: boolean; |
115 | network_status?: |
116 | | "connected" |
117 | | "disconnected" |
118 | | "disconnecting" |
119 | | "connecting"; |
120 | operator?: "<" | "<=" | ">" | ">=" | "=="; |
121 | [k: string]: unknown; |
122 | }; |
123 | match?: { |
124 | platform?: "windows" | "mac" | "linux" | "android" | "ios"; |
125 | [k: string]: unknown; |
126 | }[]; |
127 | name: string; |
128 | schedule?: string; |
129 | type: |
130 | | "file" |
131 | | "application" |
132 | | "tanium" |
133 | | "gateway" |
134 | | "warp" |
135 | | "disk_encryption" |
136 | | "sentinelone" |
137 | | "carbonblack" |
138 | | "firewall" |
139 | | "os_version" |
140 | | "domain_joined" |
141 | | "client_certificate" |
142 | | "unique_client_id" |
143 | | "kolide" |
144 | | "tanium_s2s" |
145 | | "crowdstrike_s2s" |
146 | | "intune" |
147 | | "workspace_one" |
148 | | "sentinelone_s2s"; |
149 | [k: string]: unknown; |
150 | } |
151 | ) { |
152 | const url = new URL( |
153 | `https://api.cloudflare.com/client/v4/accounts/${identifier}/devices/posture/${uuid}` |
154 | ); |
155 |
|
156 | const response = await fetch(url, { |
157 | method: "PUT", |
158 | headers: { |
159 | "X-AUTH-EMAIL": auth.email, |
160 | "X-AUTH-KEY": auth.key, |
161 | "Content-Type": "application/json", |
162 | Authorization: "Bearer " + auth.token, |
163 | }, |
164 | body: JSON.stringify(body), |
165 | }); |
166 | if (!response.ok) { |
167 | const text = await response.text(); |
168 | throw new Error(`${response.status} ${text}`); |
169 | } |
170 | return await response.json(); |
171 | } |
172 |
|