import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Redacted from "effect/Redacted";
import * as Context from "effect/Context";
import { ConfigError } from "@distilled.cloud/core/errors";
export class Credentials extends Context.Service()("KubernetesCredentials") {
}
/**
 * Build a credentials layer from environment variables.
 *
 * | Variable | Required | Description |
 * |---|---|---|
 * | `KUBERNETES_TOKEN` | yes | Bearer token for authentication |
 * | `KUBERNETES_API_URL` | yes | API server URL (e.g. from `kubectl cluster-info`) |
 */
export const CredentialsFromEnv = Layer.effect(Credentials, Effect.gen(function* () {
    const token = process.env.KUBERNETES_TOKEN;
    const apiBaseUrl = process.env.KUBERNETES_API_URL;
    if (!token) {
        return yield* new ConfigError({
            message: "KUBERNETES_TOKEN environment variable is required. " +
                "Set it to a bearer token for your Kubernetes cluster.",
        });
    }
    if (!apiBaseUrl) {
        return yield* new ConfigError({
            message: "KUBERNETES_API_URL environment variable is required. " +
                "Set it to the API server URL for your Kubernetes cluster " +
                "(e.g. from `kubectl cluster-info` or the EKS cluster endpoint).",
        });
    }
    return { token: Redacted.make(token), apiBaseUrl };
}));
//# sourceMappingURL=credentials.js.map