0

Update predefined profile

by
Published Nov 16, 2023

Updates a DLP predefined profile. Only supports enabling/disabling entries.

Script cloudflare
  • Submitted by hugo697 Typescript (fetch-only)
    Created 534 days ago
    1
    type Cloudflare = {
    2
      token: string;
    3
      email: string;
    4
      key: string;
    5
    };
    6
    /**
    7
     * Update predefined profile
    8
     * Updates a DLP predefined profile. Only supports enabling/disabling entries.
    9
     */
    10
    export async function main(
    11
      auth: Cloudflare,
    12
      profile_id: string,
    13
      account_identifier: string,
    14
      body: {
    15
        allowed_match_count?: number;
    16
        entries?: { enabled?: boolean; id?: string; [k: string]: unknown }[];
    17
        [k: string]: unknown;
    18
      }
    19
    ) {
    20
      const url = new URL(
    21
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dlp/profiles/predefined/${profile_id}`
    22
      );
    23
    
    
    24
      const response = await fetch(url, {
    25
        method: "PUT",
    26
        headers: {
    27
          "X-AUTH-EMAIL": auth.email,
    28
          "X-AUTH-KEY": auth.key,
    29
          "Content-Type": "application/json",
    30
          Authorization: "Bearer " + auth.token,
    31
        },
    32
        body: JSON.stringify(body),
    33
      });
    34
      if (!response.ok) {
    35
        const text = await response.text();
    36
        throw new Error(`${response.status} ${text}`);
    37
      }
    38
      return await response.json();
    39
    }
    40