hammerkit 2.0.0-next.18 → 2.0.0-next.19

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.
@@ -36,12 +36,7 @@ exports.hasShell = hasShell;
36
36
  */
37
37
  async function connectServer(environment, options) {
38
38
  const config = await (0, host_config_1.readHostConfig)(environment);
39
- const name = options.server ?? config.run.on;
40
- if (!name || !(0, host_config_1.hasServer)(config.servers, name)) {
41
- throw new Error(options.server
42
- ? `server ${options.server} is not registered, add it with: hammerkit remote add ${options.server} <url> --issuer <url>`
43
- : 'name a server (HAMMERKIT_SERVER or --server), or set a default with: hammerkit remote use <name>');
44
- }
39
+ const name = (0, host_config_1.chooseServer)(config, options.server || undefined, 'with HAMMERKIT_SERVER or --server');
45
40
  if (!options.build) {
46
41
  throw new Error('name the published version of the build file whose tasks run on the sandbox by its hash (HAMMERKIT_BUILD or --build), as hammerkit remote publish printed it');
47
42
  }
@@ -25,7 +25,7 @@ function registerMcpCommand(remote, environment, input = process.stdin) {
25
25
  remote
26
26
  .command('mcp')
27
27
  .description('serve the files, shell and tasks of a sandbox on a server as MCP tools over stdio (experimental)')
28
- .addOption(new commander_1.Option('--server <name>', 'registered server (default: hammerkit remote use)').env('HAMMERKIT_SERVER'))
28
+ .addOption(new commander_1.Option('--server <name>', 'registered server (default: hammerkit remote use, or the only registered server)').env('HAMMERKIT_SERVER'))
29
29
  .addOption(new commander_1.Option('--sandbox <id>', 'a sandbox of yours on the server').env('HAMMERKIT_SANDBOX'))
30
30
  .addOption(new commander_1.Option('--repo <repo>', 'create a sandbox of this repository').env('HAMMERKIT_REPO'))
31
31
  .addOption(new commander_1.Option('--ref <ref>', 'at this branch').env('HAMMERKIT_REF'))
@@ -115,7 +115,7 @@ function parseService(workTree, service, environment, context) {
115
115
  caching,
116
116
  // set once the service is planned, see appendServiceInit
117
117
  init: null,
118
- secrets: (0, work_secret_1.parseWorkSecrets)(service.cwd, context.projectRoot, service.schema.secrets, envs, environment, context.secrets, service.schema.account),
118
+ secrets: (0, work_secret_1.parseWorkSecrets)(service.cwd, context.projectRoot, service.schema.secrets, envs, environment, context.secrets, `service ${service.relativeName}`, service.schema.account),
119
119
  resources: (0, work_resources_1.parseWorkResources)(service.schema.resources),
120
120
  volumeSize: service.schema.volumeSize ?? null,
121
121
  restarts: service.schema.restarts ?? null,
@@ -80,7 +80,7 @@ function parseTask(cwd, task, environment, context) {
80
80
  caching: (0, resolve_cache_1.resolveCache)(task.schema.cache ?? null, context.caches, task.relativeName),
81
81
  shell: task.schema.shell ? (0, template_value_1.templateValue)(task.schema.shell, envs) : '/bin/sh',
82
82
  timeout: task.schema.timeout ? (0, units_1.parseDuration)(task.schema.timeout) : null,
83
- secrets: (0, work_secret_1.parseWorkSecrets)(cwd, context.projectRoot, task.schema.secrets, envs, environment, context.secrets, task.schema.account),
83
+ secrets: (0, work_secret_1.parseWorkSecrets)(cwd, context.projectRoot, task.schema.secrets, envs, environment, context.secrets, `task ${task.relativeName}`, task.schema.account),
84
84
  resources: (0, work_resources_1.parseWorkResources)(task.schema.resources),
85
85
  network: (0, work_network_1.parseWorkNetwork)(task.schema.network),
86
86
  networkCeiling: null,
@@ -31,6 +31,8 @@ function getPortableSecretName(projectRoot, secret) {
31
31
  }
32
32
  exports.getPortableSecretName = getPortableSecretName;
33
33
  function parseWorkSecrets(cwd, projectRoot, secrets, envs, environment, catalog,
34
+ // what the secrets belong to, for messages: `task build` or `service db`
35
+ owner,
34
36
  // the service account of the task or service the secrets belong to
35
37
  account) {
36
38
  return (secrets ?? []).map((secret) => {
@@ -39,7 +41,7 @@ account) {
39
41
  ? { type: 'env', name: secret.env }
40
42
  : { type: 'file', path: (0, normalize_path_1.normalizePath)(cwd, cwd, (0, template_value_1.templateValue)(secret.path ?? '', envs)) };
41
43
  const name = target.type === 'env' ? target.name : secret.path;
42
- const source = parseSecretSource(secret, ref, cwd, envs, catalog, account, `secret ${name}`);
44
+ const source = parseSecretSource(secret, ref, cwd, envs, catalog, account, owner, `secret ${name}`);
43
45
  const workSecret = {
44
46
  source,
45
47
  target,
@@ -50,7 +52,7 @@ account) {
50
52
  });
51
53
  }
52
54
  exports.parseWorkSecrets = parseWorkSecrets;
53
- function parseSecretSource(secret, ref, cwd, envs, catalog, taskAccount, label) {
55
+ function parseSecretSource(secret, ref, cwd, envs, catalog, taskAccount, owner, label) {
54
56
  const kind = secret.from.substring(0, secret.from.indexOf(':'));
55
57
  if (kind === 'env') {
56
58
  return { type: 'env', name: ref };
@@ -58,30 +60,29 @@ function parseSecretSource(secret, ref, cwd, envs, catalog, taskAccount, label)
58
60
  if (kind === 'file') {
59
61
  return { type: 'file', path: (0, normalize_path_1.normalizePath)(cwd, (0, os_1.homedir)(), (0, template_value_1.templateValue)(ref, envs)) };
60
62
  }
63
+ const reads = `${owner} reads ${label} from ${secret.from}`;
61
64
  const provider = (0, secret_catalog_1.declared)(catalog.providers, kind);
62
65
  if (!provider) {
63
- const declared = Object.keys(catalog.providers);
64
- throw new Error(`${label}: unknown secret provider ${kind}, ${declared.length > 0 ? `declared: ${declared.join(', ')}` : 'none is declared'}`);
66
+ throw new Error(unknownProviderMessage(catalog, reads, kind));
65
67
  }
66
68
  const providerRef = (0, template_value_1.templateValue)(ref, envs);
67
69
  if (providerRef.length === 0 || providerRef.startsWith('-')) {
68
- throw new Error(`${label}: a reference for ${kind} must not be empty or start with -`);
70
+ throw new Error(`${reads}: a reference for ${kind} must not be empty or start with -`);
69
71
  }
70
72
  const accountName = catalog.explicitAccounts
71
73
  ? secret.account
72
74
  : secret.account ?? taskAccount ?? Object.values(catalog.accounts).find((a) => a.default)?.name;
73
75
  if (!accountName) {
74
- throw new Error(catalog.explicitAccounts
75
- ? `${label}: ${kind}:${providerRef} needs account: on the secret, a server uses neither a task's account nor a default`
76
- : `${label}: ${kind}:${providerRef} needs an account, and none is named or marked default: true`);
76
+ throw new Error(missingAccountMessage(catalog, reads, owner));
77
77
  }
78
78
  const account = (0, secret_catalog_1.declared)(catalog.accounts, accountName);
79
79
  if (!account) {
80
- throw new Error(`${label}: unknown secret account ${accountName}, declared: ${Object.keys(catalog.accounts).join(', ') || 'none'}`);
80
+ const namedBy = secret.account ? 'the account: of the secret' : `the account: of ${owner}`;
81
+ throw new Error(unknownAccountMessage(catalog, reads, owner, accountName, namedBy, kind));
81
82
  }
82
83
  const credentials = (0, secret_catalog_1.declared)(account.providers, kind);
83
84
  if (!credentials) {
84
- throw new Error(`${label}: account ${accountName} has no credentials for provider ${kind}`);
85
+ throw new Error(missingCredentialsMessage(catalog, reads, account, kind));
85
86
  }
86
87
  return {
87
88
  type: 'provider',
@@ -91,6 +92,126 @@ function parseSecretSource(secret, ref, cwd, envs, catalog, taskAccount, label)
91
92
  binding: { definition: provider, account: { name: accountName, env: credentials.env } },
92
93
  };
93
94
  }
95
+ // The messages below say what is wrong, where the names come from and what to write: a
96
+ // person who only ran a task should not need to know how secrets are declared. On a
97
+ // server the build file can only change what it names, the operator declares the rest.
98
+ const SECRET_PROVIDERS_DOCS = 'https://hammerkit.dev/docs/task/secret-providers';
99
+ // `tests, dev in ~/.hammerkit/config.yaml and ci in .hammerkit.yaml`, or `none`
100
+ function listDeclared(definitions, server) {
101
+ if (definitions.length === 0) {
102
+ return 'none';
103
+ }
104
+ if (server) {
105
+ return definitions.map((d) => d.name).join(', ');
106
+ }
107
+ const byFile = new Map();
108
+ for (const definition of definitions) {
109
+ byFile.set(definition.declaredIn, [...(byFile.get(definition.declaredIn) ?? []), definition.name]);
110
+ }
111
+ return [...byFile.entries()].map(([file, names]) => `${names.join(', ')} in ${file}`).join(' and ');
112
+ }
113
+ // A build file is checked as a whole when it is read, so one wrong secret stops
114
+ // the tasks that don't read it, too.
115
+ function seeDocs(anchor) {
116
+ return `Every task of the build file is checked when it is read, so this stops other tasks too. See ${SECRET_PROVIDERS_DOCS}#${anchor}`;
117
+ }
118
+ function hostConfigOf(catalog) {
119
+ return catalog.hostConfig ?? 'the host config';
120
+ }
121
+ function indent(lines) {
122
+ return lines.map((line) => ` ${line}`).join('\n');
123
+ }
124
+ // A variable of this machine to hold the credential, for snippets: `${OPERATOR_CREDENTIALS}`
125
+ function credentialVariable(account, key, keys) {
126
+ const prefix = account.toUpperCase().replace(/[^A-Z0-9]+/g, '_');
127
+ return `\${${prefix}_${keys === 1 ? 'CREDENTIALS' : key}}`;
128
+ }
129
+ // The credential variables a provider's command reads, as another account passes them;
130
+ // a placeholder when no account has credentials for the provider yet
131
+ function credentialLines(catalog, account, provider) {
132
+ const sibling = Object.values(catalog.accounts).find((a) => (0, secret_catalog_1.declared)(a.providers, provider));
133
+ const keys = sibling ? Object.keys(sibling.providers[provider].env) : [];
134
+ if (keys.length === 0) {
135
+ return [`<VARIABLE>: \${<VARIABLE OF THIS MACHINE>} # what ${provider} reads its credential from`];
136
+ }
137
+ return keys.map((key) => `${key}: ${credentialVariable(account, key, keys.length)}`);
138
+ }
139
+ function unknownProviderMessage(catalog, reads, kind) {
140
+ const declaredProviders = listDeclared(Object.values(catalog.providers), !!catalog.explicitAccounts);
141
+ if (catalog.explicitAccounts) {
142
+ return (`${reads}, but this server has no secret provider ${kind} (it has: ${declaredProviders}). ` +
143
+ `Use one of its providers, or ask the operator of the server to add ${kind} to its config.`);
144
+ }
145
+ return [
146
+ `${reads}, but no secret provider ${kind} is declared (declared: ${declaredProviders}).`,
147
+ `A provider is the command that prints a secret's value. Declare it in the host config, ${hostConfigOf(catalog)}:`,
148
+ '',
149
+ indent(['secretProviders:', ` ${kind}:`, ` command: [<command>, <its arguments>, '{{ref}}']`]),
150
+ '',
151
+ seeDocs('providers'),
152
+ ].join('\n');
153
+ }
154
+ function missingAccountMessage(catalog, reads, owner) {
155
+ const declaredAccounts = listDeclared(Object.values(catalog.accounts), !!catalog.explicitAccounts);
156
+ if (catalog.explicitAccounts) {
157
+ return (`${reads}, but names no account. A server reads every secret as the account the secret names, ` +
158
+ `never as the account of a task or a default: add account: to the secret (this server has: ${declaredAccounts}).`);
159
+ }
160
+ return [
161
+ `${reads}, but neither the secret nor ${owner} names an account, and no account is marked default: true (declared: ${declaredAccounts}).`,
162
+ `An account says which credential a secret is read with. Name one with account: on the secret or on ${owner}, ` +
163
+ `or mark one as the default in ${hostConfigOf(catalog)}:`,
164
+ '',
165
+ indent(['secretAccounts:', ' <account>:', ' default: true']),
166
+ '',
167
+ seeDocs('accounts'),
168
+ ].join('\n');
169
+ }
170
+ function unknownAccountMessage(catalog, reads, owner, account, namedBy, provider) {
171
+ const declaredAccounts = listDeclared(Object.values(catalog.accounts), !!catalog.explicitAccounts);
172
+ if (catalog.explicitAccounts) {
173
+ return (`${reads} as account ${account}, but this server has no account ${account} (it has: ${declaredAccounts}). ` +
174
+ `Name one of its accounts with account: on the secret, or ask the operator of the server to add ${account} to its config.`);
175
+ }
176
+ return [
177
+ `${reads} as account ${account} (${namedBy}), but no account ${account} is declared (declared: ${declaredAccounts}).`,
178
+ `An account says which credential a secret is read with, and each machine declares its own in its host config, ` +
179
+ `${hostConfigOf(catalog)}. Add ${account} there:`,
180
+ '',
181
+ indent([
182
+ 'secretAccounts:',
183
+ ` ${account}:`,
184
+ ' providers:',
185
+ ` ${provider}:`,
186
+ ' env:',
187
+ ...credentialLines(catalog, account, provider).map((line) => ` ${line}`),
188
+ ]),
189
+ '',
190
+ `Or read the secret as one of the declared accounts with account: on the secret${namedBy === 'the account: of the secret' ? '' : ` or on ${owner}`}.`,
191
+ seeDocs('accounts'),
192
+ ].join('\n');
193
+ }
194
+ function missingCredentialsMessage(catalog, reads, account, provider) {
195
+ if (catalog.explicitAccounts) {
196
+ return (`${reads} as account ${account.name}, but that account of this server has no credentials for ${provider}. ` +
197
+ `Ask the operator of the server to add them to its config.`);
198
+ }
199
+ return [
200
+ `${reads} as account ${account.name}, but account ${account.name} (in ${account.declaredIn}) has no credentials for provider ${provider}.`,
201
+ `Add the variables that make ${provider} act as ${account.name}:`,
202
+ '',
203
+ indent([
204
+ 'secretAccounts:',
205
+ ` ${account.name}:`,
206
+ ' providers:',
207
+ ` ${provider}:`,
208
+ ' env:',
209
+ ...credentialLines(catalog, account.name, provider).map((line) => ` ${line}`),
210
+ ]),
211
+ '',
212
+ seeDocs('accounts'),
213
+ ].join('\n');
214
+ }
94
215
  function readSecretValueSync(secret, environment) {
95
216
  if (secret.source.type === 'env') {
96
217
  const value = environment.processEnvs[secret.source.name];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pinLogin = exports.setDefaultLocation = exports.removeServer = exports.addServer = exports.normalizeServerUrl = exports.validateServerName = exports.writeHostConfig = exports.readHostConfig = exports.getHostConfigPath = exports.getRegisteredServer = exports.getTokenCommand = exports.hasServer = exports.hostConfigSchema = exports.hostServerSchema = exports.RESERVED_SERVER_NAMES = void 0;
3
+ exports.pinLogin = exports.setDefaultLocation = exports.removeServer = exports.addServer = exports.normalizeServerUrl = exports.validateServerName = exports.writeHostConfig = exports.readHostConfig = exports.getHostConfigPath = exports.chooseServer = exports.notRegisteredMessage = exports.getRegisteredServer = exports.getTokenCommand = exports.hasServer = exports.hostConfigSchema = exports.hostServerSchema = exports.RESERVED_SERVER_NAMES = void 0;
4
4
  const path_1 = require("path");
5
5
  const zod_1 = require("zod");
6
6
  const yaml_1 = require("yaml");
@@ -69,6 +69,52 @@ function getRegisteredServer(config, name) {
69
69
  return { ...config.servers[name], ...(tokenCommand ? { tokenCommand } : {}) };
70
70
  }
71
71
  exports.getRegisteredServer = getRegisteredServer;
72
+ // `a, b and c`
73
+ function listNames(names) {
74
+ return names.length > 1 ? `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}` : names.join('');
75
+ }
76
+ // `(registered: a and b)`, for a name that is not one of them
77
+ function registeredNote(config) {
78
+ const names = Object.keys(config.servers).sort();
79
+ return names.length === 0 ? '(no server is registered yet)' : `(registered: ${listNames(names)})`;
80
+ }
81
+ // `server nope is not registered (registered: a and b)`, with how to add it unless it is being removed
82
+ function notRegisteredMessage(config, name, howToAdd = true) {
83
+ const add = howToAdd ? `, add it with: hammerkit remote add ${name} <url> --issuer <url>` : '';
84
+ return `server ${name} is not registered ${registeredNote(config)}${add}`;
85
+ }
86
+ exports.notRegisteredMessage = notRegisteredMessage;
87
+ // The server a remote command talks to: the one it names, else the default of `remote use`,
88
+ // else the only one registered. With several and no default, the person names one.
89
+ // A default that names a server no longer registered is an error, as it is for `hammerkit run`:
90
+ // a call never goes to another server than the one chosen. `how` says how a name is given,
91
+ // for the message: `with --server <name>`.
92
+ function chooseServer(config, name, how = 'as the last argument') {
93
+ if (name !== undefined) {
94
+ if (!hasServer(config.servers, name)) {
95
+ throw new Error(notRegisteredMessage(config, name));
96
+ }
97
+ return name;
98
+ }
99
+ const on = config.run.on;
100
+ if (on && !exports.RESERVED_SERVER_NAMES.includes(on)) {
101
+ if (!hasServer(config.servers, on)) {
102
+ throw new Error(`the default of remote use, server ${on}, is not registered ${registeredNote(config)}; ` +
103
+ `pick another with: hammerkit remote use <name>, or add it with: hammerkit remote add ${on} <url> --issuer <url>`);
104
+ }
105
+ return on;
106
+ }
107
+ const names = Object.keys(config.servers).sort();
108
+ if (names.length === 1) {
109
+ return names[0];
110
+ }
111
+ if (names.length === 0) {
112
+ throw new Error('no server is registered, add one with: hammerkit remote add <name> <url> --issuer <url>');
113
+ }
114
+ throw new Error(`${names.length} servers are registered (${listNames(names)}), name one ${how}, ` +
115
+ `or make one the default with: hammerkit remote use <name>`);
116
+ }
117
+ exports.chooseServer = chooseServer;
72
118
  function setTokenCommand(config, name, entry) {
73
119
  const commands = { ...(config.tokenCommands ?? {}) };
74
120
  if (entry) {
@@ -201,7 +247,7 @@ exports.addServer = addServer;
201
247
  async function removeServer(environment, name) {
202
248
  const config = await readHostConfig(environment);
203
249
  if (!hasServer(config.servers, name)) {
204
- throw new Error(`server "${name}" is not registered`);
250
+ throw new Error(notRegisteredMessage(config, name, false));
205
251
  }
206
252
  delete config.servers[name];
207
253
  setTokenCommand(config, name, undefined);
@@ -216,7 +262,7 @@ exports.removeServer = removeServer;
216
262
  async function setDefaultLocation(environment, on) {
217
263
  const config = await readHostConfig(environment);
218
264
  if (!exports.RESERVED_SERVER_NAMES.includes(on) && !hasServer(config.servers, on)) {
219
- throw new Error(`server "${on}" is not registered; add it with: hammerkit remote add ${on} <url> --issuer <url>`);
265
+ throw new Error(notRegisteredMessage(config, on));
220
266
  }
221
267
  config.run.on = on;
222
268
  await writeHostConfig(environment, config);
@@ -14,7 +14,7 @@ async function resolveRunLocation(workTree, environment, options = {}) {
14
14
  const config = await (0, host_config_1.readHostConfig)(environment);
15
15
  const explicit = options.local ? 'local' : options.on ?? (environment.processEnvs.HAMMERKIT_ON || undefined);
16
16
  if (explicit && explicit !== 'auto') {
17
- return explicit === 'local' ? { type: 'local' } : lookup(config.servers, explicit);
17
+ return explicit === 'local' ? { type: 'local' } : lookup(config, explicit);
18
18
  }
19
19
  const runners = getTaskRunners(workTree);
20
20
  if (runners.length > 1) {
@@ -24,13 +24,13 @@ async function resolveRunLocation(workTree, environment, options = {}) {
24
24
  if (!requested || requested === 'local' || requested === 'auto') {
25
25
  return { type: 'local' };
26
26
  }
27
- return lookup(config.servers, requested);
27
+ return lookup(config, requested);
28
28
  }
29
29
  exports.resolveRunLocation = resolveRunLocation;
30
- function lookup(servers, name) {
31
- const server = (0, host_config_1.hasServer)(servers, name) ? servers[name] : undefined;
30
+ function lookup(config, name) {
31
+ const server = (0, host_config_1.hasServer)(config.servers, name) ? config.servers[name] : undefined;
32
32
  if (!server) {
33
- throw new Error(`server ${name} is not registered, add it with: hammerkit remote add ${name} <url> --issuer <url>`);
33
+ throw new Error((0, host_config_1.notRegisteredMessage)(config, name));
34
34
  }
35
35
  return { type: 'server', name, server };
36
36
  }
@@ -94,21 +94,17 @@ passthrough = []) {
94
94
  await (0, host_config_1.setDefaultLocation)(environment, location);
95
95
  environment.stdout.write(`default location: ${location}\n`);
96
96
  }));
97
- const getServer = async (name) => {
97
+ // a command that takes a server: the named one, the default or the only one, see chooseServer
98
+ const getServer = async (name, how) => {
98
99
  const config = await (0, host_config_1.readHostConfig)(environment);
99
- const chosen = name ?? config.run.on;
100
- if (!chosen || !(0, host_config_1.hasServer)(config.servers, chosen)) {
101
- throw new Error(name
102
- ? `server ${name} is not registered, add it with: hammerkit remote add ${name} <url> --issuer <url>`
103
- : 'name a server, or set one as the default with: hammerkit remote use <name>');
104
- }
100
+ const chosen = (0, host_config_1.chooseServer)(config, name, how);
105
101
  return { name: chosen, server: (0, host_config_1.getRegisteredServer)(config, chosen) };
106
102
  };
107
103
  remote
108
- .command('login <name>')
109
- .description('sign in to a registered server with your identity provider (device code, works headless)')
110
- .action(guarded('Remote login was not successful', async (name) => {
111
- const { server } = await getServer(name);
104
+ .command('login [name]')
105
+ .description('sign in to a registered server with your identity provider (device code, works headless); the name can be left out when only one server is registered or one is set with remote use')
106
+ .action(guarded('Remote login was not successful', async (given) => {
107
+ const { name, server } = await getServer(given);
112
108
  if (server.tokenCommand) {
113
109
  // a sign-in would never be used: the command's token goes first
114
110
  throw new Error(`${name} takes its tokens from its token command (${server.tokenCommand}), it needs no sign-in; ` +
@@ -145,9 +141,11 @@ passthrough = []) {
145
141
  }
146
142
  }));
147
143
  remote
148
- .command('logout <name>')
149
- .description('forget the sign-in to a server')
150
- .action(guarded('Remote logout was not successful', async (name) => {
144
+ .command('logout [name]')
145
+ .description('forget the sign-in to a server; the name can be left out as for login')
146
+ .action(guarded('Remote logout was not successful', async (given) => {
147
+ // a sign-in outlives its server's registration, so a name given is taken as it is
148
+ const name = given ?? (0, host_config_1.chooseServer)(await (0, host_config_1.readHostConfig)(environment), undefined);
151
149
  const removed = await (0, credentials_1.removeToken)(environment, name);
152
150
  environment.stdout.write(removed ? `signed out of ${name}\n` : `not signed in to ${name}\n`);
153
151
  }));
@@ -186,8 +186,8 @@ function registerWorkCommands(remote, context) {
186
186
  }
187
187
  return { type: 'ref', repo, ref, ...(commit ? { commit } : {}) };
188
188
  };
189
- const connect = async (name) => {
190
- const chosen = await getServer(name);
189
+ const connect = async (name, how) => {
190
+ const chosen = await getServer(name, how);
191
191
  // a CI job or an agent brings its own token, a person signs in
192
192
  const token = await (0, token_source_1.getTokenSource)(environment, chosen.name, chosen.server).token();
193
193
  return { ...chosen, token };
@@ -340,7 +340,7 @@ function registerWorkCommands(remote, context) {
340
340
  remote
341
341
  .command('run <tasks...>')
342
342
  .description('run tasks of a published build file on a server from a git ref, print their output and exit as they did')
343
- .addOption(new commander_1.Option('--server <name>', 'the server to run on; the default of remote use when left out'))
343
+ .addOption(new commander_1.Option('--server <name>', 'the server to run on; when left out, the default of remote use or the only registered server'))
344
344
  .addOption(new commander_1.Option('--build <hash>', 'the published version to run (sha256:...), or HAMMERKIT_BUILD; the hash of the build file here when left out'))
345
345
  .addOption(new commander_1.Option('--repo <host/path>', 'the repository, such as github.com/corp/payments; origin of the checkout here when left out'))
346
346
  .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to run; the branch checked out here when left out'))
@@ -355,7 +355,7 @@ function registerWorkCommands(remote, context) {
355
355
  const { definition, local } = await runDefinition(options);
356
356
  const source = await refSource(options);
357
357
  const ref = source.ref;
358
- const { name: serverName, server } = await getServer(options.server);
358
+ const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
359
359
  const connection = { url: server.url, ...(0, token_source_1.getTokenSource)(environment, serverName, server) };
360
360
  const runOptions = {};
361
361
  for (const key of ['env', 'cache', 'timeout', 'maxTimeout']) {
@@ -407,7 +407,7 @@ function registerWorkCommands(remote, context) {
407
407
  .command('up <services...>')
408
408
  .description('start services of a published build file on a server from a git ref and keep them up until their ttl ends, ' +
409
409
  'with their endpoints at addresses of their own behind the sign-in of the server')
410
- .addOption(new commander_1.Option('--server <name>', 'the server to run on; the default of remote use when left out'))
410
+ .addOption(new commander_1.Option('--server <name>', 'the server to run on; when left out, the default of remote use or the only registered server'))
411
411
  .addOption(new commander_1.Option('--endpoint <service:port>', 'publish this port of a service, such as web:8080; may be given more than once').argParser(collectOption))
412
412
  .addOption(new commander_1.Option('--ttl <duration>', 'how long they stay once ready, such as 2h, then they are removed; the server default when left out'))
413
413
  .addOption(new commander_1.Option('--sleep-ttl <duration>', 'how long they stay up without a request, such as 30m, then they sleep until the next request wakes them; ' +
@@ -424,7 +424,7 @@ function registerWorkCommands(remote, context) {
424
424
  const { definition, local } = await runDefinition(options);
425
425
  const endpoints = (options.endpoint ?? []).map(service_tools_1.parseEndpoint);
426
426
  const source = await refSource(options);
427
- const { name: serverName, server } = await getServer(options.server);
427
+ const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
428
428
  const connection = { url: server.url, ...(0, token_source_1.getTokenSource)(environment, serverName, server) };
429
429
  const submitted = await submitPublishing({ serverName, server, connection }, {
430
430
  definition,
@@ -687,7 +687,7 @@ function registerWorkCommands(remote, context) {
687
687
  .command('verify <tasks...>')
688
688
  .description('check that the server already passed tasks for the files checked out here, without running them; ' +
689
689
  'exits 1 at once for any it did not')
690
- .addOption(new commander_1.Option('--server <name>', 'the server to ask; the default of remote use when left out'))
690
+ .addOption(new commander_1.Option('--server <name>', 'the server to ask; when left out, the default of remote use or the only registered server'))
691
691
  .addOption(new commander_1.Option('--repo <host/path>', 'the repository, such as github.com/corp/payments; origin of the checkout here when left out'))
692
692
  .addOption(new commander_1.Option('--env <name>', 'the environment of the build file, as --env of run'))
693
693
  .action(guarded('Remote verify was not successful', async (tasks, options) => {
@@ -709,7 +709,7 @@ function registerWorkCommands(remote, context) {
709
709
  keys.push({ task, key: found.key });
710
710
  }
711
711
  }
712
- const { name: serverName, server, token } = await connect(options.server);
712
+ const { name: serverName, server, token } = await connect(options.server, 'with --server <name>');
713
713
  const answer = keys.length > 0
714
714
  ? await (0, server_client_1.callServer)(server, token, 'POST', '/v1/checks/lookup', { repo, keys })
715
715
  : { body: { checks: [] } };
@@ -57,6 +57,7 @@ function collectSecretCatalog(files, environment, context, host) {
57
57
  }
58
58
  }
59
59
  if (host) {
60
+ catalog.hostConfig = host.fileName;
60
61
  // the host config has no envs of its own: `${NAME}` is read from the process
61
62
  for (const [name, provider] of Object.entries(host.secretProviders ?? {})) {
62
63
  catalog.providers[name] = toProvider(name, provider, {}, host.fileName);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hammerkit",
3
3
  "description": "Containerized build tool with incremental caching that runs the same build file locally, in Docker and on Kubernetes.",
4
- "version": "2.0.0-next.18",
4
+ "version": "2.0.0-next.19",
5
5
  "keywords": [
6
6
  "build",
7
7
  "build-tool",