use fastly::backend::Backend;
use fastly::secret_store::{LookupError, SecretStore};
use fastly::{Error, Request, Response};
#[fastly::main]
fn main(req: Request) -> Result<Response, Error> {
let store = SecretStore::open("my_credentials_store")?;
let certificate_bytes = store
.get("fastly-certificate")
.ok_or_else(|| LookupError::InvalidSecretName("fastly_certificate".to_string()))?
.plaintext()
.to_vec();
let certificate = String::from_utf8(certificate_bytes)?;
let certificate_key = store
.get("fastly-key")
.ok_or_else(|| LookupError::InvalidSecretName("fastly_key".to_string()))?;
let backend = Backend::builder("origin_0", "http-me.glitch.me")
.enable_ssl()
.override_host("http-me.glitch.me")
.provide_client_certificate(certificate, certificate_key)
.finish()?;
Ok(req.send(backend)?)
}