(env: Env)
| 4 | import type { AuthenticatorCredentials } from "./user"; |
| 5 | |
| 6 | export 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 | } |
no test coverage detected