| 1 | import type * as acm from "@distilled.cloud/aws/acm"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Certificate } from "./Certificate.ts"; |
| 5 | |
| 6 | /** |
| 7 | * The export request without the injected `CertificateArn`. |
| 8 | * |
| 9 | * `Passphrase` encrypts the exported private key and is sensitive — pass it |
| 10 | * as `Redacted.make(new TextEncoder().encode(passphrase))` so it never leaks |
| 11 | * into logs or traces. |
| 12 | */ |
| 13 | export interface ExportCertificateRequest extends Omit< |
| 14 | acm.ExportCertificateRequest, |
| 15 | "CertificateArn" |
| 16 | > {} |
| 17 | |
| 18 | /** |
| 19 | * Runtime binding for `acm:ExportCertificate`. |
| 20 | * |
| 21 | * Bind this operation to a {@link Certificate} to get a callable that exports |
| 22 | * the certificate, its chain, and the **encrypted private key**. Only |
| 23 | * exportable certificates can be exported: private-CA certificates, or public |
| 24 | * certificates requested with `export: "ENABLED"`. The returned `PrivateKey` |
| 25 | * is sensitive and comes back wrapped in `Redacted` — unwrap it with |
| 26 | * `Redacted.value` only at the point of use. Provide the implementation with |
| 27 | * `Effect.provide(AWS.ACM.ExportCertificateHttp)`. |
| 28 | * ### Exporting Certificates |
| 29 | * **Example:** Export a Certificate and Its Private Key |
| 30 | * ```typescript |
| 31 | * // init — bind the operation to the certificate |
| 32 | * const exportCertificate = yield* AWS.ACM.ExportCertificate(certificate); |
| 33 | * |
| 34 | * // runtime — the passphrase encrypts the exported private key |
| 35 | * const result = yield* exportCertificate({ |
| 36 | * Passphrase: Redacted.make(new TextEncoder().encode(passphrase)), |
| 37 | * }); |
| 38 | * const pem = result.Certificate; |
| 39 | * const privateKeyPem = |
| 40 | * typeof result.PrivateKey === "string" |
| 41 | * ? result.PrivateKey |
| 42 | * : result.PrivateKey && Redacted.value(result.PrivateKey); |
| 43 | * ``` |
| 44 | * |
| 45 | * @binding |
| 46 | */ |
| 47 | export interface ExportCertificate extends Binding.Service< |
| 48 | ExportCertificate, |
| 49 | "AWS.ACM.ExportCertificate", |
| 50 | ( |
| 51 | certificate: Certificate, |
| 52 | ) => Effect.Effect< |
| 53 | ( |
| 54 | request: ExportCertificateRequest, |
| 55 | ) => Effect.Effect< |
| 56 | acm.ExportCertificateResponse, |
| 57 | acm.ExportCertificateError |
| 58 | > |
| 59 | > |
| 60 | > {} |
| 61 | |
| 62 | export const ExportCertificate = Binding.Service<ExportCertificate>( |
| 63 | "AWS.ACM.ExportCertificate", |
| 64 | ); |