Edits history of script submission #4580 for ' Update custom profile (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Update custom profile
     * Updates a DLP custom profile.
     */
    export async function main(
      auth: Cloudflare,
      profile_id: string,
      account_identifier: string,
      body: {
        allowed_match_count?: number;
        description?: string;
        entries?: {
          created_at?: string;
          enabled?: boolean;
          id?: string;
          name?: string;
          pattern?: { regex: string; validation?: "luhn"; [k: string]: unknown };
          profile_id?: { [k: string]: unknown };
          updated_at?: string;
          [k: string]: unknown;
        }[];
        name?: string;
        shared_entries?: (
          | { enabled?: boolean; entry_id?: string; [k: string]: unknown }
          | { enabled?: boolean; entry_id?: string; [k: string]: unknown }
        )[];
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dlp/profiles/custom/${profile_id}`
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 383 days ago

  • nativets
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Update custom profile
     * Updates a DLP custom profile.
     */
    export async function main(
      auth: Cloudflare,
      profile_id: string,
      account_identifier: string,
      body: {
        allowed_match_count?: number;
        description?: string;
        entries?: {
          created_at?: string;
          enabled?: boolean;
          id?: string;
          name?: string;
          pattern?: { regex: string; validation?: "luhn"; [k: string]: unknown };
          profile_id?: { [k: string]: unknown };
          updated_at?: string;
          [k: string]: unknown;
        }[];
        name?: string;
        shared_entries?: (
          | { enabled?: boolean; entry_id?: string; [k: string]: unknown }
          | { enabled?: boolean; entry_id?: string; [k: string]: unknown }
        )[];
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dlp/profiles/custom/${profile_id}`
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 920 days ago