Edits history of script submission #23098 for ' Create Origin CA Certificate (cloudflare)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Origin CA Certificate
     * Issue a Cloudflare Origin CA certificate for your origin server from a CSR you generated. requested_validity is in days: 7, 30, 90, 365, 730, 1095 or 5475 (default).
     */
    export async function main(
      auth: RT.Cloudflare,
      csr: string,
      hostnames: string[],
      request_type: "origin-rsa" | "origin-ecc",
      requested_validity: number | undefined
    ) {
      const response = await fetch(
        "https://api.cloudflare.com/client/v4/certificates",
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({
            csr,
            hostnames,
            request_type,
            requested_validity: requested_validity ?? 5475,
          }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 4 hours ago