UNPKG

the-moby-effect

Version:
89 lines 4.37 kB
import * as PlatformError from "@effect/platform/Error"; import * as HttpClient from "@effect/platform/HttpClient"; import * as HttpClientRequest from "@effect/platform/HttpClientRequest"; import * as HttpClientResponse from "@effect/platform/HttpClientResponse"; import * as Effect from "effect/Effect"; import * as Function from "effect/Function"; import * as Option from "effect/Option"; import * as Predicate from "effect/Predicate"; import * as Schema from "effect/Schema"; import * as Tuple from "effect/Tuple"; import { SwarmSecret, SwarmSecretCreateResponse, SwarmSecretSpec } from "../generated/index.js"; import { maybeAddQueryParameter } from "./common.js"; /** * @since 1.0.0 * @category Errors */ export const SecretsErrorTypeId = /*#__PURE__*/Symbol.for("@the-moby-effect/endpoints/SecretsError"); /** * @since 1.0.0 * @category Errors */ export const isSecretsError = u => Predicate.hasProperty(u, SecretsErrorTypeId); /** * @since 1.0.0 * @category Errors */ export class SecretsError extends /*#__PURE__*/PlatformError.TypeIdError(SecretsErrorTypeId, "SecretsError") { get message() { return `${this.method}`; } } /** * Secrets are sensitive data that can be used by services. Swarm mode must be * enabled for these endpoints to work. * * @since 1.0.0 * @category Tags * @see https://docs.docker.com/reference/api/engine/latest/#tag/Secret */ export class Secrets extends /*#__PURE__*/Effect.Service()("@the-moby-effect/endpoints/Secrets", { accessors: false, dependencies: [], effect: /*#__PURE__*/Effect.gen(function* () { const defaultClient = yield* HttpClient.HttpClient; const client = defaultClient.pipe(HttpClient.filterStatusOk); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Secret/operation/SecretList */ const list_ = options => Function.pipe(HttpClientRequest.get("/secrets"), maybeAddQueryParameter("filters", Function.pipe(options?.filters, Option.fromNullable, Option.map(JSON.stringify))), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Array(SwarmSecret))), Effect.mapError(cause => new SecretsError({ method: "list", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Secret/operation/SecretCreate */ const create_ = data => Function.pipe(Schema.decode(SwarmSecretSpec)(data), Effect.map(body => Tuple.make(HttpClientRequest.post("/secrets/create"), body)), Effect.flatMap(Function.tupled(HttpClientRequest.schemaBodyJson(SwarmSecretSpec))), Effect.flatMap(client.execute), Effect.flatMap(HttpClientResponse.schemaBodyJson(SwarmSecretCreateResponse)), Effect.mapError(cause => new SecretsError({ method: "create", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Secret/operation/SecretDelete */ const delete_ = id => Function.pipe(HttpClientRequest.del(`/secrets/${encodeURIComponent(id)}`), client.execute, Effect.asVoid, Effect.mapError(cause => new SecretsError({ method: "delete", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Secret/operation/SecretInspect */ const inspect_ = id => Function.pipe(HttpClientRequest.get(`/secrets/${encodeURIComponent(id)}`), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(SwarmSecret)), Effect.mapError(cause => new SecretsError({ method: "inspect", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Secret/operation/SecretUpdate */ const update_ = (id, options) => Function.pipe(HttpClientRequest.post(`/secrets/${encodeURIComponent(id)}/update`), maybeAddQueryParameter("version", Option.some(options.version)), HttpClientRequest.schemaBodyJson(SwarmSecretSpec)(options.spec), Effect.flatMap(client.execute), Effect.asVoid, Effect.mapError(cause => new SecretsError({ method: "update", cause }))); return { list: list_, create: create_, delete: delete_, inspect: inspect_, update: update_ }; }) }) {} /** * Secrets are sensitive data that can be used by services. Swarm mode must be * enabled for these endpoints to work. * * @since 1.0.0 * @category Layers * @see https://docs.docker.com/reference/api/engine/latest/#tag/Secret */ export const SecretsLayer = Secrets.Default; //# sourceMappingURL=secrets.js.map