certificates
ModuleTLS certificates for custom domains: the Provider every vendor
implements, the Certificates front, and the providers
(Cloudflare, Fastly, FastlyTls, and Proxy, which routes
between them).
Contents
4 submodules, and what the module defines itself.
use utopia_cdn::certificates::Certificates;pub struct Certificates<P>Manages certificates through a provider.
use utopia_cdn::certificates::{Certificates, FastlyTls, Status};
let certificates = Certificates::new(FastlyTls::new("api-token", "tls-configuration-id"));
if certificates.is_renew_required("shop.example.com", None).await? {
certificates.issue_certificate("shop", "shop.example.com", None).await?;
}
match certificates.certificate_status("shop.example.com", None).await {
Ok(Status::Issued) => println!("serving"),
Ok(status) => println!("{status}"),
Err(utopia_cdn::Error::Certificate(blocked)) => {
for challenge in &blocked.challenges {
println!("{} {} -> {}", challenge.record_type, challenge.record_name, challenge.values.join(" or "));
}
}
Err(e) => return Err(e),
}use utopia_cdn::certificates::Challenge;pub struct ChallengeA DNS record the domain owner has to publish before the certificate authority accepts that they control the domain.
use utopia_cdn::certificates::Status;pub enum StatusWhere a certificate's issuance stands.
Display.use utopia_cdn::certificates::Provider;pub trait Provider: Send + SyncIssues, checks, renews and deletes the certificate of a domain.
domain_type is the caller's kind of domain; Proxy routes site,
network and redirect domains to its network provider. Implement it
to add a provider.
certificates::cloudflare
Own pageCloudflare for SaaS custom hostnames.
use utopia_cdn::certificates::cloudflare::Cloudflare;pub struct Cloudflare<C = DefaultClient>Certificates as Cloudflare for SaaS custom hostnames: issuing creates the hostname with an HTTP-validated DV certificate, which Cloudflare manages from then on; a hostname that already exists is left as it is.
Cloudflare reports no status (Provider::certificate_status fails
with Error::UnsupportedOperation); a renewal is required when the
hostname is gone.
use utopia_cdn::certificates::{Cloudflare, Provider};
let cloudflare = Cloudflare::new("zone-id", "api-token");
cloudflare.issue_certificate("shop", "shop.example.com", None).await?;certificates::fastly
Own pageFastly domains together with their TLS subscriptions.
use utopia_cdn::certificates::fastly::Fastly;pub struct Fastly<C = DefaultClient>Certificates for domains a Fastly service serves: the domain is added to
the service through Fastly's domain management, then certified by a
FastlyTls subscription sharing this provider's client.
A domain on another service moves to this one only once its certificate is issued, so a failure never moves a live hostname. A domain on a classic service version is left alone when issuing; deleting it clones and activates a version without it, polls until that version is deployed, then deletes its subscription.
use utopia_cdn::certificates::{Fastly, Provider};
let fastly = Fastly::new("api-token", "service-id").with_tls_configuration_id("tls-configuration-id");
fastly.issue_certificate("shop", "shop.example.com", None).await?;certificates::fastly_tls
Own pageFastly TLS subscriptions and activations.
use utopia_cdn::certificates::fastly_tls::FastlyTls;pub struct FastlyTls<C = DefaultClient>Certificates as Fastly TLS subscriptions, issued by a certificate
authority Fastly works with (certainly by default).
With a TLS configuration ID, an issued certificate is also activated on every hostname of the subscription (so the hostname stops serving Fastly's shared certificate), and a renewal moves the activations to the new certificate. Without one, Fastly's domain management activates it.
While the certificate authority waits for the domain owner to publish a
DNS record, Provider::certificate_status fails with
Error::Certificate, carrying the records to create.
use utopia_cdn::certificates::{FastlyTls, Provider};
let tls = FastlyTls::new("api-token", "tls-configuration-id");
let renew_after = tls.issue_certificate("shop", "shop.example.com", None).await?;certificates::proxy
Own pageRouting certificate calls by domain.
use utopia_cdn::certificates::proxy::Proxy;pub struct ProxyRoutes each certificate call to the providers responsible for the
domain: the network provider for site, network and redirect
domains, the app domain's provider for the app domain itself, and every
custom-domain provider for anything else (fails with
Error::Configuration when there are none).
Over several providers, a certificate is instant only when every one is, needs renewing when any does, and is issued when every provider that is not instant reports it issued (else the first other status).
use std::sync::Arc;
use utopia_cdn::certificates::{Cloudflare, FastlyTls, Proxy};
let app = Arc::new(FastlyTls::new("token", "app-configuration"));
let network = Arc::new(FastlyTls::new("token", "edge-configuration"));
let custom = vec![Arc::new(Cloudflare::new("zone", "token")) as _, Arc::new(FastlyTls::new("token", "")) as _];
let proxy = Proxy::new("App.Example.com", app, network, custom)?;
assert_eq!(proxy.app_domain(), "app.example.com");Debug.