Edits history of script submission #14852 for ' Delete an existing egress rule (cockroachdb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cockroachdb = {
      token: string;
    };
    /**
     * Delete an existing egress rule
     * Can be used by the following roles assigned at the organization, folder or cluster scope:
    - CLUSTER_ADMIN
    - CLUSTER_OPERATOR_WRITER
    
     */
    export async function main(
      auth: Cockroachdb,
      cluster_id: string,
      rule_id: string,
      idempotency_key: string | undefined,
    ) {
      const url = new URL(
        `https://cockroachlabs.cloud/api/v1/clusters/${cluster_id}/networking/egress-rules/${rule_id}`,
      );
      for (const [k, v] of [["idempotency_key", idempotency_key]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago