Edits history of script submission #14839 for ' Create or update the Log Export configuration for a cluster (cockroachdb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cockroachdb = {
      token: string;
    };
    /**
     * Create or update the Log Export configuration for a cluster
     * Can be used by the following roles assigned at the organization, folder or cluster scope:
    - ORG_ADMIN
    - CLUSTER_ADMIN
    - CLUSTER_OPERATOR_WRITER
    
     */
    export async function main(
      auth: Cockroachdb,
      cluster_id: string,
      body: {
        auth_principal: string;
        aws_external_id?: string;
        azure_shared_key?: string;
        groups?: {
          channels: string[];
          log_name: string;
          min_level?: "UNSPECIFIED" | "WARNING" | "ERROR" | "FATAL";
          redact?: false | true;
        }[];
        log_name: string;
        omitted_channels?: string[];
        redact?: false | true;
        region?: string;
        type: "AWS_CLOUDWATCH" | "GCP_CLOUD_LOGGING" | "AZURE_LOG_ANALYTICS";
      },
    ) {
      const url = new URL(
        `https://cockroachlabs.cloud/api/v1/clusters/${cluster_id}/logexport`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "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 235 days ago