@revoengine/cli 1.0.15 → 1.0.17
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/README.md +70 -12
- package/dist/src/cli.js +6 -2
- package/dist/src/client.d.ts +29 -3
- package/dist/src/client.js +92 -2
- package/dist/src/commands/component.js +2 -4
- package/dist/src/commands/index.d.ts +1 -0
- package/dist/src/commands/index.js +1 -0
- package/dist/src/commands/migrate.js +83 -20
- package/dist/src/commands/service-accounts.d.ts +2 -0
- package/dist/src/commands/service-accounts.js +149 -0
- package/dist/src/commands/terminal-browser.d.ts +29 -2
- package/dist/src/commands/terminal-browser.js +144 -35
- package/dist/src/commands/terminal-file.d.ts +21 -0
- package/dist/src/commands/terminal-file.js +160 -0
- package/dist/src/commands/terminal-operational-log.js +2 -2
- package/dist/src/commands/terminal-policy.d.ts +5 -2
- package/dist/src/commands/terminal-policy.js +10 -4
- package/dist/src/commands/terminal-reconnect-grace.js +1 -1
- package/dist/src/commands/terminal-sandbox.js +7 -0
- package/dist/src/commands/terminal-secure-browser.d.ts +1 -0
- package/dist/src/commands/terminal-secure-browser.js +2 -1
- package/dist/src/commands/terminal-service.js +4 -4
- package/dist/src/commands/terminal.d.ts +12 -0
- package/dist/src/commands/terminal.js +134 -45
- package/dist/src/component-lock.d.ts +4 -0
- package/dist/src/component-lock.js +21 -2
- package/dist/src/metadata-backfill.js +50 -1
- package/dist/src/migration.d.ts +20 -5
- package/dist/src/migration.js +200 -75
- package/dist/src/resource-inventory.d.ts +3 -2
- package/dist/src/resource-inventory.js +6 -1
- package/dist/src/resource-syncs/account-principal.d.ts +22 -0
- package/dist/src/resource-syncs/account-principal.js +86 -0
- package/dist/src/resource-syncs/group-sync.d.ts +10 -0
- package/dist/src/resource-syncs/group-sync.js +92 -20
- package/dist/src/resource-syncs/identity-migration.d.ts +19 -0
- package/dist/src/resource-syncs/identity-migration.js +108 -0
- package/dist/src/resource-syncs/job-template-sync.d.ts +4 -0
- package/dist/src/resource-syncs/job-template-sync.js +55 -12
- package/dist/src/resource-syncs/service-account-sync.d.ts +98 -0
- package/dist/src/resource-syncs/service-account-sync.js +620 -0
- package/dist/src/sync-output.js +10 -5
- package/dist/src/tracked-resources.d.ts +1 -1
- package/dist/src/tracked-resources.js +5 -1
- package/dist/src/types.d.ts +12 -0
- package/dist/src/ui.js +6 -3
- package/dist/src/workspace-diff.d.ts +1 -0
- package/dist/src/workspace-diff.js +4 -1
- package/dist/src/workspace-prune.d.ts +40 -0
- package/dist/src/workspace-prune.js +363 -0
- package/package.json +2 -2
package/dist/src/migration.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { applyWorkspacePrune, buildWorkspacePrunePlan, samePrunePlan } from "./workspace-prune.js";
|
|
3
|
+
import { planIdentityMigration } from "./resource-syncs/identity-migration.js";
|
|
4
|
+
import { SERVICE_ACCOUNTS_DIRECTORY, buildServiceAccountsPlan, pullServiceAccountsToWorkspace, pushServiceAccounts } from "./resource-syncs/service-account-sync.js";
|
|
2
5
|
import os from 'node:os';
|
|
3
6
|
import path from 'node:path';
|
|
4
7
|
import { RevoClient } from "./client.js";
|
|
@@ -19,6 +22,7 @@ const RESOURCE_ORDER = [
|
|
|
19
22
|
'database-table',
|
|
20
23
|
'database-view',
|
|
21
24
|
'component',
|
|
25
|
+
'service-account',
|
|
22
26
|
'job-template',
|
|
23
27
|
'endpoint',
|
|
24
28
|
'schedule',
|
|
@@ -486,6 +490,24 @@ function summarizeGroupPhase(plan) {
|
|
|
486
490
|
blockers,
|
|
487
491
|
};
|
|
488
492
|
}
|
|
493
|
+
function serviceAccountItemAction(item) {
|
|
494
|
+
if (item.status === 'manual-owner') {
|
|
495
|
+
return 'excluded';
|
|
496
|
+
}
|
|
497
|
+
return roleGroupItemAction({ ...item, status: item.status });
|
|
498
|
+
}
|
|
499
|
+
function summarizeServiceAccountPhase(plan) {
|
|
500
|
+
const operations = emptyOperations();
|
|
501
|
+
for (const item of plan.items) {
|
|
502
|
+
operations[serviceAccountItemAction(item)] += 1;
|
|
503
|
+
}
|
|
504
|
+
const warnings = [...plan.exclusions,
|
|
505
|
+
...plan.items.filter((item) => item.status === 'manual-owner').map((item) => `Service account "${item.stableKey}": ${item.reason}.`),
|
|
506
|
+
...plan.items.filter((item) => item.status === 'create').map((item) => `Service account "${item.stableKey}" will be created active with platform access; configure secrets separately on ${plan.env}.`),
|
|
507
|
+
];
|
|
508
|
+
return { order: 4, resource: 'service-account', operations, warnings, blockers: plan.blockers,
|
|
509
|
+
needsChanges: operations.create + operations.update > 0, readyToMigrate: plan.blockers.length === 0, verdict: phaseVerdict(plan.blockers, warnings) };
|
|
510
|
+
}
|
|
489
511
|
function summarizeRoleGroupPhase(plan) {
|
|
490
512
|
const operations = emptyOperations();
|
|
491
513
|
for (const item of plan.items) {
|
|
@@ -573,6 +595,9 @@ function summarizePulls(mode, pulls) {
|
|
|
573
595
|
skipped: pulls.groups.skipped.length,
|
|
574
596
|
};
|
|
575
597
|
}
|
|
598
|
+
if (pulls.serviceAccounts) {
|
|
599
|
+
byResource['service-account'] = { pulled: pulls.serviceAccounts.pulled.length, pruned: pulls.serviceAccounts.pruned.length, skipped: pulls.serviceAccounts.skipped.length };
|
|
600
|
+
}
|
|
576
601
|
if (pulls.roleGroups) {
|
|
577
602
|
byResource['role-group'] = {
|
|
578
603
|
pulled: pulls.roleGroups.pulled.length,
|
|
@@ -593,7 +618,7 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
|
|
|
593
618
|
}
|
|
594
619
|
const gates = [];
|
|
595
620
|
const forceOperations = [];
|
|
596
|
-
if (phase.resource === 'database-table' && plans.databaseSchemas) {
|
|
621
|
+
if (phase.resource === 'database-table' && plans.databaseSchemas && !input.prune) {
|
|
597
622
|
for (const item of plans.databaseSchemas.items.filter((candidate) => candidate.status === 'delete-partition')) {
|
|
598
623
|
const operation = {
|
|
599
624
|
from: 'excluded',
|
|
@@ -628,6 +653,17 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
|
|
|
628
653
|
}
|
|
629
654
|
}
|
|
630
655
|
}
|
|
656
|
+
if (phase.resource === 'service-account' && plans.serviceAccounts) {
|
|
657
|
+
for (const item of plans.serviceAccounts.items) {
|
|
658
|
+
const action = serviceAccountItemAction(item);
|
|
659
|
+
if (action === 'create' || action === 'update') {
|
|
660
|
+
gates.push({
|
|
661
|
+
from: action,
|
|
662
|
+
message: `Service Account "${item.stableKey || item.name}" can change environment access and requires --force for repository deployment.`,
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
631
667
|
if (phase.resource === 'role-group' && plans.roleGroups) {
|
|
632
668
|
for (const item of plans.roleGroups.items) {
|
|
633
669
|
const action = roleGroupItemAction(item);
|
|
@@ -642,7 +678,7 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
|
|
|
642
678
|
const operations = { ...phase.operations };
|
|
643
679
|
if (input.allowDestructive === true) {
|
|
644
680
|
for (const operation of forceOperations) {
|
|
645
|
-
operations[operation.from] = Math.max(0, operations[operation.from] - 1);
|
|
681
|
+
operations[operation.from] = Math.max(0, (operations[operation.from] || 0) - 1);
|
|
646
682
|
operations.update += 1;
|
|
647
683
|
}
|
|
648
684
|
return {
|
|
@@ -655,7 +691,7 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
|
|
|
655
691
|
return phase;
|
|
656
692
|
}
|
|
657
693
|
for (const gate of gates) {
|
|
658
|
-
operations[gate.from] = Math.max(0, operations[gate.from] - 1);
|
|
694
|
+
operations[gate.from] = Math.max(0, (operations[gate.from] || 0) - 1);
|
|
659
695
|
operations.blocked += 1;
|
|
660
696
|
}
|
|
661
697
|
const blockers = [...new Set([...phase.blockers, ...gates.map((gate) => gate.message)])];
|
|
@@ -673,89 +709,94 @@ function combinePlan(input) {
|
|
|
673
709
|
...(input.databaseSchemas ? [summarizeSchemaPhase(input.databaseSchemas)] : []),
|
|
674
710
|
...(input.databaseViews ? [summarizeViewPhase(input.databaseViews)] : []),
|
|
675
711
|
...(input.components ? [summarizeComponentPhase(input.components)] : []),
|
|
712
|
+
...(input.serviceAccounts ? [summarizeServiceAccountPhase(input.serviceAccounts)] : []),
|
|
676
713
|
...(input.jobTemplates ? [summarizeJobTemplatePhase(input.jobTemplates)] : []),
|
|
677
714
|
...(input.endpoints ? [summarizeEndpointPhase(input.endpoints)] : []),
|
|
678
715
|
...(input.schedules ? [summarizeSchedulePhase(input.schedules)] : []),
|
|
679
716
|
...(input.events ? [summarizeEventPhase(input.events)] : []),
|
|
680
717
|
...(input.groups ? [summarizeGroupPhase(input.groups)] : []),
|
|
681
718
|
...(input.roleGroups ? [summarizeRoleGroupPhase(input.roleGroups)] : []),
|
|
682
|
-
].map((phase) => applyWorkspaceDeploymentPolicy(input.migrationInput, phase, input))
|
|
719
|
+
].map((phase) => ({ ...phase, order: RESOURCE_ORDER.indexOf(phase.resource) + 1 })).map((phase) => applyWorkspaceDeploymentPolicy(input.migrationInput, phase, input))
|
|
683
720
|
.map((phase) => {
|
|
684
|
-
const pullWarnings = phase.resource === '
|
|
685
|
-
? (input.pulls.
|
|
686
|
-
: phase.resource === 'database-
|
|
687
|
-
? (input.pulls.
|
|
688
|
-
: phase.resource === '
|
|
689
|
-
? (input.pulls.
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
.map((item) => `Source Schedule "${item.stableKey}": ${item.reason}.`),
|
|
706
|
-
...(input.pulls.schedules?.pulled || [])
|
|
707
|
-
.filter(({ manifest }) => manifest.activationCandidate === true)
|
|
708
|
-
.map(({ manifest }) => `Source Schedule "${manifest.stableKey}" is an activation candidate; migration syncs its portable definition but does not automatically change target activation state.`),
|
|
709
|
-
]
|
|
710
|
-
: phase.resource === 'event'
|
|
721
|
+
const pullWarnings = phase.resource === 'service-account'
|
|
722
|
+
? (input.pulls.serviceAccounts?.skipped || []).map((item) => `Source Service Account "${item.name}" skipped: ${item.reason}.`)
|
|
723
|
+
: phase.resource === 'database-table'
|
|
724
|
+
? (input.pulls.databaseSchemas?.skipped || []).map((item) => `Source Database Table skipped: ${item.targetPath}: ${item.reason}.`)
|
|
725
|
+
: phase.resource === 'database-view'
|
|
726
|
+
? (input.pulls.databaseViews?.skipped || []).map((item) => `Source Database View "${item.stableKey || item.name}" skipped: ${item.reason}.`)
|
|
727
|
+
: phase.resource === 'component'
|
|
728
|
+
? (input.pulls.components || [])
|
|
729
|
+
.filter((item) => item.status === 'skipped' && item.reason !== 'no changes')
|
|
730
|
+
.map((item) => `Source Component skipped: ${item.targetPath}: ${item.reason || 'unknown reason'}.`)
|
|
731
|
+
: phase.resource === 'job-template'
|
|
732
|
+
? [
|
|
733
|
+
...(input.pulls.jobTemplates?.skipped || [])
|
|
734
|
+
.map((item) => `Source Job Template "${item.name}" skipped: ${item.reason}.`),
|
|
735
|
+
...(input.pulls.jobTemplates?.warnings || [])
|
|
736
|
+
.map((item) => `Source Job Template "${item.stableKey}": ${item.reason}.`),
|
|
737
|
+
]
|
|
738
|
+
: phase.resource === 'endpoint'
|
|
739
|
+
? (input.pulls.endpoints?.skipped || [])
|
|
740
|
+
.map((item) => `Source Endpoint skipped: ${item.targetPath}: ${item.reason}.`)
|
|
741
|
+
: phase.resource === 'schedule'
|
|
711
742
|
? [
|
|
712
|
-
...(input.pulls.
|
|
713
|
-
.map((item) => `Source
|
|
714
|
-
...(input.pulls.
|
|
715
|
-
.filter(({ manifest }) => manifest.
|
|
716
|
-
.map(({ manifest }) => `Source
|
|
743
|
+
...(input.pulls.schedules?.warnings || [])
|
|
744
|
+
.map((item) => `Source Schedule "${item.stableKey}": ${item.reason}.`),
|
|
745
|
+
...(input.pulls.schedules?.pulled || [])
|
|
746
|
+
.filter(({ manifest }) => manifest.activationCandidate === true)
|
|
747
|
+
.map(({ manifest }) => `Source Schedule "${manifest.stableKey}" is an activation candidate; migration syncs its portable definition but does not automatically change target activation state.`),
|
|
717
748
|
]
|
|
718
|
-
: phase.resource === '
|
|
749
|
+
: phase.resource === 'event'
|
|
719
750
|
? [
|
|
720
|
-
...(input.pulls.
|
|
721
|
-
.map((item) => `Source
|
|
722
|
-
...(input.pulls.
|
|
723
|
-
.
|
|
751
|
+
...(input.pulls.events?.warnings || [])
|
|
752
|
+
.map((item) => `Source Event "${item.stableKey}": ${item.reason}.`),
|
|
753
|
+
...(input.pulls.events?.pulled || [])
|
|
754
|
+
.filter(({ manifest }) => manifest.active === true)
|
|
755
|
+
.map(({ manifest }) => `Source Event "${manifest.stableKey}" is active; migration syncs its portable configuration but does not automatically change target activation state.`),
|
|
724
756
|
]
|
|
725
|
-
:
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
757
|
+
: phase.resource === 'group'
|
|
758
|
+
? [
|
|
759
|
+
...(input.pulls.groups?.skipped || [])
|
|
760
|
+
.map((item) => `Source Group "${item.name}" skipped: ${item.reason}.`),
|
|
761
|
+
...(input.pulls.groups?.notices || [])
|
|
762
|
+
.map((item) => `Source Group "${item.stableKey}": ${item.reason}.`),
|
|
763
|
+
]
|
|
764
|
+
: (input.pulls.roleGroups?.skipped || [])
|
|
765
|
+
.map((item) => `Source Role Group "${item.name}" skipped: ${item.reason}.`);
|
|
766
|
+
const pruneWarnings = phase.resource === 'service-account'
|
|
767
|
+
? (input.pulls.serviceAccounts?.pruned || []).map((item) => `Pruned stale source workspace Service Account "${item.stableKey}".`)
|
|
768
|
+
: phase.resource === 'database-table'
|
|
769
|
+
? (input.pulls.databaseSchemas?.pruned || []).map((item) => `Pruned stale source workspace Database Table "${item.stableKey}".`)
|
|
770
|
+
: phase.resource === 'database-view'
|
|
771
|
+
? (input.pulls.databaseViews?.pruned || []).map((item) => `Pruned stale source workspace Database View "${item.stableKey}".`)
|
|
772
|
+
: phase.resource === 'component'
|
|
773
|
+
? (input.pulls.components || [])
|
|
774
|
+
.filter((item) => item.status === 'pruned')
|
|
775
|
+
.map((item) => `Pruned stale source workspace Component at "${item.targetPath}".`)
|
|
776
|
+
: phase.resource === 'job-template'
|
|
777
|
+
? (input.pulls.jobTemplates?.pruned || [])
|
|
778
|
+
.map((item) => `Pruned stale source workspace Job Template "${item.stableKey}".`)
|
|
779
|
+
: phase.resource === 'endpoint'
|
|
780
|
+
? (input.pulls.endpoints?.pruned || [])
|
|
781
|
+
.map((item) => `Pruned stale source workspace Endpoint "${item.stableKey}".`)
|
|
782
|
+
: phase.resource === 'schedule'
|
|
783
|
+
? (input.pulls.schedules?.pruned || [])
|
|
784
|
+
.map((item) => `Pruned stale source workspace Schedule "${item.stableKey}".`)
|
|
785
|
+
: phase.resource === 'event'
|
|
786
|
+
? (input.pulls.events?.pruned || [])
|
|
787
|
+
.map((item) => `Pruned stale source workspace Event "${item.stableKey}".`)
|
|
788
|
+
: phase.resource === 'group'
|
|
789
|
+
? (input.pulls.groups?.pruned || [])
|
|
790
|
+
.map((item) => `Pruned stale source workspace Group "${item.stableKey}".`)
|
|
791
|
+
: (input.pulls.roleGroups?.pruned || [])
|
|
792
|
+
.map((item) => `Pruned stale source workspace Role Group "${item.stableKey}".`);
|
|
752
793
|
const warnings = [...new Set([...phase.warnings, ...pullWarnings, ...pruneWarnings])];
|
|
753
794
|
return { ...phase, warnings, verdict: phaseVerdict(phase.blockers, warnings) };
|
|
754
795
|
});
|
|
755
796
|
const operations = emptyOperations();
|
|
756
797
|
for (const phase of phases) {
|
|
757
798
|
for (const key of Object.keys(operations)) {
|
|
758
|
-
operations[key]
|
|
799
|
+
operations[key] = (operations[key] || 0) + (phase.operations[key] || 0);
|
|
759
800
|
}
|
|
760
801
|
}
|
|
761
802
|
const warnings = [...new Set(phases.flatMap((phase) => phase.warnings))];
|
|
@@ -782,6 +823,7 @@ function combinePlan(input) {
|
|
|
782
823
|
...(input.events ? { events: input.events } : {}),
|
|
783
824
|
...(input.groups ? { groups: input.groups } : {}),
|
|
784
825
|
...(input.roleGroups ? { roleGroups: input.roleGroups } : {}),
|
|
826
|
+
...(input.serviceAccounts ? { serviceAccounts: input.serviceAccounts } : {}),
|
|
785
827
|
warnings,
|
|
786
828
|
blockers,
|
|
787
829
|
};
|
|
@@ -816,6 +858,7 @@ function createTemporaryProject(input) {
|
|
|
816
858
|
EVENTS_DIRECTORY,
|
|
817
859
|
GROUPS_DIRECTORY,
|
|
818
860
|
ROLE_GROUPS_DIRECTORY,
|
|
861
|
+
SERVICE_ACCOUNTS_DIRECTORY,
|
|
819
862
|
]) {
|
|
820
863
|
const sourceDirectory = path.join(workspaceRoot, directory);
|
|
821
864
|
if (fs.existsSync(sourceDirectory)) {
|
|
@@ -927,6 +970,10 @@ export async function pullResourcesToWorkspace(input) {
|
|
|
927
970
|
pruneOrphans: input.pruneOrphans === true,
|
|
928
971
|
}));
|
|
929
972
|
}
|
|
973
|
+
if (resources.includes('service-account')) {
|
|
974
|
+
pulls.serviceAccounts = await runMigrationStage('source pull', 'service-account', input.sourceLabel, () => pullServiceAccountsToWorkspace({ client, cwd: input.cwd, envName: input.sourceKey, stableKeyName,
|
|
975
|
+
force: input.force === true, pruneOrphans: input.pruneOrphans === true }));
|
|
976
|
+
}
|
|
930
977
|
if (resources.includes('job-template')) {
|
|
931
978
|
pulls.jobTemplates = await runMigrationStage('source pull', 'job-template', input.sourceLabel, () => pullJobTemplatesToWorkspace({
|
|
932
979
|
client,
|
|
@@ -1130,12 +1177,20 @@ async function planWorkspace(input) {
|
|
|
1130
1177
|
operation: 'plan',
|
|
1131
1178
|
}), undefined, input.detailedDiff === true))
|
|
1132
1179
|
: undefined;
|
|
1180
|
+
const identities = await planIdentityMigration({ client, cwd: input.cwd, stableKeyName, resources });
|
|
1181
|
+
const serviceAccounts = resources.includes('service-account')
|
|
1182
|
+
? await runMigrationStage('target plan', 'service-account', environmentLabel, () => buildServiceAccountsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName,
|
|
1183
|
+
projectedIdentities: identities?.projection })) : undefined;
|
|
1184
|
+
if (serviceAccounts && identities) {
|
|
1185
|
+
serviceAccounts.blockers.push(...identities.blockers);
|
|
1186
|
+
}
|
|
1133
1187
|
const jobTemplates = resources.includes('job-template')
|
|
1134
1188
|
? await runMigrationStage('target plan', 'job-template', environmentLabel, () => buildJobTemplatesPlan({
|
|
1135
1189
|
client,
|
|
1136
1190
|
cwd: input.cwd,
|
|
1137
1191
|
envName: environmentKey,
|
|
1138
1192
|
stableKeyName,
|
|
1193
|
+
projectedServiceAccounts: identities?.projection.serviceAccounts,
|
|
1139
1194
|
...(input.projectDependencies === true && components
|
|
1140
1195
|
? { projectedComponents: projectedComponentDependencies(components) }
|
|
1141
1196
|
: {}),
|
|
@@ -1183,8 +1238,12 @@ async function planWorkspace(input) {
|
|
|
1183
1238
|
cwd: input.cwd,
|
|
1184
1239
|
envName: environmentKey,
|
|
1185
1240
|
stableKeyName,
|
|
1241
|
+
projectedIdentities: identities?.projection,
|
|
1186
1242
|
}))
|
|
1187
1243
|
: undefined;
|
|
1244
|
+
if (groups && identities && !serviceAccounts) {
|
|
1245
|
+
groups.blockers.push(...identities.blockers);
|
|
1246
|
+
}
|
|
1188
1247
|
const roleGroups = resources.includes('role-group')
|
|
1189
1248
|
? await runMigrationStage('target plan', 'role-group', environmentLabel, () => buildRoleGroupsPlan({
|
|
1190
1249
|
client,
|
|
@@ -1193,7 +1252,7 @@ async function planWorkspace(input) {
|
|
|
1193
1252
|
stableKeyName,
|
|
1194
1253
|
}))
|
|
1195
1254
|
: undefined;
|
|
1196
|
-
|
|
1255
|
+
const combined = combinePlan({
|
|
1197
1256
|
migrationInput: input,
|
|
1198
1257
|
sourcePullMode: input.sourcePullMode,
|
|
1199
1258
|
pulls: input.pulls,
|
|
@@ -1206,7 +1265,30 @@ async function planWorkspace(input) {
|
|
|
1206
1265
|
events,
|
|
1207
1266
|
groups,
|
|
1208
1267
|
roleGroups,
|
|
1268
|
+
serviceAccounts,
|
|
1209
1269
|
});
|
|
1270
|
+
if (identities) {
|
|
1271
|
+
combined.identityOrder = identities.ordered.map(({ resource, stableKey }) => ({ resource, stableKey }));
|
|
1272
|
+
}
|
|
1273
|
+
if (input.prune) {
|
|
1274
|
+
if (input.sourceMode !== 'workspace')
|
|
1275
|
+
throw new Error('Prune requires repository plan/deploy; named migration remains upsert-only.');
|
|
1276
|
+
combined.prune = await buildWorkspacePrunePlan({ cwd: input.cwd, client, resources });
|
|
1277
|
+
combined.pruneTargetKey = environmentKey;
|
|
1278
|
+
combined.policy.mode = 'reconcile';
|
|
1279
|
+
combined.operations.delete = combined.prune.items.length;
|
|
1280
|
+
combined.operations.blocked += combined.prune.blockers.length;
|
|
1281
|
+
for (const phase of combined.phases) {
|
|
1282
|
+
const removed = Math.min(phase.operations.excluded, combined.prune.items.filter((item) => item.resource === phase.resource).length);
|
|
1283
|
+
phase.operations.excluded -= removed;
|
|
1284
|
+
combined.operations.excluded -= removed;
|
|
1285
|
+
}
|
|
1286
|
+
combined.blockers = [...new Set([...combined.blockers, ...combined.prune.blockers])];
|
|
1287
|
+
combined.readyToMigrate = combined.blockers.length === 0;
|
|
1288
|
+
combined.needsChanges ||= combined.prune.items.length > 0;
|
|
1289
|
+
combined.verdict = phaseVerdict(combined.blockers, combined.warnings);
|
|
1290
|
+
}
|
|
1291
|
+
return combined;
|
|
1210
1292
|
}
|
|
1211
1293
|
export async function buildMigrationPlan(input) {
|
|
1212
1294
|
requireProject(input);
|
|
@@ -1235,7 +1317,7 @@ export async function buildMigrationPlan(input) {
|
|
|
1235
1317
|
}
|
|
1236
1318
|
}
|
|
1237
1319
|
function resultsAreComplete(results) {
|
|
1238
|
-
return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
|
|
1320
|
+
return results.every((result) => result.status === 'deployed' || result.status === 'skipped' || result.status === 'pruned');
|
|
1239
1321
|
}
|
|
1240
1322
|
function componentResultsAreComplete(results) {
|
|
1241
1323
|
return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
|
|
@@ -1267,6 +1349,11 @@ export async function runMigration(input) {
|
|
|
1267
1349
|
sourcePullMode,
|
|
1268
1350
|
projectDependencies: true,
|
|
1269
1351
|
});
|
|
1352
|
+
if (input.reviewedPrune && (!initialPlan.prune || !samePrunePlan(input.reviewedPrune, initialPlan.prune))) {
|
|
1353
|
+
initialPlan.blockers.push('Deletion plan changed after confirmation; review the fresh plan before deploying.');
|
|
1354
|
+
initialPlan.readyToMigrate = false;
|
|
1355
|
+
initialPlan.verdict = 'blocked';
|
|
1356
|
+
}
|
|
1270
1357
|
const base = {
|
|
1271
1358
|
schemaVersion: 2,
|
|
1272
1359
|
command: 'run',
|
|
@@ -1291,8 +1378,8 @@ export async function runMigration(input) {
|
|
|
1291
1378
|
envName: environmentKey,
|
|
1292
1379
|
stableKeyName,
|
|
1293
1380
|
force: true,
|
|
1294
|
-
prunePartitions: reviewedWorkspaceChanges,
|
|
1295
|
-
prunePartitionsConfirmed: reviewedWorkspaceChanges,
|
|
1381
|
+
prunePartitions: reviewedWorkspaceChanges && !input.prune,
|
|
1382
|
+
prunePartitionsConfirmed: reviewedWorkspaceChanges && !input.prune,
|
|
1296
1383
|
migrationPolicy: migrationPolicy(input),
|
|
1297
1384
|
});
|
|
1298
1385
|
phaseResults['database-table'] = pushed.results;
|
|
@@ -1322,6 +1409,7 @@ export async function runMigration(input) {
|
|
|
1322
1409
|
events: initialPlan.events,
|
|
1323
1410
|
groups: initialPlan.groups,
|
|
1324
1411
|
roleGroups: initialPlan.roleGroups,
|
|
1412
|
+
serviceAccounts: initialPlan.serviceAccounts,
|
|
1325
1413
|
});
|
|
1326
1414
|
return { ...base, verdict: 'failed', results, phaseResults, verification };
|
|
1327
1415
|
}
|
|
@@ -1404,6 +1492,32 @@ export async function runMigration(input) {
|
|
|
1404
1492
|
return { ...base, verdict: 'failed', results, phaseResults, verification };
|
|
1405
1493
|
}
|
|
1406
1494
|
}
|
|
1495
|
+
const identityRun = await planIdentityMigration({ client: targetClient, cwd: input.cwd, stableKeyName, resources });
|
|
1496
|
+
if (identityRun) {
|
|
1497
|
+
if (identityRun.blockers.length > 0) {
|
|
1498
|
+
return { ...base, verdict: 'failed', results, phaseResults };
|
|
1499
|
+
}
|
|
1500
|
+
for (const node of identityRun.ordered) {
|
|
1501
|
+
const pushed = node.resource === 'service-account'
|
|
1502
|
+
? await pushServiceAccounts({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true, onlyStableKeys: [node.stableKey] })
|
|
1503
|
+
: await pushGroups({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true, onlyStableKeys: [node.stableKey] });
|
|
1504
|
+
const relevant = pushed.results.filter((item) => item.stableKey === node.stableKey);
|
|
1505
|
+
phaseResults[node.resource] = [...(phaseResults[node.resource] || []), ...relevant];
|
|
1506
|
+
results.push(...relevant);
|
|
1507
|
+
if (!resultsAreComplete(relevant)) {
|
|
1508
|
+
return { ...base, verdict: 'failed', results, phaseResults };
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
if (resources.includes('service-account')) {
|
|
1512
|
+
const pushed = await pushServiceAccounts({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true });
|
|
1513
|
+
const remaining = pushed.results.filter((item) => !(phaseResults['service-account'] || []).some((prior) => 'stableKey' in prior && prior.stableKey === item.stableKey));
|
|
1514
|
+
phaseResults['service-account'] = [...(phaseResults['service-account'] || []), ...remaining];
|
|
1515
|
+
results.push(...remaining);
|
|
1516
|
+
if (!resultsAreComplete(pushed.results)) {
|
|
1517
|
+
return { ...base, verdict: 'failed', results, phaseResults };
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1407
1521
|
if (resources.includes('job-template')) {
|
|
1408
1522
|
const liveJobTemplatePlan = await buildJobTemplatesPlan({
|
|
1409
1523
|
client: targetClient,
|
|
@@ -1567,8 +1681,9 @@ export async function runMigration(input) {
|
|
|
1567
1681
|
stableKeyName,
|
|
1568
1682
|
force: true,
|
|
1569
1683
|
});
|
|
1570
|
-
phaseResults.group
|
|
1571
|
-
|
|
1684
|
+
const groupRemaining = pushed.results.filter((item) => !(phaseResults.group || []).some((prior) => 'stableKey' in prior && prior.stableKey === item.stableKey));
|
|
1685
|
+
phaseResults.group = [...(phaseResults.group || []), ...groupRemaining];
|
|
1686
|
+
results.push(...groupRemaining);
|
|
1572
1687
|
if (!resultsAreComplete(pushed.results)) {
|
|
1573
1688
|
const verification = await planWorkspace({
|
|
1574
1689
|
...input,
|
|
@@ -1614,6 +1729,16 @@ export async function runMigration(input) {
|
|
|
1614
1729
|
return { ...base, verdict: 'failed', results, phaseResults, verification };
|
|
1615
1730
|
}
|
|
1616
1731
|
}
|
|
1732
|
+
if (initialPlan.prune) {
|
|
1733
|
+
const fresh = await buildWorkspacePrunePlan({ cwd: input.cwd, client: targetClient, resources });
|
|
1734
|
+
if (!samePrunePlan(initialPlan.prune, fresh)) {
|
|
1735
|
+
results.push({ status: 'failed', targetPath: 'workspace prune', reason: 'Deletion plan changed during upserts; review a fresh plan.' });
|
|
1736
|
+
return { ...base, verdict: 'failed', results, phaseResults };
|
|
1737
|
+
}
|
|
1738
|
+
const pruneResults = await applyWorkspacePrune({ cwd: input.cwd, client: targetClient,
|
|
1739
|
+
resources, envName: environmentKey, plan: initialPlan.prune });
|
|
1740
|
+
results.push(...pruneResults);
|
|
1741
|
+
}
|
|
1617
1742
|
const verification = await planWorkspace({
|
|
1618
1743
|
...input,
|
|
1619
1744
|
pulls,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { RevoClient } from './client.ts';
|
|
2
2
|
import type { TrackableResourceType } from './tracked-resources.ts';
|
|
3
|
-
import type { ComponentRecord, DatabaseSchemaRecord, DatabaseViewRecord, EndpointRecord, EventRecord, GroupRecord, JobTemplateRecord, RoleGroupRecord, ScheduleRecord } from './types.ts';
|
|
3
|
+
import type { ComponentRecord, DatabaseSchemaRecord, DatabaseViewRecord, EndpointRecord, EventRecord, GroupRecord, JobTemplateRecord, RoleGroupRecord, ScheduleRecord, ServiceAccountRecord } from './types.ts';
|
|
4
4
|
type ResourceRecordMap = {
|
|
5
|
+
'service-account': ServiceAccountRecord;
|
|
5
6
|
component: ComponentRecord;
|
|
6
7
|
'database-table': DatabaseSchemaRecord;
|
|
7
8
|
'database-view': DatabaseViewRecord;
|
|
@@ -13,7 +14,7 @@ type ResourceRecordMap = {
|
|
|
13
14
|
event: EventRecord;
|
|
14
15
|
};
|
|
15
16
|
export type ResourceRecord = ResourceRecordMap[TrackableResourceType];
|
|
16
|
-
export type ResourceInventoryClient = Pick<RevoClient, 'listAllComponents' | 'getComponent' | 'listAllDatabaseSchemas' | 'listAllDatabaseViewsForSync' | 'listAllEndpoints' | 'getEndpoint' | 'listAllRoleGroups' | 'getRoleGroup' | 'listAllGroups' | 'getGroup' | 'listAllJobTemplates' | 'getJobTemplate' | 'listAllSchedules' | 'getSchedule' | 'listAllEvents' | 'getEvent'>;
|
|
17
|
+
export type ResourceInventoryClient = Pick<RevoClient, 'listAllServiceAccounts' | 'getServiceAccount' | 'listAllComponents' | 'getComponent' | 'listAllDatabaseSchemas' | 'listAllDatabaseViewsForSync' | 'listAllEndpoints' | 'getEndpoint' | 'listAllRoleGroups' | 'getRoleGroup' | 'listAllGroups' | 'getGroup' | 'listAllJobTemplates' | 'getJobTemplate' | 'listAllSchedules' | 'getSchedule' | 'listAllEvents' | 'getEvent'>;
|
|
17
18
|
type InventoryOptions = {
|
|
18
19
|
skipPartitions?: boolean;
|
|
19
20
|
};
|
|
@@ -10,7 +10,8 @@ export function unwrapResource(value) {
|
|
|
10
10
|
return value;
|
|
11
11
|
}
|
|
12
12
|
export function resourceIdOf(resource) {
|
|
13
|
-
return String(('
|
|
13
|
+
return String(('userId' in resource && resource.userId)
|
|
14
|
+
|| ('databaseId' in resource && resource.databaseId)
|
|
14
15
|
|| ('databaseViewId' in resource && resource.databaseViewId)
|
|
15
16
|
|| ('jobTemplateId' in resource && resource.jobTemplateId)
|
|
16
17
|
|| ('endpointId' in resource && resource.endpointId)
|
|
@@ -34,6 +35,10 @@ async function* readDetails(summaries, getDetail) {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
const readers = {
|
|
38
|
+
async *'service-account'(client) {
|
|
39
|
+
const { serviceAccounts } = await client.listAllServiceAccounts();
|
|
40
|
+
yield* readDetails(serviceAccounts, (id) => client.getServiceAccount(id));
|
|
41
|
+
},
|
|
37
42
|
async *component(client) {
|
|
38
43
|
const { components } = await client.listAllComponents();
|
|
39
44
|
yield* readDetails(components, (id) => client.getComponent(id));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type RevoClient } from '../client.ts';
|
|
2
|
+
import type { GroupOwnerPolicy } from '../component-lock.ts';
|
|
3
|
+
import type { ServiceAccountRecord } from '../types.ts';
|
|
4
|
+
export type ExecutionPrincipal = {
|
|
5
|
+
kind: 'service-account';
|
|
6
|
+
stableKey: string;
|
|
7
|
+
};
|
|
8
|
+
export type IdentityProjection = {
|
|
9
|
+
serviceAccounts?: string[];
|
|
10
|
+
groups?: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare function accountPrincipal(client: RevoClient, userId: string, stableKeyName: string): Promise<ExecutionPrincipal | undefined>;
|
|
13
|
+
export declare function readPortableOwner(client: RevoClient, record: ServiceAccountRecord, stableKeyName: string): Promise<GroupOwnerPolicy>;
|
|
14
|
+
export declare function serviceAccountMatches(client: RevoClient, stableKey: string, stableKeyName: string): Promise<ServiceAccountRecord[]>;
|
|
15
|
+
export declare function resolvePortableOwner(client: RevoClient, owner: GroupOwnerPolicy, stableKeyName: string): Promise<{
|
|
16
|
+
ownerType: "USER";
|
|
17
|
+
ownerId: string;
|
|
18
|
+
} | {
|
|
19
|
+
ownerType: "GROUP";
|
|
20
|
+
ownerId: string;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function ownerIsAvailable(client: RevoClient, owner: GroupOwnerPolicy, stableKeyName: string, projection?: IdentityProjection): Promise<boolean>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ApiError } from "../client.js";
|
|
2
|
+
import { readConfiguredResourceMetadataStableKey } from "../resource-metadata.js";
|
|
3
|
+
import { unwrapData } from "./util.js";
|
|
4
|
+
export async function accountPrincipal(client, userId, stableKeyName) {
|
|
5
|
+
let account;
|
|
6
|
+
try {
|
|
7
|
+
account = await client.getAccount(userId);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error instanceof ApiError && error.status === 404) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
if (account.serviceAccount !== true || account.deletedAt) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const stableKey = readConfiguredResourceMetadataStableKey(account, stableKeyName);
|
|
19
|
+
return stableKey ? { kind: 'service-account', stableKey } : undefined;
|
|
20
|
+
}
|
|
21
|
+
export async function readPortableOwner(client, record, stableKeyName) {
|
|
22
|
+
if (record.ownerType === 'USER' && record.ownerId) {
|
|
23
|
+
const principal = await accountPrincipal(client, record.ownerId, stableKeyName);
|
|
24
|
+
return principal ? { type: 'service-account', stableKey: principal.stableKey } : { type: 'manual-user' };
|
|
25
|
+
}
|
|
26
|
+
if (record.ownerType === 'GROUP' && record.ownerId) {
|
|
27
|
+
const group = unwrapData(await client.getGroup(record.ownerId));
|
|
28
|
+
const stableKey = readConfiguredResourceMetadataStableKey(group, stableKeyName);
|
|
29
|
+
return stableKey ? { type: 'group', stableKey } : { type: 'unresolved', reason: 'owner Group has no stableKey' };
|
|
30
|
+
}
|
|
31
|
+
return { type: 'unresolved', reason: 'owner is missing or unsupported' };
|
|
32
|
+
}
|
|
33
|
+
export async function serviceAccountMatches(client, stableKey, stableKeyName) {
|
|
34
|
+
const { serviceAccounts } = await client.listAllServiceAccounts();
|
|
35
|
+
const matches = [];
|
|
36
|
+
for (const summary of serviceAccounts) {
|
|
37
|
+
const account = await client.getServiceAccount(String(summary.userId || ''));
|
|
38
|
+
if (readConfiguredResourceMetadataStableKey(account, stableKeyName) === stableKey) {
|
|
39
|
+
matches.push(account);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return matches;
|
|
43
|
+
}
|
|
44
|
+
export async function resolvePortableOwner(client, owner, stableKeyName) {
|
|
45
|
+
if (owner.type === 'service-account') {
|
|
46
|
+
const matches = await serviceAccountMatches(client, owner.stableKey, stableKeyName);
|
|
47
|
+
if (matches.length !== 1 || !matches[0].userId) {
|
|
48
|
+
throw new Error(`Owner service-account "${owner.stableKey}" must resolve to exactly one target account.`);
|
|
49
|
+
}
|
|
50
|
+
return { ownerType: 'USER', ownerId: matches[0].userId };
|
|
51
|
+
}
|
|
52
|
+
if (owner.type === 'group') {
|
|
53
|
+
const { groups } = await client.listAllGroups();
|
|
54
|
+
const matches = [];
|
|
55
|
+
for (const summary of groups) {
|
|
56
|
+
const group = unwrapData(await client.getGroup(String(summary.groupId || summary.id || '')));
|
|
57
|
+
if (!group.deletedAt && readConfiguredResourceMetadataStableKey(group, stableKeyName) === owner.stableKey) {
|
|
58
|
+
matches.push(group);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (matches.length !== 1 || !matches[0].groupId) {
|
|
62
|
+
throw new Error(`Owner Group "${owner.stableKey}" must resolve to exactly one target group.`);
|
|
63
|
+
}
|
|
64
|
+
return { ownerType: 'GROUP', ownerId: matches[0].groupId };
|
|
65
|
+
}
|
|
66
|
+
throw new Error('Owner requires manual target configuration.');
|
|
67
|
+
}
|
|
68
|
+
export async function ownerIsAvailable(client, owner, stableKeyName, projection) {
|
|
69
|
+
if (owner.type !== 'group' && owner.type !== 'service-account') {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
await resolvePortableOwner(client, owner, stableKeyName);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Projection cannot mask duplicate live identities.
|
|
78
|
+
if (owner.type === 'service-account') {
|
|
79
|
+
const matches = await serviceAccountMatches(client, owner.stableKey, stableKeyName);
|
|
80
|
+
return matches.length === 0 && (projection?.serviceAccounts || []).includes(owner.stableKey);
|
|
81
|
+
}
|
|
82
|
+
const { groups } = await client.listAllGroups();
|
|
83
|
+
const matches = groups.filter((group) => readConfiguredResourceMetadataStableKey(group, stableKeyName) === owner.stableKey);
|
|
84
|
+
return matches.length === 0 && (projection?.groups || []).includes(owner.stableKey);
|
|
85
|
+
}
|
|
86
|
+
}
|