@revoengine/cli 2.1.1 → 2.2.0
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/CHANGELOG.md +12 -0
- package/README.md +111 -12
- package/dist/src/application-access.d.ts +4 -0
- package/dist/src/application-access.js +18 -0
- package/dist/src/application-cors.d.ts +2 -0
- package/dist/src/application-cors.js +19 -0
- package/dist/src/argument-contract.js +24 -4
- package/dist/src/automation-contract.generated.d.ts +165 -6
- package/dist/src/automation-contract.generated.js +198 -6
- package/dist/src/cli.js +10 -2
- package/dist/src/client.d.ts +53 -1
- package/dist/src/client.js +84 -0
- package/dist/src/commands/applications.d.ts +2 -0
- package/dist/src/commands/applications.js +44 -0
- package/dist/src/commands/emulate.d.ts +1 -0
- package/dist/src/commands/emulate.js +79 -3
- package/dist/src/commands/index.d.ts +2 -0
- package/dist/src/commands/index.js +2 -0
- package/dist/src/commands/migrate.js +10 -2
- package/dist/src/commands/sites.d.ts +2 -0
- package/dist/src/commands/sites.js +156 -0
- package/dist/src/component-lock.d.ts +2 -1
- package/dist/src/component-lock.js +22 -1
- package/dist/src/endpoint-application.d.ts +25 -0
- package/dist/src/endpoint-application.js +75 -0
- package/dist/src/endpoint-emulator.d.ts +5 -0
- package/dist/src/endpoint-emulator.js +29 -0
- package/dist/src/endpoint-storage-transports.d.ts +2 -0
- package/dist/src/endpoint-storage-transports.js +8 -0
- package/dist/src/metadata-backfill.d.ts +1 -1
- package/dist/src/metadata-backfill.js +10 -1
- package/dist/src/migration.d.ts +6 -2
- package/dist/src/migration.js +104 -41
- package/dist/src/project.d.ts +8 -1
- package/dist/src/project.js +4 -0
- package/dist/src/request-contract.d.ts +5 -0
- package/dist/src/request-contract.js +12 -0
- package/dist/src/resource-inventory.d.ts +4 -2
- package/dist/src/resource-inventory.js +16 -1
- package/dist/src/resource-syncs/account-principal.d.ts +2 -0
- package/dist/src/resource-syncs/account-principal.js +3 -0
- package/dist/src/resource-syncs/application-principals.d.ts +60 -0
- package/dist/src/resource-syncs/application-principals.js +151 -0
- package/dist/src/resource-syncs/application-sync.d.ts +110 -0
- package/dist/src/resource-syncs/application-sync.js +328 -0
- package/dist/src/resource-syncs/endpoint-sync.d.ts +38 -0
- package/dist/src/resource-syncs/endpoint-sync.js +278 -14
- package/dist/src/resource-syncs/group-sync.d.ts +12 -0
- package/dist/src/resource-syncs/group-sync.js +60 -6
- package/dist/src/resource-syncs/runtime-definition-validation.js +26 -1
- package/dist/src/resource-syncs/service-account-sync.d.ts +10 -0
- package/dist/src/resource-syncs/service-account-sync.js +32 -4
- package/dist/src/reviewed-plan.js +2 -2
- package/dist/src/sync-omit-write-fence.js +4 -1
- package/dist/src/sync-omit.d.ts +1 -1
- package/dist/src/sync-omit.js +7 -2
- package/dist/src/tracked-resources.d.ts +1 -1
- package/dist/src/tracked-resources.js +3 -2
- package/dist/src/types.d.ts +30 -0
- package/dist/src/ui.js +2 -0
- package/dist/src/workspace-diff.js +1 -0
- package/dist/src/workspace-digests.js +2 -0
- package/dist/src/workspace-prune.js +67 -9
- package/package.json +2 -2
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { usesEndpointStorageTransport } from "../endpoint-storage-transports.js";
|
|
1
2
|
import { requestContractDefaults } from "../request-contract.js";
|
|
3
|
+
import { DEFAULT_ENDPOINT_APPLICATION_ID, DEFAULT_ENDPOINT_APPLICATION_KEY, endpointApplicationKey, endpointRecordApplicationKey, listEndpointApplications, portableEndpointApplication, resolveEndpointApplication, validEndpointApplication } from "../endpoint-application.js";
|
|
2
4
|
import { assertOmittedPropertiesPreserved, hashSyncDefinition, preserveOmittedProperties, syncBaselineHash, syncSourceBaselineHash, withoutSyncOmit, omitPaths } from "../sync-omit.js";
|
|
3
5
|
import { loadComponentSources } from "../component-manifests.js";
|
|
4
6
|
import { componentContentDigest, componentRevisionByDigest, isComponentDigest } from "../component-contract.js";
|
|
5
|
-
import { executionPrincipalAvailable, portableExecutionPolicy, runtimeExecutionPolicyPayload, validPortableExecutionPolicy } from "./account-principal.js";
|
|
7
|
+
import { executionPrincipalAvailable, serviceAccountRevisionHash, serviceAccountMatches, portableExecutionPolicy, runtimeExecutionPolicyPayload, validPortableExecutionPolicy } from "./account-principal.js";
|
|
6
8
|
import path from 'node:path';
|
|
7
9
|
import { describeFieldChanges } from "../diff-details.js";
|
|
8
10
|
import { hashPortableComponentSource, normalizePortableComponentSource, hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
9
11
|
import { withHttpTraceContext } from "../http-trace.js";
|
|
10
12
|
import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
|
|
11
13
|
import { HTTP_REQUEST_CONCURRENCY } from "../request-queue.js";
|
|
14
|
+
import { applicationManifestFromRecord, applicationRevisionHash, hashPortableApplication } from "./application-sync.js";
|
|
12
15
|
import { mapWithConcurrency, readJsonFile, sanitizeSegment } from "../utils.js";
|
|
13
16
|
import { hydrateWorkspaceComponentElementDetails } from "../workspace-component.js";
|
|
14
17
|
import { canonicalEndpointOptionDefaults, endpointDefinitionErrors, normalizeEndpointPath } from "./runtime-definition-validation.js";
|
|
@@ -21,6 +24,47 @@ const ENDPOINT_PLAN_STATUS_ORDER = [
|
|
|
21
24
|
'create', 'restore', 'safe-update', 'remote-changed', 'conflict', 'missing-lock',
|
|
22
25
|
'restore-blocked', 'collision', 'clean', 'orphan', 'skipped',
|
|
23
26
|
];
|
|
27
|
+
function reviewedApplicationSnapshots(plan) {
|
|
28
|
+
const byKey = new Map();
|
|
29
|
+
for (const item of plan?.items ?? []) {
|
|
30
|
+
const dependency = item.applicationDependency;
|
|
31
|
+
if (!dependency || dependency.readiness !== 'ready')
|
|
32
|
+
continue;
|
|
33
|
+
if (!dependency.serviceId || dependency.version === undefined || !dependency.desiredHash || !dependency.revisionHash) {
|
|
34
|
+
throw new Error('Reviewed Endpoint Application dependency is incomplete; prepare a new reviewed plan.');
|
|
35
|
+
}
|
|
36
|
+
const snapshot = { key: dependency.key, serviceId: dependency.serviceId, version: dependency.version,
|
|
37
|
+
desiredHash: dependency.desiredHash, revisionHash: dependency.revisionHash };
|
|
38
|
+
const previous = byKey.get(snapshot.key);
|
|
39
|
+
if (previous && hashStable(previous) !== hashStable(snapshot))
|
|
40
|
+
throw new Error('Reviewed Endpoint Application dependencies are inconsistent.');
|
|
41
|
+
byKey.set(snapshot.key, snapshot);
|
|
42
|
+
}
|
|
43
|
+
return [...byKey.values()];
|
|
44
|
+
}
|
|
45
|
+
function effectiveApplicationSnapshots(verified, reviewed) {
|
|
46
|
+
const byKey = new Map(reviewedApplicationSnapshots(reviewed).map(snapshot => [snapshot.key, snapshot]));
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
for (const snapshot of verified ?? []) {
|
|
49
|
+
if (seen.has(snapshot.key))
|
|
50
|
+
throw new Error('Verified Application dependency snapshots are ambiguous.');
|
|
51
|
+
seen.add(snapshot.key);
|
|
52
|
+
byKey.set(snapshot.key, snapshot);
|
|
53
|
+
}
|
|
54
|
+
return [...byKey.values()];
|
|
55
|
+
}
|
|
56
|
+
async function assertVerifiedApplication(client, applications, key, verified, stableKeyName = 'stableKey') {
|
|
57
|
+
const expected = verified?.filter(application => application.key === key) ?? [];
|
|
58
|
+
if (!expected.length)
|
|
59
|
+
return undefined;
|
|
60
|
+
const actual = applications.filter(application => application.key === key);
|
|
61
|
+
if (expected.length !== 1 || actual.length !== 1 || actual[0].serviceId !== expected[0].serviceId || actual[0].version !== expected[0].version
|
|
62
|
+
|| hashPortableApplication(await applicationManifestFromRecord(actual[0], client, stableKeyName)) !== expected[0].desiredHash
|
|
63
|
+
|| applicationRevisionHash(actual[0]) !== expected[0].revisionHash) {
|
|
64
|
+
throw new Error(`Application "${key}" changed after verified Application deployment; no Endpoint binding may adopt the drift.`);
|
|
65
|
+
}
|
|
66
|
+
return actual[0];
|
|
67
|
+
}
|
|
24
68
|
function canonicalValue(value) {
|
|
25
69
|
if (Array.isArray(value)) {
|
|
26
70
|
return value.map((item) => canonicalValue(item));
|
|
@@ -110,6 +154,7 @@ function disambiguateManifestPath(filePath, stableKey) {
|
|
|
110
154
|
const ENDPOINT_MANIFEST_FIELDS = new Set([
|
|
111
155
|
'kind', 'stableKey', 'name', 'category', 'description', 'metadata', 'active', 'timeout',
|
|
112
156
|
'route', 'options', 'execution', 'executionPolicy', 'schema',
|
|
157
|
+
'application', 'allowUnauthenticated',
|
|
113
158
|
]);
|
|
114
159
|
const INSTANCE_LOCAL_SCHEMA_OPTION_FIELDS = new Set([
|
|
115
160
|
'componentSchemaId', 'componentSchemaVersion', 'componentSchemaDigest', 'componentSchemaElement',
|
|
@@ -139,6 +184,10 @@ function hasValidSchemaBinding(value) {
|
|
|
139
184
|
const { element, ...binding } = value;
|
|
140
185
|
return hasValidBinding(binding) && (element === undefined || isNonEmptyString(element));
|
|
141
186
|
}
|
|
187
|
+
function omitsAnonymousGate() { return omitPaths('endpoint').some(parts => parts[0] === 'allowUnauthenticated'); }
|
|
188
|
+
function effectiveAnonymousGate(manifest, current) {
|
|
189
|
+
return current && omitsAnonymousGate() ? current.allowUnauthenticated ?? false : manifest.allowUnauthenticated ?? current?.allowUnauthenticated ?? false;
|
|
190
|
+
}
|
|
142
191
|
export function validateEndpointManifest(manifest, stableKeyName) {
|
|
143
192
|
if (!isRecord(manifest) || !hasOnlyKeys(manifest, ENDPOINT_MANIFEST_FIELDS)) {
|
|
144
193
|
return false;
|
|
@@ -165,12 +214,22 @@ export function validateEndpointManifest(manifest, stableKeyName) {
|
|
|
165
214
|
if (manifest.options !== undefined && !isRecord(manifest.options)) {
|
|
166
215
|
return false;
|
|
167
216
|
}
|
|
217
|
+
if (!validEndpointApplication(manifest.application))
|
|
218
|
+
return false;
|
|
219
|
+
if (endpointApplicationKey(manifest.application) !== DEFAULT_ENDPOINT_APPLICATION_KEY
|
|
220
|
+
&& String(manifest.route.path).split('/').some(part => part === '.' || part === '..'))
|
|
221
|
+
return false;
|
|
168
222
|
if (isRecord(manifest.options)
|
|
169
223
|
&& Object.keys(manifest.options).some((key) => INSTANCE_LOCAL_SCHEMA_OPTION_FIELDS.has(key))) {
|
|
170
224
|
return false;
|
|
171
225
|
}
|
|
172
226
|
if (manifest.executionPolicy !== undefined && !validPortableExecutionPolicy(manifest.executionPolicy, true))
|
|
173
227
|
return false;
|
|
228
|
+
if (manifest.allowUnauthenticated !== undefined && typeof manifest.allowUnauthenticated !== 'boolean')
|
|
229
|
+
return false;
|
|
230
|
+
if (manifest.allowUnauthenticated === true && manifest.executionPolicy !== undefined && (manifest.executionPolicy.mode !== 'SERVICE_ACCOUNT'
|
|
231
|
+
|| manifest.executionPolicy.serviceAccount?.kind !== 'service-account'))
|
|
232
|
+
return false;
|
|
174
233
|
if (manifest.execution !== undefined && !hasValidBinding(manifest.execution)) {
|
|
175
234
|
return false;
|
|
176
235
|
}
|
|
@@ -194,8 +253,10 @@ function endpointDefinitionHash(manifest, normalizeDefaults) {
|
|
|
194
253
|
description: manifest.description ?? '',
|
|
195
254
|
metadata: canonicalValue(manifest.metadata),
|
|
196
255
|
active: manifest.active,
|
|
256
|
+
...(manifest.allowUnauthenticated === true ? { allowUnauthenticated: true } : {}),
|
|
197
257
|
timeout: manifest.timeout ?? ENDPOINT_DEFAULT_TIMEOUT_SECONDS,
|
|
198
258
|
route: canonicalValue({ ...manifest.route, path: normalizeEndpointPath(manifest.route.path) }),
|
|
259
|
+
...(endpointApplicationKey(manifest.application) === DEFAULT_ENDPOINT_APPLICATION_KEY ? {} : { application: canonicalValue(manifest.application) }),
|
|
199
260
|
...(options === undefined ? {} : { options }),
|
|
200
261
|
...(manifest.execution === undefined ? {} : { execution: canonicalValue(manifest.execution) }),
|
|
201
262
|
...(manifest.executionPolicy === undefined ? {} : { executionPolicy: canonicalValue(manifest.executionPolicy) }),
|
|
@@ -244,11 +305,12 @@ async function loadRemoteEndpoints(client) {
|
|
|
244
305
|
if (!endpointId) {
|
|
245
306
|
return summary;
|
|
246
307
|
}
|
|
247
|
-
|
|
308
|
+
const record = unwrapData(await withHttpTraceContext({
|
|
248
309
|
operation: 'get',
|
|
249
310
|
entityId: endpointId,
|
|
250
311
|
...(typeof summary.name === 'string' ? { entityName: summary.name } : {}),
|
|
251
312
|
}, () => client.getEndpoint(endpointId, { timeoutMs: REMOTE_DETAIL_REQUEST_TIMEOUT_MS })));
|
|
313
|
+
return record;
|
|
252
314
|
}, HTTP_REQUEST_CONCURRENCY);
|
|
253
315
|
}
|
|
254
316
|
async function loadRemoteComponents(client, cwd) {
|
|
@@ -280,6 +342,7 @@ async function componentBinding(input) {
|
|
|
280
342
|
}
|
|
281
343
|
async function manifestFromRecord(input) {
|
|
282
344
|
const { record } = input;
|
|
345
|
+
const application = await portableEndpointApplication(input.client, record, input.applications);
|
|
283
346
|
if (typeof record.name !== 'string' || !record.name.trim()) {
|
|
284
347
|
throw new Error(`Endpoint "${input.stableKey}" has no name.`);
|
|
285
348
|
}
|
|
@@ -289,6 +352,8 @@ async function manifestFromRecord(input) {
|
|
|
289
352
|
if (record.active !== undefined && typeof record.active !== 'boolean') {
|
|
290
353
|
throw new Error(`Endpoint "${input.stableKey}" has an invalid active value.`);
|
|
291
354
|
}
|
|
355
|
+
if (record.allowUnauthenticated !== undefined && typeof record.allowUnauthenticated !== 'boolean')
|
|
356
|
+
throw new Error('Endpoint has invalid allowUnauthenticated state.');
|
|
292
357
|
if (record.timeout !== undefined && (typeof record.timeout !== 'number' || !Number.isFinite(record.timeout))) {
|
|
293
358
|
throw new Error(`Endpoint "${input.stableKey}" has an invalid timeout.`);
|
|
294
359
|
}
|
|
@@ -336,8 +401,10 @@ async function manifestFromRecord(input) {
|
|
|
336
401
|
...(typeof record.desc === 'string' ? { description: record.desc } : typeof record.description === 'string' ? { description: record.description } : {}),
|
|
337
402
|
metadata: canonicalMetadata(record, input.stableKeyName, input.stableKey),
|
|
338
403
|
active: record.active !== false,
|
|
404
|
+
...(input.includeAllowUnauthenticated === false || record.allowUnauthenticated === undefined ? {} : { allowUnauthenticated: record.allowUnauthenticated }),
|
|
339
405
|
timeout: typeof record.timeout === 'number' ? record.timeout : ENDPOINT_DEFAULT_TIMEOUT_SECONDS,
|
|
340
406
|
route: canonicalRoute(record),
|
|
407
|
+
...(application ? { application } : {}),
|
|
341
408
|
...(options === undefined ? {} : { options }),
|
|
342
409
|
...(execution ? { execution } : {}),
|
|
343
410
|
...(executionPolicy ? { executionPolicy } : {}),
|
|
@@ -355,6 +422,8 @@ export async function pullEndpointsToWorkspace(input) {
|
|
|
355
422
|
loadRemoteComponents(input.client, input.cwd),
|
|
356
423
|
]);
|
|
357
424
|
const componentsById = new Map(components.map((component) => [componentIdOf(component), component]));
|
|
425
|
+
const applications = records.some(record => record.serviceId && record.serviceId !== DEFAULT_ENDPOINT_APPLICATION_ID)
|
|
426
|
+
? await listEndpointApplications(input.client) : [];
|
|
358
427
|
const manifests = [];
|
|
359
428
|
const skipped = [];
|
|
360
429
|
const stableKeys = new Set();
|
|
@@ -382,6 +451,7 @@ export async function pullEndpointsToWorkspace(input) {
|
|
|
382
451
|
stableKey,
|
|
383
452
|
stableKeyName: input.stableKeyName,
|
|
384
453
|
componentsById,
|
|
454
|
+
applications,
|
|
385
455
|
}));
|
|
386
456
|
}
|
|
387
457
|
manifests.sort((left, right) => left.stableKey.localeCompare(right.stableKey));
|
|
@@ -503,15 +573,16 @@ export async function pullEndpointsToWorkspace(input) {
|
|
|
503
573
|
function endpointPlanCounts() {
|
|
504
574
|
return Object.fromEntries(ENDPOINT_PLAN_STATUS_ORDER.map((status) => [status, 0]));
|
|
505
575
|
}
|
|
506
|
-
function endpointRouteKey(route) {
|
|
576
|
+
function endpointRouteKey(route, applicationKey = DEFAULT_ENDPOINT_APPLICATION_KEY) {
|
|
507
577
|
const method = route.method.trim().toUpperCase();
|
|
508
578
|
const rawPath = route.path.trim();
|
|
509
579
|
const pathValue = rawPath.replace(/\/{2,}/g, '/').replace(/\/+$/g, '') || '/';
|
|
510
|
-
return `${method} ${pathValue}
|
|
580
|
+
return applicationKey === DEFAULT_ENDPOINT_APPLICATION_KEY ? `${method} ${pathValue}`
|
|
581
|
+
: `Application ${applicationKey}: ${method} ${pathValue.split('/').map(part => part === '@' || part.startsWith(':') ? '@' : part).join('/')}`;
|
|
511
582
|
}
|
|
512
|
-
function endpointRecordRouteKey(record) {
|
|
583
|
+
function endpointRecordRouteKey(record, applications) {
|
|
513
584
|
try {
|
|
514
|
-
return endpointRouteKey(canonicalRoute(record));
|
|
585
|
+
return endpointRouteKey(canonicalRoute(record), endpointRecordApplicationKey(record, applications));
|
|
515
586
|
}
|
|
516
587
|
catch {
|
|
517
588
|
return '';
|
|
@@ -525,9 +596,11 @@ function diffEndpoints(desired, current) {
|
|
|
525
596
|
['description', desired.description ?? '', current.description ?? ''],
|
|
526
597
|
['metadata', canonicalValue(desired.metadata), canonicalValue(current.metadata)],
|
|
527
598
|
['active', desired.active, current.active],
|
|
599
|
+
...(desired.allowUnauthenticated === undefined ? [] : [['allowUnauthenticated', desired.allowUnauthenticated, current.allowUnauthenticated ?? false]]),
|
|
528
600
|
['timeout', desired.timeout ?? ENDPOINT_DEFAULT_TIMEOUT_SECONDS, current.timeout ?? ENDPOINT_DEFAULT_TIMEOUT_SECONDS],
|
|
529
601
|
['route.method', desired.route.method, current.route.method],
|
|
530
602
|
['route.path', normalizeEndpointPath(desired.route.path), normalizeEndpointPath(current.route.path)],
|
|
603
|
+
['application', endpointApplicationKey(desired.application), endpointApplicationKey(current.application)],
|
|
531
604
|
['options', canonicalPortableOptions(desired.options) ?? null, canonicalPortableOptions(current.options) ?? null],
|
|
532
605
|
['execution', canonicalValue(desired.execution ?? null), canonicalValue(current.execution ?? null)],
|
|
533
606
|
...(desired.executionPolicy ? [['executionPolicy', canonicalValue(desired.executionPolicy), canonicalValue(current.executionPolicy ?? null)]] : []),
|
|
@@ -658,11 +731,14 @@ function targetComponentsByStableKey(components, stableKeyName) {
|
|
|
658
731
|
}
|
|
659
732
|
function endpointRevisionHash(record) {
|
|
660
733
|
return hashStable({
|
|
734
|
+
serviceId: record.serviceId ?? DEFAULT_ENDPOINT_APPLICATION_ID,
|
|
661
735
|
stableKeyMetadata: canonicalValue(record.metadata ?? record.metaData ?? record.resourceMetadata ?? null),
|
|
662
736
|
name: record.name ?? null,
|
|
663
737
|
category: record.category ?? null,
|
|
664
738
|
desc: record.desc ?? record.description ?? null,
|
|
665
739
|
active: record.active ?? null,
|
|
740
|
+
allowUnauthenticated: record.allowUnauthenticated ?? false,
|
|
741
|
+
executionPolicy: canonicalValue(record.executionPolicy ?? null),
|
|
666
742
|
timeout: record.timeout ?? null,
|
|
667
743
|
path: record.path ?? null,
|
|
668
744
|
method: record.method ?? null,
|
|
@@ -732,6 +808,7 @@ async function activeDeletedEndpointRestoreBlockers(input) {
|
|
|
732
808
|
return blockers;
|
|
733
809
|
}
|
|
734
810
|
export async function buildEndpointsPlan(input) {
|
|
811
|
+
const verifiedApplications = effectiveApplicationSnapshots(input.verifiedApplications, input.reviewedPlan);
|
|
735
812
|
const { projectRoot } = requireProjectLayout(input.cwd, 'Endpoint');
|
|
736
813
|
const items = [];
|
|
737
814
|
const blockers = [];
|
|
@@ -760,11 +837,22 @@ export async function buildEndpointsPlan(input) {
|
|
|
760
837
|
}
|
|
761
838
|
}
|
|
762
839
|
}
|
|
840
|
+
let storageCapabilityChecked = false;
|
|
841
|
+
if ([...localByStableKey.values()].flat().some(entry => usesEndpointStorageTransport(entry.manifest.options))) {
|
|
842
|
+
await input.client.requireEndpointStorageTransports();
|
|
843
|
+
storageCapabilityChecked = true;
|
|
844
|
+
}
|
|
763
845
|
const [targetEndpoints, targetComponents] = await Promise.all([
|
|
764
846
|
loadRemoteEndpoints(input.client),
|
|
765
847
|
loadRemoteComponents(input.client, input.cwd),
|
|
766
848
|
]);
|
|
767
849
|
const workspaceComponents = readWorkspaceComponents(input.cwd, input.stableKeyName);
|
|
850
|
+
const needsApplications = targetEndpoints.some(record => record.serviceId && record.serviceId !== DEFAULT_ENDPOINT_APPLICATION_ID)
|
|
851
|
+
|| [...localByStableKey.values()].flat().some(entry => endpointApplicationKey(entry.manifest.application) !== DEFAULT_ENDPOINT_APPLICATION_KEY)
|
|
852
|
+
|| !!verifiedApplications.length;
|
|
853
|
+
const applications = needsApplications ? await listEndpointApplications(input.client) : [];
|
|
854
|
+
for (const record of targetEndpoints)
|
|
855
|
+
endpointRecordApplicationKey(record, applications);
|
|
768
856
|
const targetComponentsByKey = targetComponentsByStableKey(targetComponents, input.stableKeyName);
|
|
769
857
|
const projectedComponentsByKey = input.projectedComponents === undefined
|
|
770
858
|
? undefined
|
|
@@ -810,7 +898,7 @@ export async function buildEndpointsPlan(input) {
|
|
|
810
898
|
const targetIssueKeys = new Set();
|
|
811
899
|
for (const record of targetEndpoints) {
|
|
812
900
|
const stableKey = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
|
|
813
|
-
const routeKey = endpointRecordRouteKey(record);
|
|
901
|
+
const routeKey = endpointRecordRouteKey(record, applications);
|
|
814
902
|
// Soft-deleted records do not own live routes. Keep them in the identity
|
|
815
903
|
// inventory for exact-key restores, matching the API's live-only uniqueness.
|
|
816
904
|
if (routeKey && !record.deletedAt && !record.deletedBy) {
|
|
@@ -842,11 +930,13 @@ export async function buildEndpointsPlan(input) {
|
|
|
842
930
|
try {
|
|
843
931
|
const manifest = await manifestFromRecord({
|
|
844
932
|
includeExecutionPolicy: (localByStableKey.get(stableKey) || []).some(entry => entry.manifest.executionPolicy !== undefined),
|
|
933
|
+
includeAllowUnauthenticated: !omitsAnonymousGate() && (localByStableKey.get(stableKey) || []).some(entry => entry.manifest.allowUnauthenticated !== undefined),
|
|
845
934
|
client: input.client,
|
|
846
935
|
record,
|
|
847
936
|
stableKey,
|
|
848
937
|
stableKeyName: input.stableKeyName,
|
|
849
938
|
componentsById,
|
|
939
|
+
applications,
|
|
850
940
|
});
|
|
851
941
|
liveTargetsByStableKey.set(stableKey, [
|
|
852
942
|
...(liveTargetsByStableKey.get(stableKey) || []),
|
|
@@ -885,11 +975,16 @@ export async function buildEndpointsPlan(input) {
|
|
|
885
975
|
entries[0] = { ...entries[0], manifest: preserveOmittedProperties('endpoint', entries[0].manifest, targets[0].manifest) };
|
|
886
976
|
}
|
|
887
977
|
}
|
|
978
|
+
// Omitted options may retain a native target even when the source has no
|
|
979
|
+
// storage mode. Unchanged retained transports still need a capable target.
|
|
980
|
+
if (!storageCapabilityChecked && [...localByStableKey.values()].flat().some(entry => usesEndpointStorageTransport(entry.manifest.options))) {
|
|
981
|
+
await input.client.requireEndpointStorageTransports();
|
|
982
|
+
}
|
|
888
983
|
const desiredRouteOwners = new Map();
|
|
889
984
|
const desiredRoutesByStableKey = new Map();
|
|
890
985
|
for (const [stableKey, entries] of localByStableKey) {
|
|
891
986
|
if (entries.length === 1) {
|
|
892
|
-
const routeKey = endpointRouteKey(entries[0].manifest.route);
|
|
987
|
+
const routeKey = endpointRouteKey(entries[0].manifest.route, endpointApplicationKey(entries[0].manifest.application));
|
|
893
988
|
desiredRouteOwners.set(routeKey, [...(desiredRouteOwners.get(routeKey) || []), stableKey]);
|
|
894
989
|
desiredRoutesByStableKey.set(stableKey, routeKey);
|
|
895
990
|
}
|
|
@@ -968,11 +1063,73 @@ export async function buildEndpointsPlan(input) {
|
|
|
968
1063
|
targetComponents: targetComponentsByKey,
|
|
969
1064
|
projectedComponents: projectedComponentsByKey,
|
|
970
1065
|
});
|
|
1066
|
+
const applicationKey = endpointApplicationKey(desired.application);
|
|
1067
|
+
const applicationFields = {};
|
|
1068
|
+
try {
|
|
1069
|
+
await assertVerifiedApplication(input.client, applications, applicationKey, verifiedApplications, input.stableKeyName);
|
|
1070
|
+
}
|
|
1071
|
+
catch (error) {
|
|
1072
|
+
dependency.blockers.push(error.message);
|
|
1073
|
+
}
|
|
1074
|
+
if (applicationKey !== DEFAULT_ENDPOINT_APPLICATION_KEY) {
|
|
1075
|
+
const actual = applications.filter(application => application.key === applicationKey);
|
|
1076
|
+
const projected = input.projectedApplications?.filter(application => application.key === applicationKey);
|
|
1077
|
+
if (actual.length > 1 || projected && projected.length !== 1 || !projected && actual.length !== 1
|
|
1078
|
+
|| projected?.[0]?.state === 'ready' && actual.length !== 1) {
|
|
1079
|
+
dependency.blockers.push(`Endpoint "${stableKey}" Application "${applicationKey}" is missing or ambiguous; align Applications before Endpoints.`);
|
|
1080
|
+
}
|
|
1081
|
+
if (projected?.[0]?.state === 'ready' && actual.length === 1
|
|
1082
|
+
&& hashPortableApplication(await applicationManifestFromRecord(actual[0], input.client, input.stableKeyName)) !== projected[0].desiredHash) {
|
|
1083
|
+
dependency.blockers.push(`Endpoint "${stableKey}" Application "${applicationKey}" does not match its verified projected definition.`);
|
|
1084
|
+
}
|
|
1085
|
+
const readiness = projected?.[0]?.state ?? (actual.length === 1 ? 'ready' : 'blocked');
|
|
1086
|
+
applicationFields.applicationDependency = { key: applicationKey, readiness,
|
|
1087
|
+
...(actual.length === 1 ? { serviceId: actual[0].serviceId, version: actual[0].version,
|
|
1088
|
+
desiredHash: hashPortableApplication(await applicationManifestFromRecord(actual[0], input.client, input.stableKeyName)),
|
|
1089
|
+
revisionHash: applicationRevisionHash(actual[0]) } : {}),
|
|
1090
|
+
...(projected?.[0] ? { desiredHash: projected[0].desiredHash } : {}) };
|
|
1091
|
+
if (readiness.startsWith('pending-'))
|
|
1092
|
+
dependency.warnings.push(`Endpoint "${stableKey}" waits for verified Application "${applicationKey}" readback.`);
|
|
1093
|
+
}
|
|
971
1094
|
warnings.push(...dependency.warnings);
|
|
972
1095
|
// Repository operation classification needs item-level gates without changing legacy family statuses.
|
|
973
1096
|
const dependencyBlockers = input.includeDependencyBlockers && dependency.blockers.length > 0
|
|
974
1097
|
? { dependencyBlockers: [...dependency.blockers] }
|
|
975
1098
|
: {};
|
|
1099
|
+
const targetForAnonymous = targetRecordsByStableKey.get(stableKey)?.[0];
|
|
1100
|
+
const anonymousEnabled = effectiveAnonymousGate(desired, targetForAnonymous);
|
|
1101
|
+
const anonymousPolicy = desired.executionPolicy ?? targetForAnonymous?.executionPolicy;
|
|
1102
|
+
if (anonymousEnabled && (anonymousPolicy?.mode !== 'SERVICE_ACCOUNT'
|
|
1103
|
+
|| 'serviceAccount' in anonymousPolicy && anonymousPolicy.serviceAccount?.kind !== 'service-account'
|
|
1104
|
+
|| 'serviceAccountUserId' in anonymousPolicy && (!anonymousPolicy.serviceAccountUserId || anonymousPolicy.serviceAccountUserId === '00000000-0000-0000-0000-000000000000')
|
|
1105
|
+
|| !('serviceAccount' in anonymousPolicy) && !('serviceAccountUserId' in anonymousPolicy))) {
|
|
1106
|
+
const reason = 'Anonymous Endpoint access requires an explicit dedicated SERVICE_ACCOUNT execution policy; System and inheritance are not permitted.';
|
|
1107
|
+
blockers.push(`Endpoint "${stableKey}": ${reason}`);
|
|
1108
|
+
items.push({ status: 'conflict', stableKey, name: desired.name, reason });
|
|
1109
|
+
continue;
|
|
1110
|
+
}
|
|
1111
|
+
if (anonymousEnabled) {
|
|
1112
|
+
try {
|
|
1113
|
+
const principal = desired.executionPolicy?.serviceAccount;
|
|
1114
|
+
const pending = principal?.kind === 'service-account' && input.projectedServiceAccounts?.includes(principal.stableKey)
|
|
1115
|
+
&& (await serviceAccountMatches(input.client, principal.stableKey, input.stableKeyName)).length === 0;
|
|
1116
|
+
if (pending && input.reviewedPlan?.items.find(item => item.stableKey === stableKey)?.anonymousExecutionDependency)
|
|
1117
|
+
throw new Error('Reviewed anonymous execution account disappeared after planning; review a new plan.');
|
|
1118
|
+
if (!pending) {
|
|
1119
|
+
const policy = desired.executionPolicy ? await runtimeExecutionPolicyPayload(input.client, desired.executionPolicy, input.stableKeyName) : targetForAnonymous?.executionPolicy;
|
|
1120
|
+
const actual = await anonymousExecutionDependency(input.client, policy, input.stableKeyName);
|
|
1121
|
+
const reviewed = input.reviewedPlan?.items.find(item => item.stableKey === stableKey)?.anonymousExecutionDependency;
|
|
1122
|
+
assertAnonymousExecutionDependency(actual, reviewed, input.verifiedServiceAccounts);
|
|
1123
|
+
applicationFields.anonymousExecutionDependency = actual;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
catch (error) {
|
|
1127
|
+
const reason = error instanceof Error ? error.message : 'Anonymous execution account is unavailable.';
|
|
1128
|
+
blockers.push(`Endpoint "${stableKey}": ${reason}`);
|
|
1129
|
+
items.push({ status: 'conflict', stableKey, name: desired.name, reason });
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
976
1133
|
if (desired.executionPolicy) {
|
|
977
1134
|
try {
|
|
978
1135
|
const principal = desired.executionPolicy.serviceAccount;
|
|
@@ -1001,7 +1158,7 @@ export async function buildEndpointsPlan(input) {
|
|
|
1001
1158
|
});
|
|
1002
1159
|
// Restore happens before configuration update, so the old physical route
|
|
1003
1160
|
// must also be available even when the desired manifest changes its path.
|
|
1004
|
-
const oldRoute = endpointRecordRouteKey(deletedTargets[0]);
|
|
1161
|
+
const oldRoute = endpointRecordRouteKey(deletedTargets[0], applications);
|
|
1005
1162
|
const oldRouteOwners = oldRoute ? targetRouteOwners.get(oldRoute) || [] : [];
|
|
1006
1163
|
if (oldRouteOwners.length > 0) {
|
|
1007
1164
|
restoreSafety.push(`old route ${oldRoute} is owned by ${oldRouteOwners.map(owner => owner.stableKey || owner.name).sort().join(', ')}`);
|
|
@@ -1015,6 +1172,7 @@ export async function buildEndpointsPlan(input) {
|
|
|
1015
1172
|
const restoreBlocked = dependency.blockers.length > 0 || restoreSafety.length > 0;
|
|
1016
1173
|
items.push({
|
|
1017
1174
|
status: restoreBlocked ? 'restore-blocked' : 'restore',
|
|
1175
|
+
...applicationFields,
|
|
1018
1176
|
...dependencyBlockers,
|
|
1019
1177
|
stableKey,
|
|
1020
1178
|
name: desired.name,
|
|
@@ -1044,6 +1202,7 @@ export async function buildEndpointsPlan(input) {
|
|
|
1044
1202
|
if (targets.length === 0) {
|
|
1045
1203
|
items.push({
|
|
1046
1204
|
status: 'create',
|
|
1205
|
+
...applicationFields,
|
|
1047
1206
|
...dependencyBlockers,
|
|
1048
1207
|
stableKey,
|
|
1049
1208
|
name: desired.name,
|
|
@@ -1061,11 +1220,13 @@ export async function buildEndpointsPlan(input) {
|
|
|
1061
1220
|
const current = targets[0];
|
|
1062
1221
|
const baselineHash = syncBaselineHash('endpoint', lock.endpoints[stableKey]?.environments[input.envName]);
|
|
1063
1222
|
const common = {
|
|
1223
|
+
...applicationFields,
|
|
1064
1224
|
...dependencyBlockers,
|
|
1065
1225
|
stableKey,
|
|
1066
1226
|
name: desired.name,
|
|
1067
1227
|
desiredHash,
|
|
1068
1228
|
currentHash: current.hash,
|
|
1229
|
+
targetRevisionHash: endpointRevisionHash(targetRecordsByStableKey.get(stableKey)[0]),
|
|
1069
1230
|
...(baselineHash ? { baselineHash } : {}),
|
|
1070
1231
|
details: dependency.details,
|
|
1071
1232
|
dependencies: dependency.dependencies,
|
|
@@ -1156,6 +1317,49 @@ function endpointWriteOptions(manifest, schemaComponent) {
|
|
|
1156
1317
|
}
|
|
1157
1318
|
return Object.keys(options).length > 0 ? options : undefined;
|
|
1158
1319
|
}
|
|
1320
|
+
async function resolvePlannedApplication(client, reference, expected, verified, stableKeyName = 'stableKey') {
|
|
1321
|
+
const key = endpointApplicationKey(reference);
|
|
1322
|
+
const verifiedSnapshot = verified?.some(application => application.key === key);
|
|
1323
|
+
const application = verifiedSnapshot ? await assertVerifiedApplication(client, await listEndpointApplications(client), key, verified, stableKeyName)
|
|
1324
|
+
: await resolveEndpointApplication(client, reference);
|
|
1325
|
+
if (application && expected?.readiness === 'ready'
|
|
1326
|
+
&& (application.serviceId !== expected.serviceId || application.version !== expected.version)) {
|
|
1327
|
+
throw new Error('Endpoint Application changed after planning; review the new Application binding before deployment.');
|
|
1328
|
+
}
|
|
1329
|
+
return application;
|
|
1330
|
+
}
|
|
1331
|
+
async function assertAnonymousEndpointAuthority(client, enabled, policy) {
|
|
1332
|
+
if (!enabled)
|
|
1333
|
+
return;
|
|
1334
|
+
if (policy?.mode !== 'SERVICE_ACCOUNT' || !policy.serviceAccountUserId || policy.serviceAccountUserId === '00000000-0000-0000-0000-000000000000')
|
|
1335
|
+
throw new Error('Anonymous Endpoint access requires an explicit dedicated SERVICE_ACCOUNT execution policy; System and inheritance are not permitted.');
|
|
1336
|
+
const account = await client.getAccount(policy.serviceAccountUserId);
|
|
1337
|
+
if (account.serviceAccount !== true || account.deletedAt || account.deletedBy || ![0, 'ACTIVE'].includes(account.status) || account.platformAccess !== true)
|
|
1338
|
+
throw new Error('Anonymous Endpoint execution account must be an available dedicated service account with platform access.');
|
|
1339
|
+
// Effective role/delegation checks belong to the canonical Endpoint API, not a CLI authorization grant.
|
|
1340
|
+
return account;
|
|
1341
|
+
}
|
|
1342
|
+
async function anonymousExecutionDependency(client, policy, stableKeyName = 'stableKey') {
|
|
1343
|
+
const account = (await assertAnonymousEndpointAuthority(client, true, policy));
|
|
1344
|
+
if (account.userId !== policy.serviceAccountUserId || typeof account.version !== 'number' || !Number.isSafeInteger(account.version) || account.version < 0)
|
|
1345
|
+
throw new Error('Anonymous execution account did not expose an exact physical identity and revision.');
|
|
1346
|
+
const stableKey = readConfiguredResourceMetadataStableKey(account, stableKeyName);
|
|
1347
|
+
return { serviceAccountUserId: policy.serviceAccountUserId, version: account.version, revisionHash: serviceAccountRevisionHash(account), ...(stableKey ? { stableKey } : {}) };
|
|
1348
|
+
}
|
|
1349
|
+
function assertAnonymousExecutionDependency(actual, expected, verified) {
|
|
1350
|
+
const receipts = actual.stableKey ? verified?.filter(receipt => receipt.stableKey === actual.stableKey) ?? [] : [];
|
|
1351
|
+
if (receipts.length > 1)
|
|
1352
|
+
throw new Error('Verified anonymous execution account receipts are ambiguous.');
|
|
1353
|
+
if (receipts.length === 1) {
|
|
1354
|
+
const receipt = receipts[0];
|
|
1355
|
+
if (expected && expected.serviceAccountUserId !== receipt.userId || actual.serviceAccountUserId !== receipt.userId
|
|
1356
|
+
|| actual.version !== receipt.version || actual.revisionHash !== receipt.revisionHash)
|
|
1357
|
+
throw new Error('Anonymous execution account changed after verified Service Account deployment.');
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
if (expected && (actual.serviceAccountUserId !== expected.serviceAccountUserId || actual.version !== expected.version || actual.revisionHash !== expected.revisionHash))
|
|
1361
|
+
throw new Error('Anonymous execution account identity or revision changed after planning; review a new plan.');
|
|
1362
|
+
}
|
|
1159
1363
|
async function resolveEndpointWritePayload(input) {
|
|
1160
1364
|
const targetComponents = await loadRemoteComponents(input.client, input.cwd);
|
|
1161
1365
|
const targetByKey = targetComponentsByStableKey(targetComponents, input.stableKeyName);
|
|
@@ -1192,8 +1396,17 @@ async function resolveEndpointWritePayload(input) {
|
|
|
1192
1396
|
}
|
|
1193
1397
|
const options = endpointWriteOptions(input.manifest, schema);
|
|
1194
1398
|
const executionPolicy = await runtimeExecutionPolicyPayload(input.client, input.manifest.executionPolicy, input.stableKeyName);
|
|
1399
|
+
const effectiveAnonymous = effectiveAnonymousGate(input.manifest, input.current);
|
|
1400
|
+
const effectivePolicy = executionPolicy ?? input.current?.executionPolicy;
|
|
1401
|
+
if (effectiveAnonymous)
|
|
1402
|
+
assertAnonymousExecutionDependency(await anonymousExecutionDependency(input.client, effectivePolicy, input.stableKeyName), input.anonymousExecutionDependency);
|
|
1403
|
+
const application = await resolvePlannedApplication(input.client, input.manifest.application, input.applicationDependency, input.verifiedApplications, input.stableKeyName);
|
|
1404
|
+
const serviceId = (application?.key !== DEFAULT_ENDPOINT_APPLICATION_KEY ? application?.serviceId : undefined) ?? (input.current?.serviceId && input.current.serviceId !== DEFAULT_ENDPOINT_APPLICATION_ID
|
|
1405
|
+
? DEFAULT_ENDPOINT_APPLICATION_ID : undefined);
|
|
1195
1406
|
const common = {
|
|
1407
|
+
...(serviceId === undefined ? {} : { serviceId }),
|
|
1196
1408
|
...(executionPolicy ? { executionPolicy } : {}),
|
|
1409
|
+
...(input.manifest.allowUnauthenticated === undefined || input.current && omitsAnonymousGate() ? {} : { allowUnauthenticated: input.manifest.allowUnauthenticated }),
|
|
1197
1410
|
name: input.manifest.name,
|
|
1198
1411
|
category: input.manifest.category ?? null,
|
|
1199
1412
|
desc: input.manifest.description ?? '',
|
|
@@ -1250,6 +1463,7 @@ async function updateEndpointConfigurationAndActivation(input) {
|
|
|
1250
1463
|
preservationComponents = new Map(targetComponents.map(component => [componentIdOf(component), component]));
|
|
1251
1464
|
const currentManifest = await manifestFromRecord({
|
|
1252
1465
|
includeExecutionPolicy: input.manifest.executionPolicy !== undefined,
|
|
1466
|
+
includeAllowUnauthenticated: input.manifest.allowUnauthenticated !== undefined,
|
|
1253
1467
|
client: input.client,
|
|
1254
1468
|
record: latest,
|
|
1255
1469
|
stableKey: input.stableKey,
|
|
@@ -1259,19 +1473,27 @@ async function updateEndpointConfigurationAndActivation(input) {
|
|
|
1259
1473
|
preservedTargetManifest = currentManifest;
|
|
1260
1474
|
effectiveManifest = preserveOmittedProperties('endpoint', input.manifest, currentManifest);
|
|
1261
1475
|
}
|
|
1262
|
-
const payload = await resolveEndpointWritePayload({ ...input, manifest: effectiveManifest });
|
|
1476
|
+
const payload = await resolveEndpointWritePayload({ ...input, manifest: effectiveManifest, current: latest });
|
|
1263
1477
|
const runtimePaths = omitPaths('endpoint').filter(parts => parts[0] === 'options');
|
|
1264
1478
|
const wholeOptions = runtimePaths.some(parts => parts.length === 1);
|
|
1265
1479
|
const schemaChanged = preservedTargetManifest && hashStable(effectiveManifest.schema ?? null) !== hashStable(preservedTargetManifest.schema ?? null);
|
|
1266
1480
|
if (wholeOptions && schemaChanged)
|
|
1267
1481
|
throw new Error('Endpoint schema binding cannot change while the complete options envelope is omitted; reconcile the binding or narrow --omit before deployment.');
|
|
1268
|
-
const runtimeChanged = !preservedTargetManifest || hashStable(canonicalPortableOptions(effectiveManifest.options)) !== hashStable(canonicalPortableOptions(preservedTargetManifest.options)) || schemaChanged;
|
|
1482
|
+
const runtimeChanged = !preservedTargetManifest || hashStable(canonicalPortableOptions(effectiveManifest.options) ?? null) !== hashStable(canonicalPortableOptions(preservedTargetManifest.options) ?? null) || schemaChanged;
|
|
1269
1483
|
const { options, ...configuration } = payload;
|
|
1270
1484
|
const writeOptions = runtimePaths.length > 0 && !runtimeChanged ? {} : { options: options ?? null };
|
|
1271
1485
|
if (Object.hasOwn(writeOptions, 'options') && preservedTargetManifest)
|
|
1272
1486
|
assertEndpointOmitWriteSafe(preservedTargetManifest, effectiveManifest, options ?? null);
|
|
1487
|
+
if (!Object.hasOwn(writeOptions, 'options') && usesEndpointStorageTransport(effectiveManifest.options))
|
|
1488
|
+
await input.client.requireEndpointStorageTransports();
|
|
1273
1489
|
await input.client.updateEndpoint(input.endpointId, { ...configuration, ...writeOptions, version: latest.version });
|
|
1274
1490
|
let configured = unwrapData(await input.client.getEndpoint(input.endpointId));
|
|
1491
|
+
if ((configured.allowUnauthenticated ?? false) !== effectiveAnonymousGate(effectiveManifest, latest))
|
|
1492
|
+
throw new Error('Written Endpoint anonymous access did not match the explicit value or preserved target gate.');
|
|
1493
|
+
if (configured.allowUnauthenticated === true)
|
|
1494
|
+
assertAnonymousExecutionDependency(await anonymousExecutionDependency(input.client, configured.executionPolicy, input.stableKeyName), input.anonymousExecutionDependency);
|
|
1495
|
+
await portableEndpointApplication(input.client, configured);
|
|
1496
|
+
await resolvePlannedApplication(input.client, input.manifest.application, input.applicationDependency, input.verifiedApplications, input.stableKeyName);
|
|
1275
1497
|
if (Boolean(configured.active) !== effectiveManifest.active) {
|
|
1276
1498
|
if (effectiveManifest.active) {
|
|
1277
1499
|
await input.client.activateEndpoint(input.endpointId);
|
|
@@ -1285,12 +1507,18 @@ async function updateEndpointConfigurationAndActivation(input) {
|
|
|
1285
1507
|
if (preservedTargetManifest) {
|
|
1286
1508
|
const verifiedManifest = await manifestFromRecord({ client: input.client, record: configured,
|
|
1287
1509
|
stableKey: input.stableKey, stableKeyName: input.stableKeyName,
|
|
1288
|
-
includeExecutionPolicy: input.manifest.executionPolicy !== undefined, componentsById: preservationComponents
|
|
1510
|
+
includeExecutionPolicy: input.manifest.executionPolicy !== undefined, componentsById: preservationComponents,
|
|
1511
|
+
includeAllowUnauthenticated: input.manifest.allowUnauthenticated !== undefined });
|
|
1289
1512
|
assertOmittedPropertiesPreserved('endpoint', preservedTargetManifest, verifiedManifest);
|
|
1290
1513
|
}
|
|
1291
1514
|
}
|
|
1292
1515
|
async function verifyEndpointWrite(input) {
|
|
1293
1516
|
const verified = unwrapData(await input.client.getEndpoint(input.endpointId));
|
|
1517
|
+
await resolvePlannedApplication(input.client, input.desiredManifest.application, input.applicationDependency, input.verifiedApplications, input.stableKeyName);
|
|
1518
|
+
if (input.expectedAllowUnauthenticated !== undefined && (verified.allowUnauthenticated ?? false) !== input.expectedAllowUnauthenticated)
|
|
1519
|
+
throw new Error('Written Endpoint anonymous access changed before verified readback.');
|
|
1520
|
+
if (verified.allowUnauthenticated === true)
|
|
1521
|
+
assertAnonymousExecutionDependency(await anonymousExecutionDependency(input.client, verified.executionPolicy, input.stableKeyName), input.anonymousExecutionDependency);
|
|
1294
1522
|
const verifiedStableKey = readConfiguredResourceMetadataStableKey(verified, input.stableKeyName);
|
|
1295
1523
|
if (verifiedStableKey !== input.stableKey) {
|
|
1296
1524
|
throw new Error(`written target is missing or changed ${input.stableKeyName}`);
|
|
@@ -1299,6 +1527,7 @@ async function verifyEndpointWrite(input) {
|
|
|
1299
1527
|
const componentsById = new Map(targetComponents.map((component) => [componentIdOf(component), component]));
|
|
1300
1528
|
const verifiedManifest = await manifestFromRecord({
|
|
1301
1529
|
includeExecutionPolicy: input.desiredManifest.executionPolicy !== undefined,
|
|
1530
|
+
includeAllowUnauthenticated: input.desiredManifest.allowUnauthenticated !== undefined,
|
|
1302
1531
|
client: input.client,
|
|
1303
1532
|
record: verified,
|
|
1304
1533
|
stableKey: verifiedStableKey,
|
|
@@ -1352,6 +1581,7 @@ async function executeEndpointPushItem(input) {
|
|
|
1352
1581
|
const prepared = {
|
|
1353
1582
|
stableKey,
|
|
1354
1583
|
manifest: local.manifest,
|
|
1584
|
+
expectedAllowUnauthenticated: input.action === 'create' ? local.manifest.allowUnauthenticated ?? false : undefined,
|
|
1355
1585
|
};
|
|
1356
1586
|
const endpointId = await input.mutate(prepared);
|
|
1357
1587
|
const remoteHash = await verifyEndpointWrite({
|
|
@@ -1360,9 +1590,13 @@ async function executeEndpointPushItem(input) {
|
|
|
1360
1590
|
endpointId,
|
|
1361
1591
|
stableKey,
|
|
1362
1592
|
desiredManifest: local.manifest,
|
|
1593
|
+
expectedAllowUnauthenticated: prepared.expectedAllowUnauthenticated,
|
|
1363
1594
|
verifyFullSource: input.action === 'create',
|
|
1364
1595
|
desiredHash,
|
|
1365
1596
|
stableKeyName: input.stableKeyName,
|
|
1597
|
+
applicationDependency: input.item.applicationDependency,
|
|
1598
|
+
anonymousExecutionDependency: input.item.anonymousExecutionDependency,
|
|
1599
|
+
verifiedApplications: input.verifiedApplications,
|
|
1366
1600
|
});
|
|
1367
1601
|
updateEndpointEnvironmentBaseline({
|
|
1368
1602
|
cwd: input.cwd,
|
|
@@ -1428,13 +1662,18 @@ async function pushEndpointUpdate(input) {
|
|
|
1428
1662
|
throw new Error(`expected one live target match, found ${matches.length}`);
|
|
1429
1663
|
}
|
|
1430
1664
|
const target = matches[0];
|
|
1665
|
+
prepared.expectedAllowUnauthenticated = effectiveAnonymousGate(prepared.manifest, target);
|
|
1431
1666
|
const targetId = endpointIdOf(target);
|
|
1432
1667
|
if (!targetId) {
|
|
1433
1668
|
throw new Error('live target did not include endpointId');
|
|
1434
1669
|
}
|
|
1670
|
+
if (input.item.targetRevisionHash && endpointRevisionHash(target) !== input.item.targetRevisionHash) {
|
|
1671
|
+
throw new Error('target changed after planning');
|
|
1672
|
+
}
|
|
1435
1673
|
const targetComponents = await loadRemoteComponents(input.client, input.cwd);
|
|
1436
1674
|
const targetManifest = await manifestFromRecord({
|
|
1437
1675
|
includeExecutionPolicy: prepared.manifest.executionPolicy !== undefined,
|
|
1676
|
+
includeAllowUnauthenticated: prepared.manifest.allowUnauthenticated !== undefined,
|
|
1438
1677
|
client: input.client,
|
|
1439
1678
|
record: target,
|
|
1440
1679
|
stableKey: prepared.stableKey,
|
|
@@ -1458,12 +1697,16 @@ async function pushEndpointUpdate(input) {
|
|
|
1458
1697
|
expectedRevisionHash: endpointRevisionHash(target),
|
|
1459
1698
|
targetLabel: 'target',
|
|
1460
1699
|
workspaceComponents: input.workspaceComponents,
|
|
1700
|
+
applicationDependency: input.item.applicationDependency,
|
|
1701
|
+
anonymousExecutionDependency: input.item.anonymousExecutionDependency,
|
|
1702
|
+
verifiedApplications: input.verifiedApplications,
|
|
1461
1703
|
});
|
|
1462
1704
|
return targetId;
|
|
1463
1705
|
},
|
|
1464
1706
|
});
|
|
1465
1707
|
}
|
|
1466
1708
|
export async function pushEndpoints(input) {
|
|
1709
|
+
input = { ...input, verifiedApplications: effectiveApplicationSnapshots(input.verifiedApplications, input.reviewedPlan) };
|
|
1467
1710
|
const plan = await buildEndpointsPlan(input);
|
|
1468
1711
|
if (plan.blockers.length > 0) {
|
|
1469
1712
|
throw new Error(`Endpoint push blocked: ${plan.blockers.join(' ')}`);
|
|
@@ -1521,6 +1764,8 @@ export async function pushEndpoints(input) {
|
|
|
1521
1764
|
...input,
|
|
1522
1765
|
manifest: prepared.manifest,
|
|
1523
1766
|
workspaceComponents,
|
|
1767
|
+
applicationDependency: item.applicationDependency,
|
|
1768
|
+
anonymousExecutionDependency: item.anonymousExecutionDependency,
|
|
1524
1769
|
});
|
|
1525
1770
|
const createPayload = { ...payload, active: false };
|
|
1526
1771
|
if (!prepared.manifest.execution) {
|
|
@@ -1529,6 +1774,12 @@ export async function pushEndpoints(input) {
|
|
|
1529
1774
|
delete createPayload.componentDigest;
|
|
1530
1775
|
}
|
|
1531
1776
|
const created = unwrapData(await input.client.createEndpoint(createPayload));
|
|
1777
|
+
if ((created.allowUnauthenticated ?? false) !== (prepared.manifest.allowUnauthenticated ?? false))
|
|
1778
|
+
throw new Error('Created Endpoint anonymous access did not match its requested gate.');
|
|
1779
|
+
if (created.allowUnauthenticated === true)
|
|
1780
|
+
assertAnonymousExecutionDependency(await anonymousExecutionDependency(input.client, created.executionPolicy, input.stableKeyName), item.anonymousExecutionDependency);
|
|
1781
|
+
await portableEndpointApplication(input.client, created);
|
|
1782
|
+
await resolvePlannedApplication(input.client, prepared.manifest.application, item.applicationDependency, input.verifiedApplications, input.stableKeyName);
|
|
1532
1783
|
const createdId = endpointIdOf(created);
|
|
1533
1784
|
if (!createdId) {
|
|
1534
1785
|
throw new Error('create response did not include endpointId');
|
|
@@ -1560,12 +1811,15 @@ export async function pushEndpoints(input) {
|
|
|
1560
1811
|
action: 'restore',
|
|
1561
1812
|
mutate: async (prepared) => {
|
|
1562
1813
|
const liveEndpoints = await loadRemoteEndpoints(input.client);
|
|
1814
|
+
const applications = liveEndpoints.some(record => record.serviceId && record.serviceId !== DEFAULT_ENDPOINT_APPLICATION_ID)
|
|
1815
|
+
? await listEndpointApplications(input.client) : [];
|
|
1563
1816
|
const matches = liveEndpoints.filter((record) => (Boolean(record.deletedAt || record.deletedBy)
|
|
1564
1817
|
&& readConfiguredResourceMetadataStableKey(record, input.stableKeyName) === prepared.stableKey));
|
|
1565
1818
|
if (matches.length !== 1) {
|
|
1566
1819
|
throw new Error(`expected one deleted target match, found ${matches.length}`);
|
|
1567
1820
|
}
|
|
1568
1821
|
const target = matches[0];
|
|
1822
|
+
prepared.expectedAllowUnauthenticated = effectiveAnonymousGate(prepared.manifest, target);
|
|
1569
1823
|
const targetId = endpointIdOf(target);
|
|
1570
1824
|
if (!targetId) {
|
|
1571
1825
|
throw new Error('deleted target did not include endpointId');
|
|
@@ -1582,21 +1836,28 @@ export async function pushEndpoints(input) {
|
|
|
1582
1836
|
if (restoreBlockers.length > 0) {
|
|
1583
1837
|
throw new Error(`restore safety changed after planning: ${restoreBlockers.join('; ')}`);
|
|
1584
1838
|
}
|
|
1585
|
-
const oldRoute = endpointRecordRouteKey(target);
|
|
1839
|
+
const oldRoute = endpointRecordRouteKey(target, applications);
|
|
1586
1840
|
if (oldRoute && liveEndpoints.some(record => !record.deletedAt && !record.deletedBy
|
|
1587
|
-
&& endpointRecordRouteKey(record) === oldRoute)) {
|
|
1841
|
+
&& endpointRecordRouteKey(record, applications) === oldRoute)) {
|
|
1588
1842
|
throw new Error(`restore safety changed after planning: old route ${oldRoute} is now owned by a live endpoint`);
|
|
1589
1843
|
}
|
|
1590
1844
|
if (omitPaths('endpoint').some(parts => parts.length === 1 && parts[0] === 'options')) {
|
|
1591
1845
|
const priorManifest = await manifestFromRecord({ client: input.client, record: target, stableKey: prepared.stableKey,
|
|
1592
1846
|
stableKeyName: input.stableKeyName, includeExecutionPolicy: prepared.manifest.executionPolicy !== undefined,
|
|
1847
|
+
includeAllowUnauthenticated: prepared.manifest.allowUnauthenticated !== undefined,
|
|
1593
1848
|
componentsById: new Map(targetComponents.map(component => [componentIdOf(component), component])) });
|
|
1594
1849
|
if (hashStable(prepared.manifest.schema ?? null) !== hashStable(priorManifest.schema ?? null)) {
|
|
1595
1850
|
throw new Error('Endpoint schema binding cannot change while the complete options envelope is omitted; reconcile the binding or narrow --omit before deployment.');
|
|
1596
1851
|
}
|
|
1597
1852
|
}
|
|
1853
|
+
await resolvePlannedApplication(input.client, prepared.manifest.application, item.applicationDependency, input.verifiedApplications, input.stableKeyName);
|
|
1854
|
+
await assertAnonymousEndpointAuthority(input.client, target.allowUnauthenticated === true, target.executionPolicy);
|
|
1598
1855
|
await input.client.restoreEndpoint(targetId);
|
|
1599
1856
|
const restored = unwrapData(await input.client.getEndpoint(targetId));
|
|
1857
|
+
if ((restored.allowUnauthenticated ?? false) !== (target.allowUnauthenticated ?? false)
|
|
1858
|
+
|| hashStable(restored.executionPolicy ?? null) !== hashStable(target.executionPolicy ?? null))
|
|
1859
|
+
throw new Error('Restored Endpoint anonymous gate or execution policy changed before configuration.');
|
|
1860
|
+
await portableEndpointApplication(input.client, restored);
|
|
1600
1861
|
const restoredStableKey = readConfiguredResourceMetadataStableKey(restored, input.stableKeyName);
|
|
1601
1862
|
if (restoredStableKey !== prepared.stableKey) {
|
|
1602
1863
|
throw new Error(`restored target is missing or changed ${input.stableKeyName}`);
|
|
@@ -1617,6 +1878,9 @@ export async function pushEndpoints(input) {
|
|
|
1617
1878
|
expectedRevisionHash: endpointRevisionHash(restored),
|
|
1618
1879
|
targetLabel: 'restored target',
|
|
1619
1880
|
workspaceComponents,
|
|
1881
|
+
applicationDependency: item.applicationDependency,
|
|
1882
|
+
anonymousExecutionDependency: item.anonymousExecutionDependency,
|
|
1883
|
+
verifiedApplications: input.verifiedApplications,
|
|
1620
1884
|
});
|
|
1621
1885
|
return targetId;
|
|
1622
1886
|
},
|