SecretStore

Classin secret-store@fastly/js-compute 4.0.0View source

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
In this example we connect to a secret store named `'secrets'` and retrieve a secret
named `'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 TypeError if no secret store exists with the provided name, the name is empty, longer than 255 characters, or contains invalid characters.

Methods

fromBytes

staticView source
static fromBytes(bytes: ArrayBufferView | ArrayBuffer): SecretStoreEntry

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(key: string): Promise<SecretStoreEntry | null>

Get 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 TypeError if the key is empty, longer than 255 characters, or contains invalid characters.