-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathapi.ts
More file actions
115 lines (103 loc) · 3.52 KB
/
Copy pathapi.ts
File metadata and controls
115 lines (103 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi";
import { Schema } from "effect";
import {
ScopeId,
SecretId,
SecretInUseError,
SecretNotFoundError,
SecretOwnedByConnectionError,
SecretResolutionError,
Usage,
} from "@executor-js/sdk";
import { InternalError } from "../observability";
// ---------------------------------------------------------------------------
// Params
// ---------------------------------------------------------------------------
const ScopeParams = { scopeId: ScopeId };
const SecretParams = { scopeId: ScopeId, secretId: SecretId };
// ---------------------------------------------------------------------------
// Response / payload schemas
// ---------------------------------------------------------------------------
const SecretRefResponse = Schema.Struct({
id: SecretId,
scopeId: ScopeId,
name: Schema.String,
provider: Schema.String,
createdAt: Schema.Number,
});
const SecretStatusResponse = Schema.Struct({
secretId: SecretId,
status: Schema.Literals(["resolved", "missing"]),
});
const SetSecretPayload = Schema.Struct({
id: SecretId,
name: Schema.String,
value: Schema.String,
provider: Schema.optional(Schema.String),
});
const UpdateSecretPayload = Schema.Struct({
name: Schema.optional(Schema.String),
value: Schema.optional(Schema.String),
});
// ---------------------------------------------------------------------------
// Error schemas with HTTP status annotations
// ---------------------------------------------------------------------------
const SecretNotFound = SecretNotFoundError.annotate({ httpApiStatus: 404 });
const SecretResolution = SecretResolutionError.annotate({ httpApiStatus: 500 });
const SecretOwnedByConnection = SecretOwnedByConnectionError.annotate({ httpApiStatus: 409 });
const SecretInUse = SecretInUseError.annotate({ httpApiStatus: 409 });
// ---------------------------------------------------------------------------
// Group
// ---------------------------------------------------------------------------
export const SecretsApi = HttpApiGroup.make("secrets")
.add(
HttpApiEndpoint.get("list", "/scopes/:scopeId/secrets", {
params: ScopeParams,
success: Schema.Array(SecretRefResponse),
error: InternalError,
}),
)
.add(
HttpApiEndpoint.get("listAll", "/scopes/:scopeId/secrets/all", {
params: ScopeParams,
success: Schema.Array(SecretRefResponse),
error: InternalError,
}),
)
.add(
HttpApiEndpoint.get("status", "/scopes/:scopeId/secrets/:secretId/status", {
params: SecretParams,
success: SecretStatusResponse,
error: InternalError,
}),
)
.add(
HttpApiEndpoint.post("set", "/scopes/:scopeId/secrets", {
params: ScopeParams,
payload: SetSecretPayload,
success: SecretRefResponse,
error: [InternalError, SecretResolution],
}),
)
.add(
HttpApiEndpoint.patch("update", "/scopes/:scopeId/secrets/:secretId", {
params: SecretParams,
payload: UpdateSecretPayload,
success: SecretRefResponse,
error: [InternalError, SecretNotFound],
}),
)
.add(
HttpApiEndpoint.delete("remove", "/scopes/:scopeId/secrets/:secretId", {
params: SecretParams,
success: Schema.Struct({ removed: Schema.Boolean }),
error: [InternalError, SecretNotFound, SecretOwnedByConnection, SecretInUse],
}),
)
.add(
HttpApiEndpoint.get("usages", "/scopes/:scopeId/secrets/:secretId/usages", {
params: SecretParams,
success: Schema.Array(Usage),
error: InternalError,
}),
);