@intentius/chant-lexicon-terraform 0.124.76 → 0.124.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/drift-record.d.ts +24 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +52 -0
- package/dist/drift-rows.d.ts +49 -4
- package/dist/drift-rows.d.ts.map +1 -1
- package/dist/drift-rows.js +87 -19
- package/dist/integrity.json +2 -2
- package/dist/manifest.json +1 -1
- package/dist/pr-env.d.ts +138 -0
- package/dist/pr-env.d.ts.map +1 -0
- package/dist/pr-env.js +248 -0
- package/dist/state/gitlab.d.ts +74 -0
- package/dist/state/gitlab.d.ts.map +1 -0
- package/dist/state/gitlab.js +275 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/index.d.ts.map +1 -1
- package/dist/state/index.js +2 -0
- package/dist/state/store.d.ts +2 -1
- package/dist/state/store.d.ts.map +1 -1
- package/dist/state/versions.d.ts +39 -0
- package/dist/state/versions.d.ts.map +1 -0
- package/dist/state/versions.js +85 -0
- package/dist/state-migration.d.ts +85 -0
- package/dist/state-migration.d.ts.map +1 -0
- package/dist/state-migration.js +296 -0
- package/dist/state-ops.d.ts +54 -87
- package/dist/state-ops.d.ts.map +1 -1
- package/dist/state-ops.js +120 -77
- package/package.json +2 -2
- package/src/__fixtures__/drift-rows/refresh-plan-module.json +48 -0
- package/src/drift-record.test.ts +62 -0
- package/src/drift-record.ts +58 -0
- package/src/drift-rows.test.ts +90 -1
- package/src/drift-rows.ts +89 -18
- package/src/pr-env.test.ts +132 -0
- package/src/pr-env.ts +312 -0
- package/src/state/gitlab.test.ts +226 -0
- package/src/state/gitlab.ts +318 -0
- package/src/state/index.ts +2 -0
- package/src/state/store.ts +2 -1
- package/src/state/versions.ts +103 -0
- package/src/state-export-unlock.test.ts +230 -0
- package/src/state-migration.test.ts +236 -0
- package/src/state-migration.ts +353 -0
- package/src/state-ops.ts +132 -130
package/dist/pr-env.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pull request's copy of Terraform roots (#4762): each root initialised
|
|
3
|
+
* under its backend's state key with the environment's suffix, planned,
|
|
4
|
+
* applied, and destroyed when the pull request closes or its TTL passes.
|
|
5
|
+
* chant core runs the environment (`components/pr-env-run`: the gate, the
|
|
6
|
+
* records, the TTL, the sweep) and its component rules
|
|
7
|
+
* (`components/pr-env-components`); this module is the Terraform part.
|
|
8
|
+
*
|
|
9
|
+
* Why a key suffix and not a workspace: the other stages read a root's state
|
|
10
|
+
* from its backend block, and a workspace would put the copy in the same
|
|
11
|
+
* namespace as the root under a name only the binary resolves. A suffixed
|
|
12
|
+
* key is a state of its own that the backend block, the lock and the bucket
|
|
13
|
+
* listing all name plainly.
|
|
14
|
+
*
|
|
15
|
+
* s3, azurerm `key`: `envs/dev/terraform.tfstate` becomes
|
|
16
|
+
* `envs/dev/terraform-pr-7.tfstate`
|
|
17
|
+
* gcs `prefix`: `envs/dev` becomes `envs/dev-pr-7`
|
|
18
|
+
* local `path`
|
|
19
|
+
* http `address`, when it is a GitLab project's state API: the
|
|
20
|
+
* copy is the state `<name>-pr-7`, and its lock and unlock
|
|
21
|
+
* addresses take the same name
|
|
22
|
+
*
|
|
23
|
+
* The copy's `-backend-config` comes from the root's code and the job's
|
|
24
|
+
* `TF_CLI_ARGS` (`declaredBackend`). A root another tool prepares, such as
|
|
25
|
+
* a Terragrunt unit whose `remote_state` reads the suffix from the
|
|
26
|
+
* environment, passes `prepare`; its recorded backend must then carry the
|
|
27
|
+
* suffix, or the copy is refused, so a copy never plans, applies or destroys
|
|
28
|
+
* at a root's own key.
|
|
29
|
+
*
|
|
30
|
+
* Lifted from terragucci's `ephemeral.ts` (`suffixedKey`, `KEY_ATTRIBUTE`,
|
|
31
|
+
* `gitlabCopy`, `copyBackend`, `unitBackend`, `carriesSuffix`, `planCopy`,
|
|
32
|
+
* `copyAdapter`, `ephemeralTeardown`), so terragucci deletes its copy and
|
|
33
|
+
* keeps its words: its checkout of the pull request, its synth command, its
|
|
34
|
+
* Terragrunt preparation and its binary per root.
|
|
35
|
+
*/
|
|
36
|
+
import { join } from "node:path";
|
|
37
|
+
import { componentsPrEnvAdapter, componentsPrEnvTeardown } from "@intentius/chant/components/pr-env-components";
|
|
38
|
+
import { declaredBackend, initialisedBackend } from "./state/backend.js";
|
|
39
|
+
import { isGitLabAddress, shownUrl, suffixedGitLabAddress } from "./state/gitlab.js";
|
|
40
|
+
import { applyPlanFile, planCopy } from "./state-ops.js";
|
|
41
|
+
/** The backends a copy can be given a key of its own on, and the attribute that holds the key. */
|
|
42
|
+
export const KEY_ATTRIBUTE = { s3: "key", azurerm: "key", gcs: "prefix", local: "path", http: "address" };
|
|
43
|
+
/** The http backend's attributes that name the state too: its lock's, `<address>/lock` on GitLab. */
|
|
44
|
+
export const HTTP_LOCK_ATTRIBUTES = ["lock_address", "unlock_address"];
|
|
45
|
+
const BACKENDS = Object.keys(KEY_ATTRIBUTE).join(", ");
|
|
46
|
+
/** A root no copy can be made of, or a prepared root whose key is its own. A config error: nothing planned. */
|
|
47
|
+
export class CopyRefusedError extends Error {
|
|
48
|
+
constructor(message) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = "CopyRefusedError";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A state key with the suffix: before a closing `.tfstate`, else at the end.
|
|
55
|
+
* `envs/dev/terraform.tfstate` becomes `envs/dev/terraform-pr-7.tfstate`.
|
|
56
|
+
*/
|
|
57
|
+
export function suffixedKey(key, suffix) {
|
|
58
|
+
const k = key.replace(/\/+$/, "");
|
|
59
|
+
return /\.tfstate$/.test(k) ? k.replace(/\.tfstate$/, `-${suffix}.tfstate`) : `${k}-${suffix}`;
|
|
60
|
+
}
|
|
61
|
+
/** Whether a key or location carries a copy's suffix as {@link suffixedKey} puts it. A GitLab lock address is read without its `/lock`. */
|
|
62
|
+
export const carriesSuffix = (key, suffix) => new RegExp(`-${suffix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\.tfstate)?/*$`).test(key.replace(/\/lock\/?$/, ""));
|
|
63
|
+
/** Where a copy's state is, for messages and the record. */
|
|
64
|
+
function locationOf(type, config, key) {
|
|
65
|
+
const s = (k) => (typeof config[k] === "string" && config[k] !== "" ? config[k] : undefined);
|
|
66
|
+
if (type === "http")
|
|
67
|
+
return shownUrl(key);
|
|
68
|
+
if (type === "s3" && s("bucket"))
|
|
69
|
+
return `s3://${s("bucket")}/${key}`;
|
|
70
|
+
if (type === "gcs" && s("bucket"))
|
|
71
|
+
return `gs://${s("bucket")}/${key}`;
|
|
72
|
+
if (type === "azurerm" && s("container_name"))
|
|
73
|
+
return `az://${s("storage_account_name") ?? "azure"}/${s("container_name")}/${key}`;
|
|
74
|
+
return key;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A GitLab-managed state's attributes for its copy: the address and each
|
|
78
|
+
* lock address with the state name suffixed. Each is the configured one,
|
|
79
|
+
* else its `TF_HTTP_*` variable, as the binary reads it.
|
|
80
|
+
*/
|
|
81
|
+
export function gitlabCopy(root, config, env, suffix) {
|
|
82
|
+
const given = (name) => (typeof config[name] === "string" && config[name] !== "" ? config[name] : env[`TF_HTTP_${name.toUpperCase()}`] || undefined);
|
|
83
|
+
const address = given("address");
|
|
84
|
+
if (!address)
|
|
85
|
+
throw new CopyRefusedError(`${root}'s http backend names no address, in the block or TF_HTTP_ADDRESS, so there is no state name to give its copy a suffix`);
|
|
86
|
+
const key = suffixedGitLabAddress(address, suffix);
|
|
87
|
+
if (!key)
|
|
88
|
+
throw new CopyRefusedError(`${root}'s http backend address ${shownUrl(address)} is not a GitLab project's state API (.../projects/<id>/terraform/state/<name>), and a copy of an http backend's state is made on GitLab-managed state only`);
|
|
89
|
+
const extra = {};
|
|
90
|
+
for (const name of HTTP_LOCK_ATTRIBUTES) {
|
|
91
|
+
const v = given(name);
|
|
92
|
+
if (!v)
|
|
93
|
+
continue;
|
|
94
|
+
const suffixed = suffixedGitLabAddress(v, suffix);
|
|
95
|
+
if (!suffixed || suffixedGitLabAddress(v.replace(/\/lock\/?$/, ""), suffix) !== key)
|
|
96
|
+
throw new CopyRefusedError(`${root}'s http backend ${name} ${shownUrl(v)} is not the lock of its state, ${shownUrl(address)}/lock, so its copy's lock could not be named`);
|
|
97
|
+
extra[name] = suffixed;
|
|
98
|
+
}
|
|
99
|
+
return { key, extra };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The `-backend-config` a root's copy is initialised with, from the backend
|
|
103
|
+
* its code declares with the job's flags over it. Throws
|
|
104
|
+
* {@link CopyRefusedError} for a root no copy can be made of: a `cloud`
|
|
105
|
+
* block, a backend with no key attribute, a block that names no key.
|
|
106
|
+
*/
|
|
107
|
+
export function copyBackend(dir, root, suffix, env = {}, binary) {
|
|
108
|
+
const b = declaredBackend(dir, { env, ...(binary ? { binary } : {}) });
|
|
109
|
+
if (b?.type === "cloud")
|
|
110
|
+
throw new CopyRefusedError(`${root} keeps its state in HCP Terraform (a cloud block), where a state is a workspace and not a key; a copy is made of roots whose backend is ${BACKENDS}`);
|
|
111
|
+
const type = b?.type ?? "local";
|
|
112
|
+
const attribute = KEY_ATTRIBUTE[type];
|
|
113
|
+
if (!attribute)
|
|
114
|
+
throw new CopyRefusedError(`${root}'s backend is ${type}, and a copy is given a state key of its own on ${BACKENDS} backends only`);
|
|
115
|
+
const config = b?.config ?? {};
|
|
116
|
+
if (type === "http") {
|
|
117
|
+
const copy = gitlabCopy(root, config, env, suffix);
|
|
118
|
+
return { type, attribute, key: copy.key, location: shownUrl(copy.key), ...(Object.keys(copy.extra).length ? { extra: copy.extra } : {}) };
|
|
119
|
+
}
|
|
120
|
+
const raw = config[attribute];
|
|
121
|
+
const given = typeof raw === "string" && raw !== "" ? raw : type === "local" ? "terraform.tfstate" : undefined;
|
|
122
|
+
if (!given)
|
|
123
|
+
throw new CopyRefusedError(`${root}'s ${type} backend names no ${attribute}, so there is no key to give its copy a suffix; write the ${attribute} in the block`);
|
|
124
|
+
const key = suffixedKey(given, suffix);
|
|
125
|
+
return { type, attribute, key, location: locationOf(type, config, key) };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The backend a prepared root was initialised with, checked to be its copy:
|
|
129
|
+
* its key attribute, and a GitLab state's lock addresses, carry the suffix.
|
|
130
|
+
* Throws {@link CopyRefusedError} when it does not; `hint` says how to make
|
|
131
|
+
* the product's config read the suffix.
|
|
132
|
+
*/
|
|
133
|
+
export function preparedCopyBackend(dir, root, suffix, env = {}, hint) {
|
|
134
|
+
const how = hint ? `; ${hint}` : "";
|
|
135
|
+
const b = initialisedBackend(dir, env);
|
|
136
|
+
if (!b)
|
|
137
|
+
throw new CopyRefusedError(`${root}: it was prepared with no backend the binary recorded, so its copy has no key of its own${how}`);
|
|
138
|
+
const attribute = KEY_ATTRIBUTE[b.type];
|
|
139
|
+
if (!attribute)
|
|
140
|
+
throw new CopyRefusedError(`${root}'s backend is ${b.type}, and a copy is given a state key of its own on ${BACKENDS} backends only`);
|
|
141
|
+
const raw = b.config[attribute];
|
|
142
|
+
const key = typeof raw === "string" ? raw : "";
|
|
143
|
+
if (b.type === "http" && !isGitLabAddress(key))
|
|
144
|
+
throw new CopyRefusedError(`${root}'s http backend ${key ? `address ${shownUrl(key)} is not a GitLab project's state API` : "names no address"}, and a copy of an http backend's state is made on GitLab-managed state only`);
|
|
145
|
+
if (!carriesSuffix(key, suffix))
|
|
146
|
+
throw new CopyRefusedError(`${root}: its ${b.type} backend's ${attribute} is ${key ? (b.type === "http" ? shownUrl(key) : key) : "empty"} as it was prepared, which is the root's own state, so its copy is refused${how}`);
|
|
147
|
+
if (b.type === "http") {
|
|
148
|
+
const own = HTTP_LOCK_ATTRIBUTES.map((a) => b.config[a]).find((l) => typeof l === "string" && !carriesSuffix(l, suffix));
|
|
149
|
+
if (own)
|
|
150
|
+
throw new CopyRefusedError(`${root}: its http backend's lock address is ${shownUrl(own)} as it was prepared, the lock of the root's own state, so its copy is refused; make lock_address and unlock_address read the suffix as the address does`);
|
|
151
|
+
}
|
|
152
|
+
return { type: b.type, attribute, key, location: locationOf(b.type, b.config, key) };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Plan one root's copy: init it under its suffixed key (or prepare it, then
|
|
156
|
+
* check its key), plan (a destroy with `destroy`), and read the plan's
|
|
157
|
+
* counts. A run of the binary that fails is the plan's `error`; a root no
|
|
158
|
+
* copy can be made of throws {@link CopyRefusedError}.
|
|
159
|
+
*/
|
|
160
|
+
export async function terraformCopyPlan(input) {
|
|
161
|
+
const { copy, suffix } = input;
|
|
162
|
+
const exec = input.exec;
|
|
163
|
+
const none = { component: copy.root, planDigest: "", create: 0, update: 0, replace: 0, delete: 0 };
|
|
164
|
+
let dir = copy.dir;
|
|
165
|
+
let env = copy.env ?? process.env;
|
|
166
|
+
let backend;
|
|
167
|
+
let backendConfig = {};
|
|
168
|
+
if (copy.prepare) {
|
|
169
|
+
let prepared;
|
|
170
|
+
try {
|
|
171
|
+
prepared = await copy.prepare(suffix);
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
return { ...none, error: e.message, apply: async () => { } };
|
|
175
|
+
}
|
|
176
|
+
({ dir, env } = prepared);
|
|
177
|
+
backend = preparedCopyBackend(dir, copy.root, suffix, env, input.hint);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
backend = copyBackend(dir, copy.root, suffix, env, copy.binary);
|
|
181
|
+
backendConfig = { [backend.attribute]: backend.key, ...backend.extra };
|
|
182
|
+
}
|
|
183
|
+
const run = { root: copy.root, binary: copy.binary, dir, env, ...(exec ? { exec } : {}) };
|
|
184
|
+
try {
|
|
185
|
+
const read = await planCopy({ ...run, backendConfig, planFile: input.planFile, ...(copy.prepare ? { init: false } : {}), ...(input.destroy ? { destroy: true } : {}), ...(input.lockTimeout !== undefined ? { lockTimeout: input.lockTimeout } : {}) });
|
|
186
|
+
const count = (action) => read.part.entries.filter((e) => e.action === action).length;
|
|
187
|
+
return {
|
|
188
|
+
component: copy.root,
|
|
189
|
+
planDigest: read.planDigest,
|
|
190
|
+
create: count("create"),
|
|
191
|
+
update: count("update"),
|
|
192
|
+
replace: count("replace"),
|
|
193
|
+
delete: count("delete"),
|
|
194
|
+
location: backend.location,
|
|
195
|
+
apply: () => applyPlanFile({ ...run, planFile: input.planFile, ...(input.lockTimeout !== undefined ? { lockTimeout: input.lockTimeout } : {}) }),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
return { ...none, location: backend.location, error: e.message, apply: async () => { } };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The adapter `prEnvUp` takes for a copy of Terraform roots: each root's copy
|
|
204
|
+
* planned under `-<env>` (`pr-<n>`) and applied in order. `refused` holds a
|
|
205
|
+
* {@link CopyRefusedError}, which a product raises as a config error.
|
|
206
|
+
*/
|
|
207
|
+
export function terraformPrEnvAdapter(input) {
|
|
208
|
+
let copies = new Map();
|
|
209
|
+
return componentsPrEnvAdapter({
|
|
210
|
+
async components(target) {
|
|
211
|
+
const roots = await input.roots(target);
|
|
212
|
+
copies = new Map(roots.map((r) => [r.root, r]));
|
|
213
|
+
return roots.map((r) => r.root);
|
|
214
|
+
},
|
|
215
|
+
plan: (component, i, target) => terraformCopyPlan({ copy: copies.get(component), suffix: target.env, planFile: join(input.work, `${i}.tfplan`), ...(input.exec ? { exec: input.exec } : {}), ...(input.lockTimeout !== undefined ? { lockTimeout: input.lockTimeout } : {}), ...(input.hint ? { hint: input.hint } : {}) }),
|
|
216
|
+
...(input.nothing ? { nothing: () => input.nothing } : {}),
|
|
217
|
+
...(input.log ? { log: input.log } : {}),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The teardown `prEnvDown` and `prEnvSweep` take for a copy of Terraform
|
|
222
|
+
* roots: a root whose recorded state location carries `-<env>` is destroyed,
|
|
223
|
+
* through a planned destroy of its copy, in reverse apply order; any other
|
|
224
|
+
* is a hole, so nothing at a root's own key is destroyed. It stands in for
|
|
225
|
+
* the terraform lexicon's own teardown.
|
|
226
|
+
*/
|
|
227
|
+
export function terraformPrEnvTeardown(input) {
|
|
228
|
+
return componentsPrEnvTeardown({
|
|
229
|
+
name: input.name,
|
|
230
|
+
lexicons: ["terraform"],
|
|
231
|
+
type: "terraform_root",
|
|
232
|
+
owns: (location, env) => carriesSuffix(location, env),
|
|
233
|
+
async checkout(live) {
|
|
234
|
+
const code = await input.checkout(live);
|
|
235
|
+
const roots = new Map(code.roots.map((r) => [r.root, r]));
|
|
236
|
+
return {
|
|
237
|
+
async plan(component, i) {
|
|
238
|
+
const copy = roots.get(component);
|
|
239
|
+
if (!copy)
|
|
240
|
+
throw new Error(`${component} is not at ${live.commit.slice(0, 8)}, so its copy cannot be planned`);
|
|
241
|
+
return terraformCopyPlan({ copy, suffix: live.env, planFile: join(input.work, `destroy-${i}.tfplan`), destroy: true, ...(input.exec ? { exec: input.exec } : {}), ...(input.lockTimeout !== undefined ? { lockTimeout: input.lockTimeout } : {}), ...(input.hint ? { hint: input.hint } : {}) });
|
|
242
|
+
},
|
|
243
|
+
...(code.done ? { done: code.done } : {}),
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
...(input.log ? { log: input.log } : {}),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ForgeFetch } from "@intentius/chant/pr-forge";
|
|
2
|
+
import type { StateStore } from "./store.js";
|
|
3
|
+
/**
|
|
4
|
+
* The HTTP calls the store makes. A StoreFetch, chant's forge fetch and the
|
|
5
|
+
* global fetch all fit.
|
|
6
|
+
*/
|
|
7
|
+
export type GitLabFetch = ForgeFetch;
|
|
8
|
+
/** Where a GitLab-managed state is, and how to call its API. */
|
|
9
|
+
export interface GitLabState {
|
|
10
|
+
backend: "http";
|
|
11
|
+
/** The state's address as the backend has it. */
|
|
12
|
+
address: string;
|
|
13
|
+
/** The state's name, the last part of its address. */
|
|
14
|
+
name: string;
|
|
15
|
+
lockAddress?: string;
|
|
16
|
+
unlockAddress?: string;
|
|
17
|
+
lockMethod: string;
|
|
18
|
+
unlockMethod: string;
|
|
19
|
+
/** The Authorization header the backend's credentials make, when it has any. */
|
|
20
|
+
auth?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Whether an http backend's address is a GitLab project's state API. */
|
|
23
|
+
export declare function isGitLabAddress(address: string | undefined): boolean;
|
|
24
|
+
/** A URL with its credentials and query left out, to print and record. */
|
|
25
|
+
export declare function shownUrl(raw: string): string;
|
|
26
|
+
/** The GitLab-managed state an http backend's configuration names, or undefined when its address is not GitLab's state API. */
|
|
27
|
+
export declare function gitlabState(config: Record<string, unknown>, env?: NodeJS.ProcessEnv): GitLabState | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* A GitLab state address with its state name suffixed `-<suffix>`, and a
|
|
30
|
+
* lock address with the state name before `/lock` suffixed the same way.
|
|
31
|
+
* Undefined when the address is not GitLab's state API (or its lock).
|
|
32
|
+
*/
|
|
33
|
+
export declare function suffixedGitLabAddress(address: string, suffix: string): string | undefined;
|
|
34
|
+
/** The URL of one version of the state. */
|
|
35
|
+
export declare const gitlabVersionUrl: (s: GitLabState, serial: string | number) => string;
|
|
36
|
+
/** The address of the state beside this one whose name is this one's with `suffix` after it. */
|
|
37
|
+
export declare function gitlabBesideAddress(s: GitLabState, suffix: string): string;
|
|
38
|
+
/** A GitLab-managed state opened as a {@link StateStore}, with the reads GitLab's API has beyond one: its serial, its versions, and a lock released by its ID. */
|
|
39
|
+
export interface GitLabStateStore extends StateStore {
|
|
40
|
+
readonly backend: "http";
|
|
41
|
+
/**
|
|
42
|
+
* The serial and lineage of the state GitLab holds now, or undefined when
|
|
43
|
+
* it holds none. GitLab has no call that answers the serial alone, so this
|
|
44
|
+
* reads the state and keeps those two fields only.
|
|
45
|
+
*/
|
|
46
|
+
serial(): Promise<{
|
|
47
|
+
serial: number;
|
|
48
|
+
lineage?: string;
|
|
49
|
+
} | undefined>;
|
|
50
|
+
/** Whether GitLab keeps the version with this serial: a HEAD, so no state is read. */
|
|
51
|
+
hasVersion(serial: string | number): Promise<boolean>;
|
|
52
|
+
/** One version of the state, or undefined when GitLab keeps no version with that serial. */
|
|
53
|
+
readVersion(serial: string | number): Promise<string | undefined>;
|
|
54
|
+
/**
|
|
55
|
+
* Who holds the lock, as lock info text with its ID, its GitLab user and
|
|
56
|
+
* when it was taken, or undefined when nobody does. GitLab has no call that
|
|
57
|
+
* reads a lock, so this asks for it: a held lock answers 409 with its
|
|
58
|
+
* holder, and a free one is taken by the ask and released at once by its
|
|
59
|
+
* own ID.
|
|
60
|
+
*/
|
|
61
|
+
probeLock(): Promise<string | undefined>;
|
|
62
|
+
/**
|
|
63
|
+
* Release the lock with this ID. GitLab releases it only while that ID
|
|
64
|
+
* holds it: another lock taken since answers 409, which is thrown.
|
|
65
|
+
*/
|
|
66
|
+
releaseLock(id: string): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The GitLab-managed state as a store. `who` names the probe's lock info
|
|
70
|
+
* (its `Who`, and the start of its ID), so a holder that reads the lock
|
|
71
|
+
* while the probe has it sees whose it is.
|
|
72
|
+
*/
|
|
73
|
+
export declare function gitlabStore(s: GitLabState, fetchFn?: GitLabFetch, who?: string): GitLabStateStore;
|
|
74
|
+
//# sourceMappingURL=gitlab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitlab.d.ts","sourceRoot":"","sources":["../../src/state/gitlab.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC;AAErC,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAOpE;AAED,0EAA0E;AAC1E,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO5C;AAKD,+HAA+H;AAC/H,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,WAAW,GAAG,SAAS,CAkB1H;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAWzF;AAcD,2CAA2C;AAC3C,eAAO,MAAM,gBAAgB,MAAO,WAAW,UAAU,MAAM,GAAG,MAAM,KAAG,MAA6E,CAAC;AAEzJ,gGAAgG;AAChG,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAI1E;AAqBD,kKAAkK;AAClK,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IACpE,sFAAsF;IACtF,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,4FAA4F;IAC5F,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAClE;;;;;;OAMG;IACH,SAAS,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC;;;OAGG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,GAAE,WAA0B,EAAE,GAAG,SAAU,GAAG,gBAAgB,CAuHhH"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitLab-managed Terraform state (#4773): an http backend whose address is a
|
|
3
|
+
* GitLab project's state API, `<api>/projects/<id>/terraform/state/<name>`,
|
|
4
|
+
* with `<address>/lock` as its lock and unlock address.
|
|
5
|
+
*
|
|
6
|
+
* GitLab keeps each version of a state by its serial. `GET <address>` is the
|
|
7
|
+
* current state, `GET <address>/versions/<serial>` one version, and `POST`
|
|
8
|
+
* and `DELETE` on `<address>/lock` (the backend's `LOCK` and `UNLOCK` by
|
|
9
|
+
* default) take and release the lock. A lock that is held answers a take
|
|
10
|
+
* with 409 and the holder's lock info. While a lock is held GitLab takes a
|
|
11
|
+
* write of the state only with the lock's ID (`POST <address>?ID=<id>`), so
|
|
12
|
+
* the binary cannot write with `-lock=false` under chant's lock and the store
|
|
13
|
+
* writes the state itself, as the azurerm store does under its lease.
|
|
14
|
+
*
|
|
15
|
+
* The backend's configuration comes from the block, a `-backend-config` file
|
|
16
|
+
* or flag (which `init` records), or the job's `TF_HTTP_*` variables (which
|
|
17
|
+
* it does not record): each attribute is the recorded value, else its
|
|
18
|
+
* variable (`TF_HTTP_ADDRESS`, `TF_HTTP_LOCK_ADDRESS`,
|
|
19
|
+
* `TF_HTTP_UNLOCK_ADDRESS`, `TF_HTTP_LOCK_METHOD`, `TF_HTTP_UNLOCK_METHOD`),
|
|
20
|
+
* as the binary reads it. Every call is made with the backend's own
|
|
21
|
+
* credentials, `username` and `password` (`TF_HTTP_USERNAME`,
|
|
22
|
+
* `TF_HTTP_PASSWORD`): the job token in a pipeline, a personal access token
|
|
23
|
+
* at a shell.
|
|
24
|
+
*
|
|
25
|
+
* What a run keeps beside the state goes in another state of the same
|
|
26
|
+
* project, named the state's name with the suffix after it, so it is under
|
|
27
|
+
* the project's own access controls.
|
|
28
|
+
*
|
|
29
|
+
* Lifted from terragucci's `gitlab-state.ts` (INTENTIUS/terragucci 70b7509),
|
|
30
|
+
* so terragucci deletes its copy.
|
|
31
|
+
*/
|
|
32
|
+
import { randomUUID } from "node:crypto";
|
|
33
|
+
import { defaultFetch, StoreError } from "./object-store.js";
|
|
34
|
+
/** The path of GitLab's state API: `.../api/v4/projects/<id>/terraform/state/<name>`. */
|
|
35
|
+
const STATE_API_PATH = /\/api\/v4\/projects\/[^/]+\/terraform\/state\/([^/]+)\/?$/;
|
|
36
|
+
const str = (v) => (typeof v === "string" && v !== "" ? v : undefined);
|
|
37
|
+
/** Whether an http backend's address is a GitLab project's state API. */
|
|
38
|
+
export function isGitLabAddress(address) {
|
|
39
|
+
if (!address)
|
|
40
|
+
return false;
|
|
41
|
+
try {
|
|
42
|
+
return STATE_API_PATH.test(new URL(address).pathname);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** A URL with its credentials and query left out, to print and record. */
|
|
49
|
+
export function shownUrl(raw) {
|
|
50
|
+
try {
|
|
51
|
+
const u = new URL(raw);
|
|
52
|
+
return `${u.protocol}//${u.host}${u.pathname}`;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return raw;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** The http backend's attribute, as the binary reads it: recorded, else its `TF_HTTP_*` variable. */
|
|
59
|
+
const attribute = (config, env, name) => str(config[name]) ?? str(env[`TF_HTTP_${name.toUpperCase()}`]);
|
|
60
|
+
/** The GitLab-managed state an http backend's configuration names, or undefined when its address is not GitLab's state API. */
|
|
61
|
+
export function gitlabState(config, env = process.env) {
|
|
62
|
+
const address = attribute(config, env, "address");
|
|
63
|
+
if (!address || !isGitLabAddress(address))
|
|
64
|
+
return undefined;
|
|
65
|
+
const name = decodeURIComponent(new URL(address).pathname.match(STATE_API_PATH)[1]);
|
|
66
|
+
const username = attribute(config, env, "username");
|
|
67
|
+
const password = attribute(config, env, "password");
|
|
68
|
+
const lockAddress = attribute(config, env, "lock_address");
|
|
69
|
+
const unlockAddress = attribute(config, env, "unlock_address");
|
|
70
|
+
return {
|
|
71
|
+
backend: "http",
|
|
72
|
+
address,
|
|
73
|
+
name,
|
|
74
|
+
...(lockAddress ? { lockAddress } : {}),
|
|
75
|
+
...(unlockAddress ? { unlockAddress } : {}),
|
|
76
|
+
lockMethod: attribute(config, env, "lock_method") ?? "LOCK",
|
|
77
|
+
unlockMethod: attribute(config, env, "unlock_method") ?? "UNLOCK",
|
|
78
|
+
...(username || password ? { auth: `Basic ${Buffer.from(`${username ?? ""}:${password ?? ""}`).toString("base64")}` } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A GitLab state address with its state name suffixed `-<suffix>`, and a
|
|
83
|
+
* lock address with the state name before `/lock` suffixed the same way.
|
|
84
|
+
* Undefined when the address is not GitLab's state API (or its lock).
|
|
85
|
+
*/
|
|
86
|
+
export function suffixedGitLabAddress(address, suffix) {
|
|
87
|
+
let u;
|
|
88
|
+
try {
|
|
89
|
+
u = new URL(address);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const m = u.pathname.match(/^(.*\/api\/v4\/projects\/[^/]+\/terraform\/state\/)([^/]+?)(\/lock)?\/?$/);
|
|
95
|
+
if (!m)
|
|
96
|
+
return undefined;
|
|
97
|
+
u.pathname = `${m[1]}${m[2]}-${suffix}${m[3] ?? ""}`;
|
|
98
|
+
return u.toString();
|
|
99
|
+
}
|
|
100
|
+
const headers = (s, json = false) => ({ ...(s.auth ? { authorization: s.auth } : {}), ...(json ? { "content-type": "application/json" } : {}) });
|
|
101
|
+
const base = (address) => address.replace(/\/+$/, "");
|
|
102
|
+
/** An error that names the call and GitLab's answer, never the credentials. */
|
|
103
|
+
function answered(what, url, status, text) {
|
|
104
|
+
const why = status === 401 ? ": the backend's username and password (TF_HTTP_USERNAME, TF_HTTP_PASSWORD) are not a token GitLab accepts" : status === 403 ? ": the token may not read this project's state (reads need Developer)" : "";
|
|
105
|
+
return new StoreError(`GitLab answered ${status} to ${what} ${shownUrl(url)}${why}${text && !why ? `: ${text.trim().slice(0, 200)}` : ""}`);
|
|
106
|
+
}
|
|
107
|
+
const held = (status) => status === 409 || status === 423;
|
|
108
|
+
/** The URL of one version of the state. */
|
|
109
|
+
export const gitlabVersionUrl = (s, serial) => `${base(s.address)}/versions/${encodeURIComponent(String(serial))}`;
|
|
110
|
+
/** The address of the state beside this one whose name is this one's with `suffix` after it. */
|
|
111
|
+
export function gitlabBesideAddress(s, suffix) {
|
|
112
|
+
const u = new URL(s.address);
|
|
113
|
+
u.pathname = `${u.pathname.replace(/\/+$/, "")}${encodeURIComponent(suffix)}`;
|
|
114
|
+
return u.toString();
|
|
115
|
+
}
|
|
116
|
+
/** The holder in GitLab's answer to a take of a lock that is held: its ID, its GitLab user and when it was taken. GitLab answers the other fields with the ask's own, so they are left out. */
|
|
117
|
+
function heldBy(text) {
|
|
118
|
+
try {
|
|
119
|
+
const v = JSON.parse(text);
|
|
120
|
+
return JSON.stringify(Object.fromEntries(["ID", "Who", "Created"].filter((k) => typeof v[k] === "string").map((k) => [k, v[k]])));
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return text;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const idOf = (text) => {
|
|
127
|
+
try {
|
|
128
|
+
const v = JSON.parse(text);
|
|
129
|
+
return typeof v.ID === "string" ? v.ID : "";
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* The GitLab-managed state as a store. `who` names the probe's lock info
|
|
137
|
+
* (its `Who`, and the start of its ID), so a holder that reads the lock
|
|
138
|
+
* while the probe has it sees whose it is.
|
|
139
|
+
*/
|
|
140
|
+
export function gitlabStore(s, fetchFn = defaultFetch, who = "chant") {
|
|
141
|
+
const location = shownUrl(s.address);
|
|
142
|
+
let lockedId;
|
|
143
|
+
const needLock = () => {
|
|
144
|
+
if (!s.lockAddress || !s.unlockAddress)
|
|
145
|
+
throw new StoreError(`the http backend of ${location} names no ${s.lockAddress ? "unlock_address" : "lock_address"}`);
|
|
146
|
+
return s.lockAddress;
|
|
147
|
+
};
|
|
148
|
+
/** Take the lock with `info`: true when taken, the held answer's text when another holds it. */
|
|
149
|
+
const take = async (info) => {
|
|
150
|
+
const at = needLock();
|
|
151
|
+
const r = await fetchFn(at, { method: s.lockMethod, headers: headers(s, true), body: info });
|
|
152
|
+
const text = await r.text();
|
|
153
|
+
if (held(r.status))
|
|
154
|
+
return { heldText: text };
|
|
155
|
+
if (!r.ok)
|
|
156
|
+
throw answered("a lock of", at, r.status, text);
|
|
157
|
+
return true;
|
|
158
|
+
};
|
|
159
|
+
const releaseLock = async (id) => {
|
|
160
|
+
if (!s.unlockAddress)
|
|
161
|
+
throw new StoreError(`the http backend of ${location} names no unlock_address`);
|
|
162
|
+
const r = await fetchFn(s.unlockAddress, { method: s.unlockMethod, headers: headers(s, true), body: JSON.stringify({ ID: id }) });
|
|
163
|
+
const text = await r.text();
|
|
164
|
+
if (held(r.status))
|
|
165
|
+
throw new StoreError(`GitLab did not release lock ${id} on ${shownUrl(s.unlockAddress)}: another lock holds the state now`);
|
|
166
|
+
if (!r.ok)
|
|
167
|
+
throw answered("a release of", s.unlockAddress, r.status, text);
|
|
168
|
+
};
|
|
169
|
+
const probeLock = async () => {
|
|
170
|
+
const id = `${who}-probe-${randomUUID()}`;
|
|
171
|
+
const info = JSON.stringify({ ID: id, Operation: "OperationTypeInvalid", Info: `${who} reads who holds the lock`, Who: who, Version: "", Created: new Date().toISOString(), Path: "" });
|
|
172
|
+
const got = await take(info);
|
|
173
|
+
if (got !== true)
|
|
174
|
+
return heldBy(got.heldText);
|
|
175
|
+
await releaseLock(id);
|
|
176
|
+
return undefined;
|
|
177
|
+
};
|
|
178
|
+
/** The text at `url`, or undefined when GitLab holds no state there. */
|
|
179
|
+
const read = async (url) => {
|
|
180
|
+
const r = await fetchFn(url, { method: "GET", headers: headers(s) });
|
|
181
|
+
if (r.status === 404 || r.status === 204)
|
|
182
|
+
return undefined;
|
|
183
|
+
const text = await r.text();
|
|
184
|
+
if (!r.ok)
|
|
185
|
+
throw answered("a read of", url, r.status, text);
|
|
186
|
+
return text;
|
|
187
|
+
};
|
|
188
|
+
const post = async (url, body) => {
|
|
189
|
+
const r = await fetchFn(url, { method: "POST", headers: headers(s, true), body });
|
|
190
|
+
const text = await r.text();
|
|
191
|
+
if (held(r.status))
|
|
192
|
+
throw new StoreError(`GitLab refused a write of ${shownUrl(url)}: its lock is held by another ID`);
|
|
193
|
+
if (!r.ok)
|
|
194
|
+
throw answered("a write of", url, r.status, text);
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
backend: "http",
|
|
198
|
+
location,
|
|
199
|
+
lockLocation: shownUrl(s.lockAddress ?? s.address),
|
|
200
|
+
serial: async () => {
|
|
201
|
+
const text = await read(s.address);
|
|
202
|
+
if (text === undefined)
|
|
203
|
+
return undefined;
|
|
204
|
+
let doc;
|
|
205
|
+
try {
|
|
206
|
+
doc = JSON.parse(text);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
throw new StoreError(`GitLab answered ${location} with no state`);
|
|
210
|
+
}
|
|
211
|
+
if (typeof doc.serial !== "number")
|
|
212
|
+
throw new StoreError(`the state at ${location} has no serial`);
|
|
213
|
+
return { serial: doc.serial, ...(typeof doc.lineage === "string" ? { lineage: doc.lineage } : {}) };
|
|
214
|
+
},
|
|
215
|
+
hasVersion: async (serial) => {
|
|
216
|
+
const url = gitlabVersionUrl(s, serial);
|
|
217
|
+
const r = await fetchFn(url, { method: "HEAD", headers: headers(s) });
|
|
218
|
+
if (r.status === 404)
|
|
219
|
+
return false;
|
|
220
|
+
if (!r.ok)
|
|
221
|
+
throw answered("a check of", url, r.status, "");
|
|
222
|
+
return true;
|
|
223
|
+
},
|
|
224
|
+
readVersion: async (serial) => {
|
|
225
|
+
const url = gitlabVersionUrl(s, serial);
|
|
226
|
+
const r = await fetchFn(url, { method: "GET", headers: headers(s) });
|
|
227
|
+
if (r.status === 404)
|
|
228
|
+
return undefined;
|
|
229
|
+
const text = await r.text();
|
|
230
|
+
if (!r.ok)
|
|
231
|
+
throw answered("a read of", url, r.status, text);
|
|
232
|
+
return text;
|
|
233
|
+
},
|
|
234
|
+
probeLock,
|
|
235
|
+
releaseLock,
|
|
236
|
+
heldLock: async () => {
|
|
237
|
+
const info = await probeLock();
|
|
238
|
+
return info === undefined ? undefined : { id: idOf(info), info };
|
|
239
|
+
},
|
|
240
|
+
lock: async (info) => {
|
|
241
|
+
if ((await take(info)) !== true)
|
|
242
|
+
return false;
|
|
243
|
+
lockedId = idOf(info);
|
|
244
|
+
return true;
|
|
245
|
+
},
|
|
246
|
+
unlock: async () => {
|
|
247
|
+
if (lockedId === undefined)
|
|
248
|
+
return;
|
|
249
|
+
await releaseLock(lockedId);
|
|
250
|
+
lockedId = undefined;
|
|
251
|
+
},
|
|
252
|
+
write: async (body) => {
|
|
253
|
+
if (lockedId === undefined)
|
|
254
|
+
throw new StoreError(`${location} is written under its lock, and none is held`);
|
|
255
|
+
const u = new URL(s.address);
|
|
256
|
+
u.searchParams.set("ID", lockedId);
|
|
257
|
+
await post(u.toString(), body);
|
|
258
|
+
},
|
|
259
|
+
readBeside: (suffix) => read(gitlabBesideAddress(s, suffix)),
|
|
260
|
+
writeBeside: (suffix, body) => post(gitlabBesideAddress(s, suffix), body),
|
|
261
|
+
removeBeside: async (suffix) => {
|
|
262
|
+
const url = gitlabBesideAddress(s, suffix);
|
|
263
|
+
const r = await fetchFn(url, { method: "DELETE", headers: headers(s) });
|
|
264
|
+
if (r.status === 404)
|
|
265
|
+
return;
|
|
266
|
+
const text = await r.text();
|
|
267
|
+
if (!r.ok)
|
|
268
|
+
throw answered("a delete of", url, r.status, text);
|
|
269
|
+
},
|
|
270
|
+
besideLocation: (suffix) => shownUrl(gitlabBesideAddress(s, suffix)),
|
|
271
|
+
adopt: (h) => {
|
|
272
|
+
lockedId = h.id;
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
}
|
package/dist/state/index.d.ts
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
export * from "./object-store.js";
|
|
7
7
|
export * from "./backend.js";
|
|
8
8
|
export * from "./store.js";
|
|
9
|
+
export * from "./gitlab.js";
|
|
9
10
|
export * from "./exec.js";
|
|
10
11
|
export * from "./locks.js";
|
|
11
12
|
export * from "./root-states.js";
|
|
12
13
|
export { S3Client, s3FromEnv, type S3Target } from "./s3.js";
|
|
13
14
|
export { GcsClient, type GcsTarget } from "./gcs.js";
|
|
14
15
|
export { AzureBlobClient, type AzureTarget } from "./azure-blob.js";
|
|
16
|
+
export * from "./versions.js";
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACjE,cAAc,YAAY,CAAC"}
|
package/dist/state/index.js
CHANGED
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
export * from "./object-store.js";
|
|
7
7
|
export * from "./backend.js";
|
|
8
8
|
export * from "./store.js";
|
|
9
|
+
export * from "./gitlab.js";
|
|
9
10
|
export * from "./exec.js";
|
|
10
11
|
export * from "./locks.js";
|
|
11
12
|
export * from "./root-states.js";
|
|
12
13
|
export { S3Client, s3FromEnv } from "./s3.js";
|
|
13
14
|
export { GcsClient } from "./gcs.js";
|
|
14
15
|
export { AzureBlobClient } from "./azure-blob.js";
|
|
16
|
+
export * from "./versions.js";
|
package/dist/state/store.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export interface LockHolder {
|
|
|
8
8
|
}
|
|
9
9
|
/** A state where it is, for what locks it and keeps beside it. */
|
|
10
10
|
export interface StateStore {
|
|
11
|
-
|
|
11
|
+
/** The backend's type; `http` is a GitLab-managed state (./gitlab.ts). */
|
|
12
|
+
readonly backend: LockableState["backend"] | "http";
|
|
12
13
|
/** Where the state is. */
|
|
13
14
|
readonly location: string;
|
|
14
15
|
/** Where its lock is: the lock object, or the blob whose lease is the lock. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/state/store.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAoC,aAAa,EAAW,MAAM,WAAW,CAAC;AAE1F,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG7D,oHAAoH;AACpH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,kEAAkE;AAClE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/state/store.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAoC,aAAa,EAAW,MAAM,WAAW,CAAC;AAE1F,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG7D,oHAAoH;AACpH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,kEAAkE;AAClE,MAAM,WAAW,UAAU;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IACpD,0BAA0B;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,oDAAoD;IACpD,QAAQ,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAC5C,8FAA8F;IAC9F,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,kEAAkE;IAClE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACxD,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,wEAAwE;IACxE,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;CAC/B;AAED,8DAA8D;AAC9D,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO3C;AAiDD,+FAA+F;AAC/F,eAAO,MAAM,aAAa,oBAAoB,CAAC;AAsF/C,6HAA6H;AAC7H,wBAAgB,UAAU,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,UAAU,CAK1F"}
|