1import * as ecr from "@distilled.cloud/aws/ecr";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Binding from "../../Binding.ts";
5import { isBindingHost } from "../Lambda/Function.ts";
6import { GetAuthorizationToken } from "./GetAuthorizationToken.ts";
7
8/**
9 * HTTP implementation of {@link GetAuthorizationToken} over the ECR API.
10 * Registry-level (not repository-scoped): the token authorizes Docker
11 * `login` against the whole private registry, and `ecr:GetAuthorizationToken`
12 * supports no resource-level permissions, so the grant is on `"*"`.
13 */
14export const GetAuthorizationTokenHttp = Layer.effect(
15 GetAuthorizationToken,
16 Effect.gen(function* () {
17 const op = yield* ecr.getAuthorizationToken;
18
19 return Effect.fn(function* () {
20 if (!globalThis.__ALCHEMY_RUNTIME__) {
21 const host = yield* Binding.Host;
22 if (isBindingHost(host)) {
23 yield* host.bind`Allow(${host}, AWS.ECR.GetAuthorizationToken())`({
24 policyStatements: [
25 {
26 Effect: "Allow",
27 Action: ["ecr:GetAuthorizationToken"],
28 Resource: ["*"],
29 },
30 ],
31 });
32 }
33 }
34 return Effect.fn("AWS.ECR.GetAuthorizationToken")(function* () {
35 return yield* op({});
36 });
37 });
38 }),
39);