hammerkit 2.1.0-next.6 → 2.1.0-next.7
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/cli.js +5 -0
- package/dist/planner/validate.js +10 -0
- package/dist/planner/work-secret.js +33 -11
- package/dist/program.js +19 -1
- package/dist/secrets/prefetch-secrets.js +20 -1
- package/dist/server/plan.js +8 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -54,6 +54,9 @@ class Cli {
|
|
|
54
54
|
start: async () => {
|
|
55
55
|
(0, work_network_1.applyNetworkCeiling)(workTree, type === 'down' ? null : options?.network ?? null);
|
|
56
56
|
if (type !== 'down') {
|
|
57
|
+
// every secret of what runs, not only those of task ids: a secret this machine can't
|
|
58
|
+
// read fails the run before any of it starts
|
|
59
|
+
(0, prefetch_secrets_1.requireReadableSecrets)(workTree);
|
|
57
60
|
await this.prepareSecrets(true);
|
|
58
61
|
}
|
|
59
62
|
(0, check_for_loop_1.checkForLoop)(workTree);
|
|
@@ -170,6 +173,8 @@ class Cli {
|
|
|
170
173
|
// Ordered execution plan with predicted cache decisions, reusing the explain
|
|
171
174
|
// engine — executes nothing, starts nothing, performs no cache push/pull.
|
|
172
175
|
async dryRun(options) {
|
|
176
|
+
// fails where the run would
|
|
177
|
+
(0, prefetch_secrets_1.requireReadableSecrets)(this.workTree);
|
|
173
178
|
await this.prepareSecrets();
|
|
174
179
|
return (0, dry_run_1.planDryRun)(this.workTree, options?.cacheDefault ?? 'checksum', this.environment);
|
|
175
180
|
}
|
package/dist/planner/validate.js
CHANGED
|
@@ -7,6 +7,14 @@ const unreferenced_build_file_envs_1 = require("./unreferenced-build-file-envs")
|
|
|
7
7
|
const normalize_path_1 = require("./utils/normalize-path");
|
|
8
8
|
const dependency_outputs_1 = require("./utils/dependency-outputs");
|
|
9
9
|
const run_source_envs_1 = require("../environment/run-source-envs");
|
|
10
|
+
const work_secret_1 = require("./work-secret");
|
|
11
|
+
// A provider or account is declared by the machine that runs a task, in its host config, not
|
|
12
|
+
// by the build file: the build file is valid, only running the task here fails.
|
|
13
|
+
function* warnUnreadableSecrets(item) {
|
|
14
|
+
for (const reason of (0, work_secret_1.getUnreadableSecrets)(item.secrets)) {
|
|
15
|
+
yield { type: 'warn', message: `${reason}, running it here fails`, item };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
10
18
|
async function* validate(workTree, context) {
|
|
11
19
|
const cycleItems = [];
|
|
12
20
|
for (const item of (0, plan_work_tasks_1.iterateWorkServices)(workTree)) {
|
|
@@ -15,6 +23,7 @@ async function* validate(workTree, context) {
|
|
|
15
23
|
yield { type: 'warn', message: `missing description`, item: service };
|
|
16
24
|
}
|
|
17
25
|
if (service.type === 'container-service') {
|
|
26
|
+
yield* warnUnreadableSecrets(service);
|
|
18
27
|
yield* warnUnsetEnvs(service.envs, service);
|
|
19
28
|
if (!service.healthcheck) {
|
|
20
29
|
yield { type: 'warn', message: 'missing healthcheck', item: service };
|
|
@@ -56,6 +65,7 @@ async function* validate(workTree, context) {
|
|
|
56
65
|
yield { type: 'warn', message: `missing description`, item: task };
|
|
57
66
|
}
|
|
58
67
|
yield* warnUnsetEnvs(task.envs, task);
|
|
68
|
+
yield* warnUnreadableSecrets(task);
|
|
59
69
|
if (task.type === 'local-task' && task.resources) {
|
|
60
70
|
yield { type: 'warn', message: 'resources are not enforced for a local task', item: task };
|
|
61
71
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSecretDigest = exports.resolveSecretValue = exports.parseWorkSecrets = exports.getPortableSecretName = exports.getSecretName = exports.describeSecretSource = void 0;
|
|
3
|
+
exports.getSecretDigest = exports.resolveSecretValue = exports.parseWorkSecrets = exports.getPortableSecretName = exports.getSecretName = exports.getUnreadableSecrets = exports.describeSecretSource = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const os_1 = require("os");
|
|
6
6
|
const fs_1 = require("fs");
|
|
@@ -17,9 +17,17 @@ function describeSecretSource(secret) {
|
|
|
17
17
|
if (source.type === 'provider') {
|
|
18
18
|
return `${source.provider}:${source.ref} as ${source.account}`;
|
|
19
19
|
}
|
|
20
|
+
if (source.type === 'unavailable') {
|
|
21
|
+
return source.from;
|
|
22
|
+
}
|
|
20
23
|
return source.type === 'env' ? `env:${source.name}` : `file:${source.path}`;
|
|
21
24
|
}
|
|
22
25
|
exports.describeSecretSource = describeSecretSource;
|
|
26
|
+
// What a task or service reads that this machine can't, one line each, for `ls` and `validate`
|
|
27
|
+
function getUnreadableSecrets(secrets) {
|
|
28
|
+
return secrets.flatMap((secret) => (secret.source.type === 'unavailable' ? [secret.source.reason] : []));
|
|
29
|
+
}
|
|
30
|
+
exports.getUnreadableSecrets = getUnreadableSecrets;
|
|
23
31
|
function getSecretName(secret) {
|
|
24
32
|
return secret.target.type === 'env' ? secret.target.name : secret.target.path;
|
|
25
33
|
}
|
|
@@ -61,28 +69,37 @@ function parseSecretSource(secret, ref, cwd, envs, catalog, taskAccount, owner,
|
|
|
61
69
|
return { type: 'file', path: (0, normalize_path_1.normalizePath)(cwd, (0, os_1.homedir)(), (0, template_value_1.templateValue)(ref, envs)) };
|
|
62
70
|
}
|
|
63
71
|
const reads = `${owner} reads ${label} from ${secret.from}`;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
throw new Error(unknownProviderMessage(catalog, reads, kind));
|
|
67
|
-
}
|
|
72
|
+
// what the build file gets wrong fails it as a whole; what this machine does not declare
|
|
73
|
+
// fails only a run that reads the secret
|
|
68
74
|
const providerRef = (0, template_value_1.templateValue)(ref, envs);
|
|
69
75
|
if (providerRef.length === 0 || providerRef.startsWith('-')) {
|
|
70
76
|
throw new Error(`${reads}: a reference for ${kind} must not be empty or start with -`);
|
|
71
77
|
}
|
|
78
|
+
const unavailable = (reason, error) => ({
|
|
79
|
+
type: 'unavailable',
|
|
80
|
+
from: secret.from,
|
|
81
|
+
reason: `${label} from ${secret.from}: ${reason}`,
|
|
82
|
+
error,
|
|
83
|
+
});
|
|
84
|
+
const server = !!catalog.explicitAccounts;
|
|
85
|
+
const provider = (0, secret_catalog_1.declared)(catalog.providers, kind);
|
|
86
|
+
if (!provider) {
|
|
87
|
+
return unavailable(server ? `this server has no secret provider ${kind}` : `no secret provider ${kind} is declared`, unknownProviderMessage(catalog, reads, kind));
|
|
88
|
+
}
|
|
72
89
|
const accountName = catalog.explicitAccounts
|
|
73
90
|
? secret.account
|
|
74
91
|
: secret.account ?? taskAccount ?? Object.values(catalog.accounts).find((a) => a.default)?.name;
|
|
75
92
|
if (!accountName) {
|
|
76
|
-
|
|
93
|
+
return unavailable(server ? 'it names no account' : 'no account is named and none is the default', missingAccountMessage(catalog, reads, owner));
|
|
77
94
|
}
|
|
78
95
|
const account = (0, secret_catalog_1.declared)(catalog.accounts, accountName);
|
|
79
96
|
if (!account) {
|
|
80
97
|
const namedBy = secret.account ? 'the account: of the secret' : `the account: of ${owner}`;
|
|
81
|
-
|
|
98
|
+
return unavailable(server ? `this server has no account ${accountName}` : `no account ${accountName} is declared`, unknownAccountMessage(catalog, reads, owner, accountName, namedBy, kind));
|
|
82
99
|
}
|
|
83
100
|
const credentials = (0, secret_catalog_1.declared)(account.providers, kind);
|
|
84
101
|
if (!credentials) {
|
|
85
|
-
|
|
102
|
+
return unavailable(`account ${accountName} has no credentials for ${kind}`, missingCredentialsMessage(catalog, reads, account, kind));
|
|
86
103
|
}
|
|
87
104
|
return {
|
|
88
105
|
type: 'provider',
|
|
@@ -110,10 +127,9 @@ function listDeclared(definitions, server) {
|
|
|
110
127
|
}
|
|
111
128
|
return [...byFile.entries()].map(([file, names]) => `${names.join(', ')} in ${file}`).join(' and ');
|
|
112
129
|
}
|
|
113
|
-
//
|
|
114
|
-
// the tasks that don't read it, too.
|
|
130
|
+
// Only a run that reads the secret fails: the other tasks of the build file run.
|
|
115
131
|
function seeDocs(anchor) {
|
|
116
|
-
return `
|
|
132
|
+
return `See ${SECRET_PROVIDERS_DOCS}#${anchor}`;
|
|
117
133
|
}
|
|
118
134
|
function hostConfigOf(catalog) {
|
|
119
135
|
return catalog.hostConfig ?? 'the host config';
|
|
@@ -213,6 +229,9 @@ function missingCredentialsMessage(catalog, reads, account, provider) {
|
|
|
213
229
|
].join('\n');
|
|
214
230
|
}
|
|
215
231
|
function readSecretValueSync(secret, environment) {
|
|
232
|
+
if (secret.source.type === 'unavailable') {
|
|
233
|
+
throw new Error(secret.source.error);
|
|
234
|
+
}
|
|
216
235
|
if (secret.source.type === 'env') {
|
|
217
236
|
const value = environment.processEnvs[secret.source.name];
|
|
218
237
|
if (value === undefined || value === null) {
|
|
@@ -239,6 +258,9 @@ function readSecretValueSync(secret, environment) {
|
|
|
239
258
|
// The value, read when the task or service starts (or when a cache-affecting
|
|
240
259
|
// secret is hashed); a missing source fails naming the secret.
|
|
241
260
|
async function resolveSecretValue(secret, environment) {
|
|
261
|
+
if (secret.source.type === 'unavailable') {
|
|
262
|
+
throw new Error(secret.source.error);
|
|
263
|
+
}
|
|
242
264
|
if (secret.source.type === 'env') {
|
|
243
265
|
const value = environment.processEnvs[secret.source.name];
|
|
244
266
|
if (value === undefined || value === null) {
|
package/dist/program.js
CHANGED
|
@@ -31,6 +31,7 @@ const run_worker_command_1 = require("./server/run-worker-command");
|
|
|
31
31
|
const github_app_token_command_1 = require("./secrets/github-app-token-command");
|
|
32
32
|
const work_network_1 = require("./planner/work-network");
|
|
33
33
|
const task_arguments_1 = require("./planner/utils/task-arguments");
|
|
34
|
+
const work_secret_1 = require("./planner/work-secret");
|
|
34
35
|
async function createCli(fileName, environment, workScope) {
|
|
35
36
|
const { ctx, scope } = await (0, schema_parser_1.createParseContext)(fileName, environment);
|
|
36
37
|
const referencedScope = await (0, reference_parser_1.parseReferences)(ctx, scope, environment);
|
|
@@ -83,9 +84,22 @@ function printTaskDefinition(environment, definition) {
|
|
|
83
84
|
(0, log_1.printProperty)(environment, `env ${reference.name}`, `from $${reference.from} ${colors_1.default.grey(reference.available ? '(set)' : '(not set)')}`);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
87
|
+
// A task or service that reads a secret this machine can't read is listed, saying so: only
|
|
88
|
+
// running it fails
|
|
89
|
+
function printUnreadableSecrets(environment, item) {
|
|
90
|
+
for (const reason of (0, work_secret_1.getUnreadableSecrets)('secrets' in item ? item.secrets : [])) {
|
|
91
|
+
(0, log_1.printProperty)(environment, "can't run here", reason);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// only when there are, so the list of a build file without them stays as it was
|
|
95
|
+
function unreadableJson(item) {
|
|
96
|
+
const unreadable = (0, work_secret_1.getUnreadableSecrets)('secrets' in item ? item.secrets : []);
|
|
97
|
+
return unreadable.length > 0 ? { unreadableSecrets: unreadable } : {};
|
|
98
|
+
}
|
|
86
99
|
// `ls --json`: what a caller (an agent picking a task) needs to know, with the
|
|
87
100
|
// command that arguments after `--` are appended to (null: it takes none) and
|
|
88
|
-
// `args` as the build file says it (false: it refuses them)
|
|
101
|
+
// `args` as the build file says it (false: it refuses them), and the secrets this
|
|
102
|
+
// machine can't read, which make running it fail (`unreadableSecrets`, when there are).
|
|
89
103
|
function getListJson(tasks, services) {
|
|
90
104
|
return {
|
|
91
105
|
tasks: tasks.map(({ item }) => ({
|
|
@@ -98,6 +112,7 @@ function getListJson(tasks, services) {
|
|
|
98
112
|
labels: item.data.labels,
|
|
99
113
|
command: (0, task_arguments_1.getArgumentsTarget)(item.data)?.cmd ?? null,
|
|
100
114
|
args: item.data.args,
|
|
115
|
+
...unreadableJson(item.data),
|
|
101
116
|
})),
|
|
102
117
|
services: services.map(({ item }) => ({
|
|
103
118
|
name: item.name,
|
|
@@ -108,6 +123,7 @@ function getListJson(tasks, services) {
|
|
|
108
123
|
labels: item.data.labels,
|
|
109
124
|
command: (0, task_arguments_1.getArgumentsTarget)(item.data)?.cmd ?? null,
|
|
110
125
|
args: item.data.type === 'container-service' ? item.data.args : null,
|
|
126
|
+
...unreadableJson(item.data),
|
|
111
127
|
})),
|
|
112
128
|
};
|
|
113
129
|
}
|
|
@@ -204,6 +220,7 @@ async function getProgram(environment, argv) {
|
|
|
204
220
|
(0, log_1.printTitle)(environment, 'Services');
|
|
205
221
|
for (const service of services) {
|
|
206
222
|
(0, log_1.printItem)(environment, service.item.data);
|
|
223
|
+
printUnreadableSecrets(environment, service.item.data);
|
|
207
224
|
(0, log_1.printProperty)(environment, 'ports', service.item.data.ports.map((p) => `127.0.0.1:${p.hostPort} -> ${p.containerPort}`).join(', '));
|
|
208
225
|
if (service.item.data.type === 'kubernetes-service') {
|
|
209
226
|
(0, log_1.printProperty)(environment, 'context', service.item.data.context);
|
|
@@ -221,6 +238,7 @@ async function getProgram(environment, argv) {
|
|
|
221
238
|
(0, log_1.printTitle)(environment, 'Tasks');
|
|
222
239
|
for (const task of tasks) {
|
|
223
240
|
(0, log_1.printItem)(environment, task.item.data);
|
|
241
|
+
printUnreadableSecrets(environment, task.item.data);
|
|
224
242
|
if (task.item.needs.length > 0) {
|
|
225
243
|
(0, log_1.printProperty)(environment, 'needs', task.item.needs.map((d) => d.name).join(', '));
|
|
226
244
|
}
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prefetchSecrets = void 0;
|
|
3
|
+
exports.prefetchSecrets = exports.requireReadableSecrets = void 0;
|
|
4
4
|
const plan_work_tasks_1 = require("../planner/utils/plan-work-tasks");
|
|
5
5
|
const work_secret_1 = require("../planner/work-secret");
|
|
6
6
|
const provider_values_1 = require("./provider-values");
|
|
7
|
+
function secretsOf(workTree) {
|
|
8
|
+
return [
|
|
9
|
+
...[...(0, plan_work_tasks_1.iterateWorkServices)(workTree)].flatMap((service) => ('secrets' in service.data ? service.data.secrets : [])),
|
|
10
|
+
...[...(0, plan_work_tasks_1.iterateWorkTasks)(workTree)].flatMap((task) => task.data.secrets),
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
// A secret of a provider that this machine does not declare fails a command only when the
|
|
14
|
+
// command needs it: a run needs every secret of the tasks and services it holds, the other
|
|
15
|
+
// commands the `cache: true` ones, for task ids. A task elsewhere in the build file that reads
|
|
16
|
+
// it does not stop them (ADR 0008).
|
|
17
|
+
function requireReadableSecrets(workTree, needed = () => true) {
|
|
18
|
+
for (const secret of secretsOf(workTree)) {
|
|
19
|
+
if (secret.source.type === 'unavailable' && needed(secret)) {
|
|
20
|
+
throw new Error(secret.source.error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.requireReadableSecrets = requireReadableSecrets;
|
|
7
25
|
// Fetches the values a task id needs; a run drops the ones of the previous run
|
|
8
26
|
// first (`newRun`), any other command reuses what the run already fetched. A task id is computed synchronously and holds the
|
|
9
27
|
// digest of each `cache: true` secret, so those values must be in memory before
|
|
10
28
|
// anything asks for an id. Secrets that don't affect the id are read when their
|
|
11
29
|
// task starts, and a plan without provider secrets calls no provider.
|
|
12
30
|
async function prefetchSecrets(workTree, environment, newRun = false) {
|
|
31
|
+
requireReadableSecrets(workTree, (secret) => secret.cache);
|
|
13
32
|
if (newRun) {
|
|
14
33
|
(0, provider_values_1.beginSecretRun)(environment);
|
|
15
34
|
}
|
package/dist/server/plan.js
CHANGED
|
@@ -19,6 +19,7 @@ const parse_error_1 = require("../schema/parse-error");
|
|
|
19
19
|
const task_arguments_1 = require("../planner/utils/task-arguments");
|
|
20
20
|
const work_network_1 = require("../planner/work-network");
|
|
21
21
|
const run_source_envs_1 = require("../environment/run-source-envs");
|
|
22
|
+
const prefetch_secrets_1 = require("../secrets/prefetch-secrets");
|
|
22
23
|
class DefinitionError extends Error {
|
|
23
24
|
}
|
|
24
25
|
exports.DefinitionError = DefinitionError;
|
|
@@ -167,6 +168,9 @@ function describeSecret(secret) {
|
|
|
167
168
|
if (source.type === 'provider') {
|
|
168
169
|
return { from: `${source.provider}:${source.ref}`, account: source.account, target };
|
|
169
170
|
}
|
|
171
|
+
if (source.type === 'unavailable') {
|
|
172
|
+
return { from: source.from, account: null, target };
|
|
173
|
+
}
|
|
170
174
|
return { from: source.type === 'env' ? `env:${source.name}` : `file:${source.path}`, account: null, target };
|
|
171
175
|
}
|
|
172
176
|
// What a server refuses to publish. A secret that reads a file or a variable of the
|
|
@@ -423,6 +427,10 @@ async function planBundle(bundle, environment, options = {}) {
|
|
|
423
427
|
}
|
|
424
428
|
const context = await (0, reference_parser_1.parseReferences)(ctx, scope, inspected);
|
|
425
429
|
const workTree = (0, work_scope_parser_1.getWorkContext)(context, options.scope ?? { environmentName: null }, inspected);
|
|
430
|
+
// the server's providers and accounts are the ones that count: a task it could never read
|
|
431
|
+
// a secret of is refused when it is published, and a run when it is planned (only the
|
|
432
|
+
// tasks and services of the run count then)
|
|
433
|
+
(0, prefetch_secrets_1.requireReadableSecrets)(workTree);
|
|
426
434
|
const items = itemsOf(workTree);
|
|
427
435
|
if (options.policy) {
|
|
428
436
|
const policyProblems = findPolicyProblems(items, options.policy, directory);
|
package/package.json
CHANGED