SecretStore
Class for accessing a Fastly secret store.
A secret store is a persistent, globally distributed store for secrets accessible to Fastly Compute services during request processing.
Note: Can only be used when processing requests, not during build-time initialization.
12345678910111213141516171819202122In this example we connect to a secret store named `'secrets'` and retrieve a secretnamed `'cat-api-key'` to use in a request header.
```js/// <reference types="@fastly/js-compute" />
import { SecretStore } from "fastly:secret-store";
async function app(event) { const secrets = new SecretStore('secrets')
const catApiKey = await secrets.get('cat-api-key')
return fetch('/api/cat', { headers: { 'cat-api-key': catApiKey.plaintext() } })}
addEventListener("fetch", (event) => event.respondWith(app(event)))```Constructor
new SecretStore(name: string)Creates a new SecretStore object which interacts with the Fastly secret store named name.
Parameters
- name: string
Name of the Fastly secret store to interact with. A name cannot be empty, longer than 255 characters, or contain characters other than letters, numbers, dashes (
-), underscores (_), and periods (.).
Throws
- Throws
TypeErrorif no secret store exists with the provided name, the name is empty, longer than 255 characters, or contains invalid characters.
Methods
Construct a local in-memory SecretStoreEntry from the provided bytes, useful for
passing bytes to APIs that only accept a SecretStoreEntry.
Note: This is not the recommended way to obtain secrets — use get instead.
Parameters
- bytes: ArrayBufferView | ArrayBuffer
The raw bytes to wrap as a
SecretStoreEntry.
Returns
get
View sourceGet the value associated with the key key in the secret store. If the key does not
exist, the returned Promise resolves with null.
Parameters
- key: string
The key to retrieve. A key cannot be empty, longer than 255 characters, or contain characters other than letters, numbers, dashes (
-), underscores (_), and periods (.).
Returns
Throws
- Throws
TypeErrorif the key is empty, longer than 255 characters, or contains invalid characters.