Edits history of script submission #17186 for ' Upload an Object Storage TLS/SSL certificate (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Upload an Object Storage TLS/SSL certificate
     * Upload a TLS/SSL certificate and private key to be served when you visit your Object Storage bucket via HTTPS.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      regionId: string,
      bucket: string,
      body: { certificate: string; private_key: string },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/object-storage/buckets/${regionId}/${bucket}/ssl`,
      );
    
      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