IF Commons GitHub

credentials

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0002-anyfs-s3-store FR-005

Where the keys of a service come from, a closed union: a pair given in code (what the tests use, throwaway keys of a server of their own), the environment (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN, by a function that reads it so that nothing reads the process behind a caller's back), or a provider, a function that gives them or says why not, which is how a temporary key is fetched again and how a secret is asked of a person through the credential port of Headless. A credential is never part of a place, never in a URL, and never in a sentence: what is written of one is [redacted].

import { staticCredentials } from "./credentials.ts";
const c = staticCredentials("AKIDEXAMPLE", "not-a-real-secret");
c.kind; // "ok"

Source: commons/anyfs-s3/src/credentials.ts

6 of 7 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

cachedCredentialsfunction
function cachedCredentials(source: CredentialSource, now?: () => number): () => Promise<Result<AwsCredentials, string>>

A source that asks its provider again only after ttlMs (never, for a static pair and the environment), so a person is asked once and a temporary key is fetched when it is about to lapse.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

CredentialSourcetypeno test imports it
type CredentialSource =
  | { readonly kind: "static"; readonly credentials: AwsCredentials }
  | { readonly kind: "environment"; readonly env: (name: string) => string | undefined }
  | { readonly kind: "provider"; readonly fetch: () => Promise<Result<AwsCredentials, string>>; readonly ttlMs?: number };

Where the keys come from.

environmentCredentialsconst
const environmentCredentials: (env: (name: string) => string | undefined) => CredentialSource

The keys of the environment: a function that reads a variable, which is the only place the process is touched.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

promptedCredentialsfunction
function promptedCredentials(port: CredentialPort, accessKeyId: string, options?: { readonly id?: string | undefined; readonly prompt?: string | undefined; readonly timeoutMs?: number | undefined; }): Result<CredentialSource, string>

A source that asks a person for the secret key through the credential port of Headless, and has the access key id from the caller. The secret is revealed only to sign.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

providedCredentialsconst
const providedCredentials: (fetch: () => Promise<Result<AwsCredentials, string>>, ttlMs?: number | undefined) => CredentialSource

The keys by a function: for temporary keys, which it gives again, and for a secret asked of a person.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

resolveCredentialsfunction
function resolveCredentials(source: CredentialSource): Promise<Result<AwsCredentials, string>>

The keys a source gives now, or why it gives none. A sentence never holds a key.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

staticCredentialsfunction
function staticCredentials(accessKeyId: string, secretAccessKey: string, sessionToken?: string | undefined): Result<CredentialSource, string>

A pair of keys given in code, or why they are not a pair a service would take.

Imported by 27 tests of the run (27 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.