@revoengine/cli 1.0.15 → 1.0.16

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.
Files changed (49) hide show
  1. package/README.md +45 -9
  2. package/dist/src/cli.js +5 -1
  3. package/dist/src/client.d.ts +25 -3
  4. package/dist/src/client.js +67 -2
  5. package/dist/src/commands/component.js +1 -0
  6. package/dist/src/commands/index.d.ts +1 -0
  7. package/dist/src/commands/index.js +1 -0
  8. package/dist/src/commands/migrate.js +12 -2
  9. package/dist/src/commands/service-accounts.d.ts +2 -0
  10. package/dist/src/commands/service-accounts.js +149 -0
  11. package/dist/src/commands/terminal-browser.d.ts +29 -2
  12. package/dist/src/commands/terminal-browser.js +144 -35
  13. package/dist/src/commands/terminal-file.d.ts +21 -0
  14. package/dist/src/commands/terminal-file.js +160 -0
  15. package/dist/src/commands/terminal-operational-log.js +2 -2
  16. package/dist/src/commands/terminal-policy.d.ts +5 -2
  17. package/dist/src/commands/terminal-policy.js +10 -4
  18. package/dist/src/commands/terminal-reconnect-grace.js +1 -1
  19. package/dist/src/commands/terminal-sandbox.js +7 -0
  20. package/dist/src/commands/terminal-secure-browser.d.ts +1 -0
  21. package/dist/src/commands/terminal-secure-browser.js +2 -1
  22. package/dist/src/commands/terminal-service.js +4 -4
  23. package/dist/src/commands/terminal.d.ts +12 -0
  24. package/dist/src/commands/terminal.js +134 -45
  25. package/dist/src/component-lock.d.ts +4 -0
  26. package/dist/src/component-lock.js +21 -2
  27. package/dist/src/metadata-backfill.js +50 -1
  28. package/dist/src/migration.d.ts +10 -2
  29. package/dist/src/migration.js +159 -68
  30. package/dist/src/resource-inventory.d.ts +3 -2
  31. package/dist/src/resource-inventory.js +6 -1
  32. package/dist/src/resource-syncs/account-principal.d.ts +22 -0
  33. package/dist/src/resource-syncs/account-principal.js +86 -0
  34. package/dist/src/resource-syncs/group-sync.d.ts +10 -0
  35. package/dist/src/resource-syncs/group-sync.js +92 -20
  36. package/dist/src/resource-syncs/identity-migration.d.ts +19 -0
  37. package/dist/src/resource-syncs/identity-migration.js +108 -0
  38. package/dist/src/resource-syncs/job-template-sync.d.ts +4 -0
  39. package/dist/src/resource-syncs/job-template-sync.js +55 -12
  40. package/dist/src/resource-syncs/service-account-sync.d.ts +98 -0
  41. package/dist/src/resource-syncs/service-account-sync.js +620 -0
  42. package/dist/src/sync-output.js +3 -0
  43. package/dist/src/tracked-resources.d.ts +1 -1
  44. package/dist/src/tracked-resources.js +5 -1
  45. package/dist/src/types.d.ts +12 -0
  46. package/dist/src/ui.js +4 -1
  47. package/dist/src/workspace-diff.d.ts +1 -0
  48. package/dist/src/workspace-diff.js +4 -1
  49. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  import path from 'node:path';
2
+ import { accountPrincipal, serviceAccountMatches } from "./account-principal.js";
2
3
  import { describeFieldChanges } from "../diff-details.js";
3
4
  import { hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
4
5
  import { normalizeStableKeyValue, readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
@@ -93,6 +94,7 @@ async function loadRemoteComponents(client) {
93
94
  });
94
95
  }
95
96
  const JOB_TEMPLATE_MANIFEST_FIELDS = new Set([
97
+ 'executionPrincipal',
96
98
  'kind', 'stableKey', 'name', 'category', 'description', 'metadata', 'component',
97
99
  'timeout', 'options', 'inputs', 'migration',
98
100
  ]);
@@ -151,6 +153,11 @@ function validateManifest(manifest, stableKeyName) {
151
153
  if (!isOptionalRecord(manifest.inputs, { nullable: true })) {
152
154
  return false;
153
155
  }
156
+ if (manifest.executionPrincipal !== undefined && (!isRecord(manifest.executionPrincipal)
157
+ || !hasOnlyKeys(manifest.executionPrincipal, new Set(['kind', 'stableKey']))
158
+ || manifest.executionPrincipal.kind !== 'service-account' || !isNonEmptyString(manifest.executionPrincipal.stableKey))) {
159
+ return false;
160
+ }
154
161
  if (!hasValidJobTemplateMigration(manifest.migration)) {
155
162
  return false;
156
163
  }
@@ -180,6 +187,23 @@ function manifestFromRecord(record, stableKey, componentKey, stableKeyName) {
180
187
  ...(record.inputs === undefined ? {} : { inputs: canonicalValue(record.inputs) }),
181
188
  };
182
189
  }
190
+ async function withRecordPrincipal(client, record, manifest, stableKeyName, compare) {
191
+ if (!compare || !record.triggerUser) {
192
+ return manifest;
193
+ }
194
+ const principal = await accountPrincipal(client, record.triggerUser, stableKeyName);
195
+ return principal ? { ...manifest, executionPrincipal: principal } : manifest;
196
+ }
197
+ async function targetPrincipalId(client, manifest, stableKeyName) {
198
+ if (!manifest.executionPrincipal) {
199
+ return {};
200
+ }
201
+ const matches = await serviceAccountMatches(client, manifest.executionPrincipal.stableKey, stableKeyName);
202
+ if (matches.length !== 1 || !matches[0].userId) {
203
+ throw new Error('Execution principal must resolve to exactly one target service account.');
204
+ }
205
+ return { triggerUser: matches[0].userId };
206
+ }
183
207
  function buildCreatePayload(manifest, componentId) {
184
208
  return {
185
209
  name: manifest.name,
@@ -215,6 +239,7 @@ export function hashPortableJobTemplate(manifest) {
215
239
  description: manifest.description ?? '',
216
240
  metadata: canonicalValue(manifest.metadata),
217
241
  component: { stableKey: manifest.component.stableKey },
242
+ ...(manifest.executionPrincipal ? { executionPrincipal: manifest.executionPrincipal } : {}),
218
243
  ...(manifest.timeout === undefined ? {} : { timeout: manifest.timeout }),
219
244
  ...(options === undefined ? {} : { options }),
220
245
  ...(manifest.inputs === undefined ? {} : { inputs: canonicalJobTemplateInputs(manifest.inputs) }),
@@ -227,6 +252,7 @@ function diffJobTemplates(desired, target) {
227
252
  ['description', desired.description ?? '', target.description ?? ''],
228
253
  ['metadata', canonicalValue(desired.metadata), canonicalValue(target.metadata)],
229
254
  ['component.stableKey', desired.component.stableKey, target.component.stableKey],
255
+ ...(desired.executionPrincipal ? [['executionPrincipal', desired.executionPrincipal, target.executionPrincipal]] : []),
230
256
  ['timeout', desired.timeout, target.timeout],
231
257
  [
232
258
  'options',
@@ -344,7 +370,7 @@ export async function buildJobTemplatesPlan(input) {
344
370
  items.push({ status: 'conflict', stableKey, name: String(record.name || ''), reason });
345
371
  continue;
346
372
  }
347
- const manifest = manifestFromRecord(record, stableKey, componentKey, input.stableKeyName);
373
+ const manifest = await withRecordPrincipal(input.client, record, manifestFromRecord(record, stableKey, componentKey, input.stableKeyName), input.stableKeyName, localEntries.some((entry) => entry.manifest.stableKey === stableKey && Boolean(entry.manifest.executionPrincipal)));
348
374
  targetByKey.set(stableKeyIdentity, [{
349
375
  record,
350
376
  manifest,
@@ -362,8 +388,8 @@ export async function buildJobTemplatesPlan(input) {
362
388
  }
363
389
  const desired = entries[0].manifest;
364
390
  const lockEntry = lockEntriesByKey.get(stableKeyIdentity);
365
- if (desired.migration?.executionPrincipal === 'excluded' || lockEntry?.migration?.executionPrincipal === 'excluded') {
366
- warnings.push(`Job template "${desired.stableKey}": source execution principal is excluded from migration.`);
391
+ if (!desired.executionPrincipal && (desired.migration?.executionPrincipal === 'excluded' || lockEntry?.migration?.executionPrincipal === 'excluded')) {
392
+ warnings.push(`Job template "${desired.stableKey}": execution principal excluded; manual target execution principal configuration is required.`);
367
393
  }
368
394
  if (desired.migration?.componentBinding === 'pinned-unsupported' || lockEntry?.migration?.componentBinding === 'pinned-unsupported') {
369
395
  blockers.push(`Job template "${desired.stableKey}" uses a pinned component version, which is unsupported.`);
@@ -403,6 +429,15 @@ export async function buildJobTemplatesPlan(input) {
403
429
  ...(projectedDependency ? { componentDesiredHash: projectedDependency.desiredHash } : {}),
404
430
  dependencyReadiness,
405
431
  };
432
+ if (desired.executionPrincipal) {
433
+ const key = desired.executionPrincipal.stableKey;
434
+ const liveMatches = await serviceAccountMatches(input.client, key, input.stableKeyName);
435
+ if (liveMatches.length > 1 || (liveMatches.length === 0 && !(input.projectedServiceAccounts || []).includes(key))) {
436
+ blockers.push(`Job template "${desired.stableKey}" execution principal "${key}" is missing or ambiguous.`);
437
+ items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, reason: 'execution principal is missing or ambiguous' });
438
+ continue;
439
+ }
440
+ }
406
441
  const desiredHash = hashPortableJobTemplate(desired);
407
442
  const matches = targetByKey.get(stableKeyIdentity) || [];
408
443
  if (matches.length === 0) {
@@ -462,6 +497,13 @@ export async function buildJobTemplatesPlan(input) {
462
497
  || normalizeStableKeyValue(leftKey).localeCompare(normalizeStableKeyValue(rightKey))
463
498
  || leftKey.localeCompare(rightKey);
464
499
  });
500
+ for (const item of items) {
501
+ const desired = localEntries.find((entry) => entry.manifest.stableKey === item.stableKey)?.manifest;
502
+ if (!desired?.executionPrincipal && (desired?.migration?.executionPrincipal === 'excluded'
503
+ || lockEntriesByKey.get(item.stableKey || '')?.migration?.executionPrincipal === 'excluded')) {
504
+ item.manual = ['Configure target-local execution principal manually'];
505
+ }
506
+ }
465
507
  const counts = emptyPlanCounts();
466
508
  for (const item of items)
467
509
  counts[item.status] += 1;
@@ -505,14 +547,15 @@ export async function pullJobTemplatesToWorkspace(input) {
505
547
  }
506
548
  const migration = {
507
549
  ...(typeof record.componentVersion === 'number' ? { componentBinding: 'pinned-unsupported' } : {}),
508
- ...(record.triggerUser ? { executionPrincipal: 'excluded' } : {}),
550
+ ...(record.triggerUser && !await accountPrincipal(input.client, record.triggerUser, input.stableKeyName) ? { executionPrincipal: 'excluded' } : {}),
509
551
  };
510
552
  manifests.push({
511
- ...manifestFromRecord(record, stableKey, dependencyStableKey, input.stableKeyName),
553
+ ...await withRecordPrincipal(input.client, record, manifestFromRecord(record, stableKey, dependencyStableKey, input.stableKeyName), input.stableKeyName, true),
512
554
  ...(Object.keys(migration).length > 0 ? { migration } : {}),
513
555
  });
514
- if (record.triggerUser)
515
- warnings.push({ stableKey, reason: 'triggerUser execution principal skipped' });
556
+ if (migration.executionPrincipal) {
557
+ warnings.push({ stableKey, reason: 'manual: triggerUser execution principal skipped; configure the human or unmanaged account on target' });
558
+ }
516
559
  }
517
560
  manifests.sort((left, right) => left.stableKey.localeCompare(right.stableKey));
518
561
  skipped.sort((left, right) => left.name.localeCompare(right.name));
@@ -690,7 +733,7 @@ export async function pushJobTemplates(input) {
690
733
  const stableKey = prepared.manifest.stableKey;
691
734
  const targetPath = localTargetPath(input.cwd, prepared.manifestPath);
692
735
  try {
693
- const created = unwrapData(await input.client.createJobTemplate(buildCreatePayload(prepared.manifest, prepared.componentId)));
736
+ const created = unwrapData(await input.client.createJobTemplate({ ...buildCreatePayload(prepared.manifest, prepared.componentId), ...await targetPrincipalId(input.client, prepared.manifest, input.stableKeyName) }));
694
737
  const createdId = jobTemplateIdOf(created);
695
738
  if (!createdId)
696
739
  throw new Error('create response did not include jobTemplateId');
@@ -703,7 +746,7 @@ export async function pushJobTemplates(input) {
703
746
  const verifiedComponentKey = await componentStableKey({ client: input.client, record: verified, stableKeyName: input.stableKeyName });
704
747
  if (!verifiedComponentKey)
705
748
  throw new Error(`created job template references a component without ${input.stableKeyName}`);
706
- const verifiedManifest = manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName);
749
+ const verifiedManifest = await withRecordPrincipal(input.client, verified, manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName), input.stableKeyName, Boolean(prepared.manifest.executionPrincipal));
707
750
  if (hashPortableJobTemplate(verifiedManifest) !== prepared.desiredHash) {
708
751
  throw new Error('created job template did not match desired portable hash');
709
752
  }
@@ -772,7 +815,7 @@ export async function pushJobTemplates(input) {
772
815
  const targetComponentKey = await componentStableKey({ client: input.client, record: target, stableKeyName: input.stableKeyName });
773
816
  if (!targetComponentKey)
774
817
  throw new Error(`target dependency is missing ${input.stableKeyName}`);
775
- const targetManifest = manifestFromRecord(target, targetStableKey, targetComponentKey, input.stableKeyName);
818
+ const targetManifest = await withRecordPrincipal(input.client, target, manifestFromRecord(target, targetStableKey, targetComponentKey, input.stableKeyName), input.stableKeyName, Boolean(local.manifest.executionPrincipal));
776
819
  const targetHash = hashPortableJobTemplate(targetManifest);
777
820
  if (targetHash !== item.currentHash)
778
821
  throw new Error('target changed after planning');
@@ -802,7 +845,7 @@ export async function pushJobTemplates(input) {
802
845
  const componentId = componentIdOf(componentMatches[0]);
803
846
  if (!componentId)
804
847
  throw new Error(`dependency "${local.manifest.component.stableKey}" has no target component id`);
805
- await input.client.updateJobTemplate(targetId, buildUpdatePayload(local.manifest, componentId, target.version));
848
+ await input.client.updateJobTemplate(targetId, { ...buildUpdatePayload(local.manifest, componentId, target.version), ...await targetPrincipalId(input.client, local.manifest, input.stableKeyName) });
806
849
  const verified = unwrapData(await input.client.getJobTemplate(targetId));
807
850
  const verifiedStableKey = readConfiguredResourceMetadataStableKey(verified, input.stableKeyName);
808
851
  if (verifiedStableKey !== stableKey)
@@ -810,7 +853,7 @@ export async function pushJobTemplates(input) {
810
853
  const verifiedComponentKey = await componentStableKey({ client: input.client, record: verified, stableKeyName: input.stableKeyName });
811
854
  if (!verifiedComponentKey)
812
855
  throw new Error(`updated target dependency is missing ${input.stableKeyName}`);
813
- const verifiedManifest = manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName);
856
+ const verifiedManifest = await withRecordPrincipal(input.client, verified, manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName), input.stableKeyName, Boolean(local.manifest.executionPrincipal));
814
857
  if (hashPortableJobTemplate(verifiedManifest) !== desiredHash) {
815
858
  throw new Error('updated job template did not match desired portable hash');
816
859
  }
@@ -0,0 +1,98 @@
1
+ import type { GroupOwnerPolicy } from '../component-lock.ts';
2
+ import { type IdentityProjection } from './account-principal.ts';
3
+ import { type FieldChange } from '../diff-details.ts';
4
+ import type { ServiceAccountRecord } from '../types.ts';
5
+ import type { RevoClient } from '../client.ts';
6
+ export declare const SERVICE_ACCOUNTS_DIRECTORY = "ServiceAccounts";
7
+ export declare const SERVICE_ACCOUNT_MANIFEST_FILE = "service-account.json";
8
+ export type ServiceAccountManifest = {
9
+ kind: 'service-account';
10
+ stableKey: string;
11
+ name: string;
12
+ owner: GroupOwnerPolicy;
13
+ metadata: Record<string, unknown>;
14
+ };
15
+ export type ServiceAccountPullResult = {
16
+ pulled: Array<{
17
+ manifest: ServiceAccountManifest;
18
+ targetPath: string;
19
+ }>;
20
+ pruned: Array<{
21
+ stableKey: string;
22
+ targetPath: string;
23
+ }>;
24
+ skipped: Array<{
25
+ name: string;
26
+ targetPath: string;
27
+ reason: string;
28
+ }>;
29
+ };
30
+ export type ServiceAccountPlanStatus = 'clean' | 'create' | 'safe-update' | 'remote-changed' | 'conflict' | 'missing-lock' | 'orphan' | 'collision' | 'skipped' | 'delete' | 'manual-owner';
31
+ export type ServiceAccountPlanItem = {
32
+ fieldChanges?: FieldChange[];
33
+ status: ServiceAccountPlanStatus;
34
+ stableKey?: string;
35
+ name: string;
36
+ reason?: string;
37
+ changedFields?: string[];
38
+ manual?: string[];
39
+ desiredHash?: string;
40
+ currentHash?: string;
41
+ baselineHash?: string;
42
+ };
43
+ export type ServiceAccountsPlan = {
44
+ resourceType: 'service-account';
45
+ env: string;
46
+ counts: Record<ServiceAccountPlanStatus, number>;
47
+ blockers: string[];
48
+ items: ServiceAccountPlanItem[];
49
+ exclusions: string[];
50
+ };
51
+ export type ServiceAccountPushResult = {
52
+ stableKey: string;
53
+ action: 'create' | 'update' | 'noop' | 'orphan' | 'skipped';
54
+ status: 'deployed' | 'skipped' | 'failed';
55
+ targetPath: string;
56
+ reason?: string;
57
+ error?: string;
58
+ credentials?: {
59
+ stableKey: string;
60
+ environment: string;
61
+ policy: 'target-local';
62
+ status: 'configure-manually' | 'preserved-target-local';
63
+ };
64
+ };
65
+ export declare function serviceAccountManifestFromRecord(client: RevoClient, record: ServiceAccountRecord, stableKeyName: string): Promise<ServiceAccountManifest | null>;
66
+ export declare function hashPortableServiceAccount(manifest: ServiceAccountManifest): string;
67
+ export declare function serviceAccountManifestPath(workspaceRoot: string, manifest: ServiceAccountManifest): string;
68
+ export declare function readWorkspaceServiceAccounts(cwd: string): {
69
+ manifestPath: string;
70
+ manifest: ServiceAccountManifest;
71
+ }[];
72
+ export declare function buildServiceAccountsPlan(input: {
73
+ client: RevoClient;
74
+ cwd: string;
75
+ envName: string;
76
+ stableKeyName: string;
77
+ projectedIdentities?: IdentityProjection;
78
+ onlyStableKeys?: string[];
79
+ }): Promise<ServiceAccountsPlan>;
80
+ export declare function pullServiceAccountsToWorkspace(input: {
81
+ client: RevoClient;
82
+ cwd: string;
83
+ envName: string;
84
+ stableKeyName: string;
85
+ force?: boolean;
86
+ pruneOrphans?: boolean;
87
+ }): Promise<ServiceAccountPullResult>;
88
+ export declare function pushServiceAccounts(input: {
89
+ client: RevoClient;
90
+ cwd: string;
91
+ envName: string;
92
+ stableKeyName: string;
93
+ force?: boolean;
94
+ onlyStableKeys?: string[];
95
+ }): Promise<{
96
+ plan: ServiceAccountsPlan;
97
+ results: ServiceAccountPushResult[];
98
+ }>;