MCPcopy Create free account
hub / github.com/cloudflare/serverless-registry / authenticationMethodFromEnv

Function authenticationMethodFromEnv

src/authentication-method.ts:6–28  ·  view source on GitHub ↗
(env: Env)

Source from the content-addressed store, hash-verified

4import type { AuthenticatorCredentials } from "./user";
5
6export async function authenticationMethodFromEnv(env: Env) {
7 if (env.JWT_REGISTRY_TOKENS_PUBLIC_KEY) {
8 return await newRegistryTokens(env.JWT_REGISTRY_TOKENS_PUBLIC_KEY);
9 } else if ((env.USERNAME && env.PASSWORD) || (env.READONLY_USERNAME && env.READONLY_PASSWORD)) {
10 const credentials: AuthenticatorCredentials[] = [];
11
12 if (env.USERNAME && env.PASSWORD) {
13 credentials.push({ username: env.USERNAME, password: env.PASSWORD, capabilities: ["pull", "push"] });
14 }
15 if (env.READONLY_USERNAME && env.READONLY_PASSWORD) {
16 credentials.push({ username: env.READONLY_USERNAME, password: env.READONLY_PASSWORD, capabilities: ["pull"] });
17 }
18
19 return new UserAuthenticator(credentials);
20 }
21
22 console.error(
23 "Either env.JWT_REGISTRY_TOKENS_PUBLIC_KEY must be set or both env.USERNAME, env.PASSWORD must be set or both env.READONLY_USERNAME, env.READONLY_PASSWORD must be set.",
24 );
25
26 // invalid configuration
27 return undefined;
28}

Callers 1

fetchFunction · 0.90

Calls 1

newRegistryTokensFunction · 0.90

Tested by

no test coverage detected