Edits history of script submission #16866 for ' Create or restore a MySQL Managed Database (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Create or restore a MySQL Managed Database
     * **Provision a MySQL Managed Database**
    
    Use this operation to create a new MySQL Managed Database.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      body: {
        allow_list?: string[];
        cluster_size?: 1 | 2 | 3;
        engine: string;
        fork?: { restore_time?: string; source?: number } & {};
        label: string;
        region: string;
        ssl_connection?: false | true;
        type: string;
      },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/databases/mysql/instances`,
      );
    
      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