Edits history of script submission #14627 for ' Create new service (clickhouse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clickhouse = {
      username: string;
      password: string;
      host: string;
    };
    /**
     * Create new service
     * Creates a new service in the organization, and returns the current service state and a password to access the service. The service is started asynchronously.
     */
    export async function main(
      auth: Clickhouse,
      organizationId: string,
      body: {
        name?: string;
        provider?: "aws" | "gcp" | "azure";
        region?:
          | "ap-south-1"
          | "ap-southeast-1"
          | "eu-central-1"
          | "eu-west-1"
          | "eu-west-2"
          | "us-east-1"
          | "us-east-2"
          | "us-west-2"
          | "ap-southeast-2"
          | "ap-northeast-1"
          | "us-east1"
          | "us-central1"
          | "europe-west4"
          | "asia-southeast1"
          | "eastus"
          | "eastus2"
          | "westus3"
          | "germanywestcentral";
        tier?:
          | "development"
          | "production"
          | "dedicated_high_mem"
          | "dedicated_high_cpu"
          | "dedicated_standard"
          | "dedicated_standard_n2d_standard_4"
          | "dedicated_standard_n2d_standard_8"
          | "dedicated_standard_n2d_standard_32"
          | "dedicated_standard_n2d_standard_128";
        ipAccessList?: { source?: string; description?: string }[];
        minTotalMemoryGb?: number;
        maxTotalMemoryGb?: number;
        minReplicaMemoryGb?: number;
        maxReplicaMemoryGb?: number;
        numReplicas?: number;
        idleScaling?: false | true;
        idleTimeoutMinutes?: number;
        isReadonly?: false | true;
        dataWarehouseId?: string;
        backupId?: string;
        encryptionKey?: string;
        encryptionAssumedRoleIdentifier?: string;
        privateEndpointIds?: string[];
        privatePreviewTermsChecked?: false | true;
        releaseChannel?: "default" | "fast";
        byocId?: string;
      }
    ) {
      const url = new URL(
        `https://api.clickhouse.cloud/v1/organizations/${organizationId}/services`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        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