Update a device posture integration

Updates a configured device posture integration.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Update a device posture integration
8
 * Updates a configured device posture integration.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  uuid: string,
13
  identifier: string,
14
  body: {
15
    config?:
16
      | {
17
          api_url: string;
18
          auth_url: string;
19
          client_id: string;
20
          client_secret: string;
21
          [k: string]: unknown;
22
        }
23
      | {
24
          api_url: string;
25
          client_id: string;
26
          client_secret: string;
27
          customer_id: string;
28
          [k: string]: unknown;
29
        }
30
      | {
31
          api_url: string;
32
          client_key: string;
33
          client_secret: string;
34
          customer_id: string;
35
          [k: string]: unknown;
36
        }
37
      | {
38
          client_id: string;
39
          client_secret: string;
40
          customer_id: string;
41
          [k: string]: unknown;
42
        }
43
      | { client_id: string; client_secret: string; [k: string]: unknown }
44
      | { api_url: string; client_secret: string; [k: string]: unknown }
45
      | { api_url: string; client_secret: string; [k: string]: unknown };
46
    interval?: string;
47
    name?: string;
48
    type?:
49
      | "workspace_one"
50
      | "crowdstrike_s2s"
51
      | "uptycs"
52
      | "intune"
53
      | "kolide"
54
      | "tanium"
55
      | "sentinelone_s2s";
56
    [k: string]: unknown;
57
  }
58
) {
59
  const url = new URL(
60
    `https://api.cloudflare.com/client/v4/accounts/${identifier}/devices/posture/integration/${uuid}`
61
  );
62

63
  const response = await fetch(url, {
64
    method: "PATCH",
65
    headers: {
66
      "X-AUTH-EMAIL": auth.email,
67
      "X-AUTH-KEY": auth.key,
68
      "Content-Type": "application/json",
69
      Authorization: "Bearer " + auth.token,
70
    },
71
    body: JSON.stringify(body),
72
  });
73
  if (!response.ok) {
74
    const text = await response.text();
75
    throw new Error(`${response.status} ${text}`);
76
  }
77
  return await response.json();
78
}
79