@sequenceholdings/studio-cli 0.1.31 → 0.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/README.md +335 -26
- package/dist/artifact/delegate.js +11 -2
- package/dist/atlas-client.d.ts +16 -0
- package/dist/atlas-client.js +26 -0
- package/dist/functions/bundle.js +4 -2
- package/dist/functions/commands.d.ts +12 -2
- package/dist/functions/commands.js +176 -14
- package/dist/functions/dev.d.ts +3 -0
- package/dist/functions/dev.js +97 -0
- package/dist/functions/egress-preview.d.ts +2 -1
- package/dist/functions/egress-preview.js +3 -2
- package/dist/functions/manifest.d.ts +18 -1
- package/dist/functions/manifest.js +19 -29
- package/dist/main.js +6 -1
- package/dist/pipeline/commands.js +16 -10
- package/dist/pipeline/lifecycle.d.ts +1 -0
- package/dist/pipeline/lifecycle.js +105 -28
- package/dist/pipeline/migrations.js +6 -1
- package/dist/pipeline/stage-secrets.d.ts +95 -0
- package/dist/pipeline/stage-secrets.js +166 -0
- package/dist/pipeline/templates.d.ts +1 -1
- package/dist/pipeline/templates.js +37 -3
- package/dist/process/build.js +1 -0
- package/dist/process/codegen.js +1 -0
- package/dist/process/lint.js +12 -7
- package/dist/process/plan-diff.js +1 -0
- package/dist/process/safety-baseline.d.ts +3 -3
- package/dist/process/safety-baseline.js +4 -5
- package/dist/process/simulate.js +7 -2
- package/dist/repos/commands.d.ts +11 -1
- package/dist/repos/commands.js +37 -11
- package/dist/secrets/commands.d.ts +1 -1
- package/dist/secrets/commands.js +73 -3
- package/dist/storage/commands.d.ts +2 -0
- package/dist/storage/commands.js +215 -0
- package/dist/templates/process/pnpm-workspace.yaml +3 -0
- package/package.json +7 -5
- package/templates/process/pnpm-workspace.yaml +3 -0
|
@@ -42,18 +42,23 @@ const PIPELINE_USAGE = `usage:
|
|
|
42
42
|
emit one <stage>.stage.yml per table from a typed PerTableIngestionAuthoring
|
|
43
43
|
module (default export, authoring, or silverlakeAuthoring export name)
|
|
44
44
|
|
|
45
|
-
seq-studio pipeline plan --repo
|
|
45
|
+
seq-studio pipeline plan --repo <namespace>/<slug> --ref <sha|branch> -e <env> [--target <id>] [--migration <id> [--in-place]] [--no-provision] [--json]
|
|
46
46
|
enqueue a durable plan, poll progress, then print the completed
|
|
47
47
|
materialize + SDK/graph + compile + live-diff + provision findings
|
|
48
48
|
(no Databricks CLI / DAB validate on Atlas); exit 1 on destructive findings
|
|
49
|
+
If a stage's source.credential has no managed secret attached for the
|
|
50
|
+
target (unresolved, or resolved the legacy way on a stage never deployed
|
|
51
|
+
there), attaches the secret named by convention (abrigo_oauth ->
|
|
52
|
+
ABRIGO_OAUTH) when you can edit it, then plans again; --no-provision (CI)
|
|
53
|
+
skips this
|
|
49
54
|
--migration adds a coordinated writer/ORM assessment; it cannot be
|
|
50
55
|
applied through ordinary deploy
|
|
51
56
|
|
|
52
|
-
seq-studio pipeline deploy --repo
|
|
57
|
+
seq-studio pipeline deploy --repo <namespace>/<slug> --ref <sha|branch> -e <env>
|
|
53
58
|
[--target <id>] [--approved-by <sub>]
|
|
54
59
|
[--allow-destructive <resource-key> ...]
|
|
55
|
-
[--run-now] [--wait-timeout <duration>] [--no-wait] [--json]
|
|
56
|
-
plan then enqueue Trigger deploy (DAB bundle validate hard-gates before
|
|
60
|
+
[--run-now] [--wait-timeout <duration>] [--no-wait] [--no-provision] [--json]
|
|
61
|
+
plan (attaching missing credentials as for plan) then enqueue Trigger deploy (DAB bundle validate hard-gates before
|
|
57
62
|
bundle deploy). Default is plant-only: jobs/pipelines are created, not
|
|
58
63
|
run. Pass --run-now to run in-unit producer roots after bundle deploy.
|
|
59
64
|
Serving refresh provisioning completes before producer trigger.after
|
|
@@ -71,12 +76,12 @@ const PIPELINE_USAGE = `usage:
|
|
|
71
76
|
tasks; this read does not start or resume any work
|
|
72
77
|
|
|
73
78
|
seq-studio pipeline promote --stage <slug> --version <v> -e <env>
|
|
74
|
-
[--target <id>] [--repo
|
|
79
|
+
[--target <id>] [--repo <namespace>/<slug>] [--approved-by <you>]
|
|
75
80
|
[--wait-timeout <duration>] [--no-wait]
|
|
76
81
|
promote a validated version to the next environment (approvals are
|
|
77
82
|
self-recorded: --approved-by must name the authenticated caller)
|
|
78
83
|
|
|
79
|
-
seq-studio pipeline rollback --stage <slug> -e <env> [--target <id>] [--repo
|
|
84
|
+
seq-studio pipeline rollback --stage <slug> -e <env> [--target <id>] [--repo <namespace>/<slug>]
|
|
80
85
|
[--approved-by <you>] [--wait-timeout <duration>] [--no-wait]
|
|
81
86
|
redeploy the previously retired deployment's version (production/
|
|
82
87
|
banksouth require --approved-by — approvals are explicit even for
|
|
@@ -95,22 +100,23 @@ const PIPELINE_USAGE = `usage:
|
|
|
95
100
|
seq-studio pipeline adopt --stage <slug> --ref <sha|branch> -e <env>
|
|
96
101
|
[--target <id>] --native-id <id> [--resource-key <key>] [--kind job|dlt_pipeline]
|
|
97
102
|
--approved-by <you> [--old-source-removal-pr <url>]
|
|
98
|
-
[--repo
|
|
103
|
+
[--repo <namespace>/<slug>] [--json]
|
|
99
104
|
bind a live Databricks job/pipeline to the stage without recreation
|
|
100
105
|
(SEQ-2449). Always requires --approved-by. Monorepo-declared keys also
|
|
101
106
|
require --old-source-removal-pr.
|
|
102
107
|
|
|
103
108
|
seq-studio pipeline unbind --stage <slug> --ref <sha|branch> -e <env> [--target <id>]
|
|
104
109
|
--approved-by <you> [--resource-key <key>]
|
|
105
|
-
[--repo
|
|
110
|
+
[--repo <namespace>/<slug>] [--json]
|
|
106
111
|
release an adopted binding; the remote object stays live (never deleted)
|
|
107
112
|
|
|
108
|
-
seq-studio pipeline run-now --stage <slug> -e <env> [--target <id>] [--repo
|
|
113
|
+
seq-studio pipeline run-now --stage <slug> -e <env> [--target <id>] [--repo <namespace>/<slug>] [--json]
|
|
109
114
|
fire the stage's active deployment resource (job run-now / DLT
|
|
110
115
|
start_update) and print the Databricks run URL.
|
|
111
116
|
|
|
112
117
|
-e/--env selects the Atlas connection. --target selects the logical target
|
|
113
118
|
advertised by that deployment; it is inferred when the endpoint exposes one target.
|
|
119
|
+
--repo accepts dedicated pipelines/<slug> repos and app-owned apps/<slug> monorepos.
|
|
114
120
|
`;
|
|
115
121
|
/**
|
|
116
122
|
* Same classification as the orm delegate: is the pipeline-spec package
|
|
@@ -177,7 +183,7 @@ export async function pipelineInitCommand(args) {
|
|
|
177
183
|
}
|
|
178
184
|
else {
|
|
179
185
|
await mkdir(join(dir, 'src'), { recursive: true });
|
|
180
|
-
await writeFile(stubPath, renderEntrypointStub(name), 'utf8');
|
|
186
|
+
await writeFile(stubPath, renderEntrypointStub(name, type), 'utf8');
|
|
181
187
|
console.log(`${LOG} wrote ${stubPath}`);
|
|
182
188
|
}
|
|
183
189
|
}
|
|
@@ -6,6 +6,7 @@ import { getAccessToken, NotLoggedInError } from '../auth.js';
|
|
|
6
6
|
import { AtlasApiError, getJson, postJson } from '../atlas-client.js';
|
|
7
7
|
import { resolveEnvWithDiscovery } from '../config.js';
|
|
8
8
|
import { parseDurationMs } from '@sequenceholdings/lattice';
|
|
9
|
+
import { printReconcileResult, reconcileStageCredentials } from './stage-secrets.js';
|
|
9
10
|
const LOG = '[seq-studio]';
|
|
10
11
|
const TERMINAL = new Set(['active', 'failed', 'retired']);
|
|
11
12
|
const POLL_INTERVAL_MS = 2000;
|
|
@@ -109,8 +110,13 @@ export async function pipelinePlanCommand(args) {
|
|
|
109
110
|
const repo = flagString(args.flags, 'repo');
|
|
110
111
|
const ref = flagString(args.flags, 'ref');
|
|
111
112
|
const migrationId = flagString(args.flags, 'migration');
|
|
113
|
+
const inPlace = flagOn(args.flags, 'in-place');
|
|
114
|
+
if (inPlace && !migrationId) {
|
|
115
|
+
console.error(`${LOG} --in-place requires --migration; choose the mode when planning`);
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
112
118
|
if (!repo || !ref) {
|
|
113
|
-
console.error('usage: seq-studio pipeline plan --repo
|
|
119
|
+
console.error('usage: seq-studio pipeline plan --repo <namespace>/<slug> --ref <sha|branch> -e <env> [--migration <id> [--in-place]] [--json]');
|
|
114
120
|
return 1;
|
|
115
121
|
}
|
|
116
122
|
const { env, token } = await envAndToken(args);
|
|
@@ -125,13 +131,17 @@ export async function pipelinePlanCommand(args) {
|
|
|
125
131
|
}
|
|
126
132
|
let response;
|
|
127
133
|
try {
|
|
128
|
-
response = await
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
response = await planAttachingCredentials({
|
|
135
|
+
request: {
|
|
136
|
+
baseUrl: env.url,
|
|
137
|
+
token,
|
|
138
|
+
repo,
|
|
139
|
+
ref,
|
|
140
|
+
environment: target.id,
|
|
141
|
+
...(migrationId ? { migrationId } : {}),
|
|
142
|
+
...(inPlace ? { executionMode: 'in_place' } : {}),
|
|
143
|
+
},
|
|
144
|
+
provision: !flagOn(args.flags, 'no-provision'),
|
|
135
145
|
});
|
|
136
146
|
}
|
|
137
147
|
catch (error) {
|
|
@@ -145,13 +155,17 @@ export async function pipelinePlanCommand(args) {
|
|
|
145
155
|
console.log(response.text);
|
|
146
156
|
printFindingsTable(response.plan.findings);
|
|
147
157
|
}
|
|
158
|
+
if (inPlace && response.plan.migrationExecutionMode !== 'in_place') {
|
|
159
|
+
console.error(`${LOG} server did not confirm in-place mode; do not start this plan`);
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
148
162
|
if (migrationId && response.migration)
|
|
149
163
|
return 0;
|
|
150
164
|
return response.plan.hasDestructive || response.plan.migrationAssessment?.contracts.findings.some((finding) => finding.severity === 'error') ? 1 : 0;
|
|
151
165
|
}
|
|
152
166
|
export async function pipelineDeployCommand(args) {
|
|
153
|
-
if (args.flags.migration !== undefined) {
|
|
154
|
-
console.error(`${LOG} --migration
|
|
167
|
+
if (args.flags.migration !== undefined || args.flags['in-place'] !== undefined) {
|
|
168
|
+
console.error(`${LOG} --migration and --in-place belong to pipeline plan; a migration cannot be applied as an ordinary deployment`);
|
|
155
169
|
return 1;
|
|
156
170
|
}
|
|
157
171
|
const repo = flagString(args.flags, 'repo');
|
|
@@ -196,16 +210,13 @@ export async function pipelineDeployCommand(args) {
|
|
|
196
210
|
}
|
|
197
211
|
else {
|
|
198
212
|
if (!repo || !ref) {
|
|
199
|
-
console.error('usage: seq-studio pipeline deploy --repo
|
|
213
|
+
console.error('usage: seq-studio pipeline deploy --repo <namespace>/<slug> --ref <sha|branch> -e <env> [--target <id>] [--approved-by <sub>] [--allow-destructive <resource-key> ...] [--run-now] [--wait-timeout <duration>] [--no-wait]');
|
|
200
214
|
return 1;
|
|
201
215
|
}
|
|
202
216
|
// Plan then deploy the first planning deployment.
|
|
203
|
-
const plan = await
|
|
204
|
-
baseUrl: env.url,
|
|
205
|
-
|
|
206
|
-
repo,
|
|
207
|
-
ref,
|
|
208
|
-
environment: target.id,
|
|
217
|
+
const plan = await planAttachingCredentials({
|
|
218
|
+
request: { baseUrl: env.url, token, repo, ref, environment: target.id },
|
|
219
|
+
provision: !flagOn(args.flags, 'no-provision'),
|
|
209
220
|
});
|
|
210
221
|
if (plan.plan.hasDestructive && allowDestructiveResourceKeys.length === 0) {
|
|
211
222
|
console.error(`${LOG} plan has destructive findings — refusing to deploy`);
|
|
@@ -295,7 +306,7 @@ export async function pipelinePromoteCommand(args) {
|
|
|
295
306
|
const approvedBy = flagString(args.flags, 'approved-by');
|
|
296
307
|
const waitTimeoutMs = deploymentWaitTimeoutMs(args);
|
|
297
308
|
if (!stage || !version) {
|
|
298
|
-
console.error('usage: seq-studio pipeline promote --stage <slug> --version <v> -e <env> [--repo
|
|
309
|
+
console.error('usage: seq-studio pipeline promote --stage <slug> --version <v> -e <env> [--repo <namespace>/<slug>] [--approved-by <you>] [--wait-timeout <duration>] [--no-wait]');
|
|
299
310
|
return 1;
|
|
300
311
|
}
|
|
301
312
|
const { env, token } = await envAndToken(args);
|
|
@@ -357,7 +368,7 @@ export async function pipelineRunNowCommand(args) {
|
|
|
357
368
|
const stage = flagString(args.flags, 'stage');
|
|
358
369
|
const repo = flagString(args.flags, 'repo');
|
|
359
370
|
if (!stage) {
|
|
360
|
-
console.error('usage: seq-studio pipeline run-now --stage <slug> -e <env> [--repo
|
|
371
|
+
console.error('usage: seq-studio pipeline run-now --stage <slug> -e <env> [--repo <namespace>/<slug>] [--json]');
|
|
361
372
|
return 1;
|
|
362
373
|
}
|
|
363
374
|
const { env, token } = await envAndToken(args);
|
|
@@ -410,7 +421,7 @@ export async function pipelineRollbackCommand(args) {
|
|
|
410
421
|
const approvedBy = flagString(args.flags, 'approved-by');
|
|
411
422
|
const waitTimeoutMs = deploymentWaitTimeoutMs(args);
|
|
412
423
|
if (!stage) {
|
|
413
|
-
console.error('usage: seq-studio pipeline rollback --stage <slug> -e <env> [--repo
|
|
424
|
+
console.error('usage: seq-studio pipeline rollback --stage <slug> -e <env> [--repo <namespace>/<slug>] [--approved-by <you>] [--wait-timeout <duration>] [--no-wait]');
|
|
414
425
|
return 1;
|
|
415
426
|
}
|
|
416
427
|
const { env, token } = await envAndToken(args);
|
|
@@ -512,12 +523,78 @@ async function pollDeployment({ baseUrl, token, deploymentId, environment, timeo
|
|
|
512
523
|
`(or, for internal operators: seqapi get /api/data-pipelines/deployments/${deploymentId} -e ${environment})`);
|
|
513
524
|
return 1;
|
|
514
525
|
}
|
|
515
|
-
|
|
526
|
+
/**
|
|
527
|
+
* Plan; if it fails and any stage's declared credential has nothing attached
|
|
528
|
+
* on the target, attach (as the caller) the managed secret named by convention
|
|
529
|
+
* and plan once more — `functions deploy`'s manifest reconcile, for pipelines.
|
|
530
|
+
* A failed plan still registers its stages, so this also covers new stages.
|
|
531
|
+
* `--no-provision` (CI) skips attaching and fails as before.
|
|
532
|
+
*/
|
|
533
|
+
async function planAttachingCredentials({ request, provision, }) {
|
|
534
|
+
let response;
|
|
535
|
+
try {
|
|
536
|
+
response = await enqueueAndWaitForPlan(request);
|
|
537
|
+
}
|
|
538
|
+
catch (error) {
|
|
539
|
+
if (!provision || !(error instanceof PlanRequestFailedError))
|
|
540
|
+
throw error;
|
|
541
|
+
if (!(await attachUnattachedCredentials({ request, stageIds: error.stageIds })))
|
|
542
|
+
throw error;
|
|
543
|
+
console.log(`${LOG} re-planning with the attached secrets`);
|
|
544
|
+
return enqueueAndWaitForPlan(request);
|
|
545
|
+
}
|
|
546
|
+
// A new stage can also plan the legacy way (a same-named secret exists) with
|
|
547
|
+
// nothing attached, and its get_credential would then fail at runtime.
|
|
548
|
+
if (provision && (await attachUnattachedCredentials({ request, stageIds: response.stageIds }))) {
|
|
549
|
+
console.log(`${LOG} re-planning with the attached secrets`);
|
|
550
|
+
return enqueueAndWaitForPlan(request);
|
|
551
|
+
}
|
|
552
|
+
return response;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Attach what `reconcileStageCredentials` can for the stages this plan covered
|
|
556
|
+
* (never other stages registered in the repo, e.g. from other branches); true
|
|
557
|
+
* when anything was attached.
|
|
558
|
+
*/
|
|
559
|
+
async function attachUnattachedCredentials({ request, stageIds, }) {
|
|
560
|
+
if (stageIds.length === 0)
|
|
561
|
+
return false;
|
|
562
|
+
try {
|
|
563
|
+
const client = { baseUrl: request.baseUrl, token: request.token };
|
|
564
|
+
const { secrets } = await getJson({ ...client, path: '/api/managed-secrets' });
|
|
565
|
+
const result = await reconcileStageCredentials({
|
|
566
|
+
client,
|
|
567
|
+
repo: request.repo,
|
|
568
|
+
stageIds,
|
|
569
|
+
deployTarget: request.environment,
|
|
570
|
+
secrets,
|
|
571
|
+
});
|
|
572
|
+
printReconcileResult({ result, deployTarget: request.environment });
|
|
573
|
+
return result.attached.length > 0;
|
|
574
|
+
}
|
|
575
|
+
catch (reconcileError) {
|
|
576
|
+
// Never mask the plan's own outcome with why this follow-up couldn't run.
|
|
577
|
+
console.error(`${LOG} could not check stage credentials: ${reconcileError instanceof Error ? reconcileError.message : String(reconcileError)}`);
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
/** The planner itself rejected the plan (as opposed to a timeout or transport error). */
|
|
582
|
+
class PlanRequestFailedError extends Error {
|
|
583
|
+
stageIds;
|
|
584
|
+
name = 'PlanRequestFailedError';
|
|
585
|
+
constructor(message,
|
|
586
|
+
/** Stages the failed plan registered (recorded when it failed on a missing credential). */
|
|
587
|
+
stageIds) {
|
|
588
|
+
super(message);
|
|
589
|
+
this.stageIds = stageIds;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
async function enqueueAndWaitForPlan({ baseUrl, token, repo, ref, environment, migrationId, executionMode, }) {
|
|
516
593
|
const enqueue = await postJson({
|
|
517
594
|
baseUrl,
|
|
518
595
|
token,
|
|
519
596
|
path: '/api/data-pipelines/pipelines/plan',
|
|
520
|
-
body: { repo, ref, environment, ...(migrationId ? { migration_id: migrationId } : {}) },
|
|
597
|
+
body: { repo, ref, environment, ...(migrationId ? { migration_id: migrationId } : {}), ...(executionMode ? { execution_mode: executionMode } : {}) },
|
|
521
598
|
});
|
|
522
599
|
console.log(`${LOG} enqueued plan ${enqueue.planRequestId} (trigger=${enqueue.triggerRunId ?? 'n/a'})`);
|
|
523
600
|
const detail = await waitForPlanRequest({
|
|
@@ -551,8 +628,8 @@ async function waitForPlanRequest({ baseUrl, token, planRequestId, }) {
|
|
|
551
628
|
? `${detail.status} — ${detail.statusDetail}`
|
|
552
629
|
: detail.status;
|
|
553
630
|
if (detail.status === 'failed') {
|
|
554
|
-
throw new
|
|
555
|
-
`${detail.statusDetail ?? 'unknown error'}
|
|
631
|
+
throw new PlanRequestFailedError(`plan request ${detail.planRequestId} failed after ${formatElapsed(elapsed)}: ` +
|
|
632
|
+
`${detail.statusDetail ?? 'unknown error'}`, detail.stageIds ?? []);
|
|
556
633
|
}
|
|
557
634
|
if (detail.status === 'succeeded')
|
|
558
635
|
return detail;
|
|
@@ -578,7 +655,7 @@ export async function pipelineAdoptCommand(args) {
|
|
|
578
655
|
if (!stage || !ref || !nativeId || !approvedBy) {
|
|
579
656
|
console.error('usage: seq-studio pipeline adopt --stage <slug> --ref <sha|branch> -e <env> ' +
|
|
580
657
|
'--native-id <id> --approved-by <you> [--resource-key <key>] [--kind job|dlt_pipeline] ' +
|
|
581
|
-
'[--old-source-removal-pr <url>] [--repo
|
|
658
|
+
'[--old-source-removal-pr <url>] [--repo <namespace>/<slug>] [--json]');
|
|
582
659
|
return 1;
|
|
583
660
|
}
|
|
584
661
|
const { env, token } = await envAndToken(args);
|
|
@@ -642,7 +719,7 @@ export async function pipelineUnbindCommand(args) {
|
|
|
642
719
|
const approvedBy = flagString(args.flags, 'approved-by');
|
|
643
720
|
if (!stage || !ref || !approvedBy) {
|
|
644
721
|
console.error('usage: seq-studio pipeline unbind --stage <slug> --ref <sha|branch> -e <env> ' +
|
|
645
|
-
'--approved-by <you> [--resource-key <key>] [--repo
|
|
722
|
+
'--approved-by <you> [--resource-key <key>] [--repo <namespace>/<slug>] [--json]');
|
|
646
723
|
return 1;
|
|
647
724
|
}
|
|
648
725
|
const { env, token } = await envAndToken(args);
|
|
@@ -695,7 +772,7 @@ export async function pipelineUnbindCommand(args) {
|
|
|
695
772
|
}
|
|
696
773
|
/**
|
|
697
774
|
* Stage identity is `(repo, slug)` — a bare slug can be ambiguous across
|
|
698
|
-
* Pipelines. `--repo
|
|
775
|
+
* Pipelines. `--repo <namespace>/<slug>` scopes the lookup server-side; an
|
|
699
776
|
* ambiguous bare slug fails with the candidate repos rather than guessing.
|
|
700
777
|
*
|
|
701
778
|
* The `slug` query param is an EXACT server-side filter (contracts.ts
|
|
@@ -720,7 +797,7 @@ async function resolveStageIdBySlug({ baseUrl, token, slug, repo, }) {
|
|
|
720
797
|
}
|
|
721
798
|
if (listed.stages.length > 1) {
|
|
722
799
|
throw new Error(`stage '${slug}' exists in multiple Pipelines (${listed.stages.map((m) => m.repo).join(', ')}) — ` +
|
|
723
|
-
'disambiguate with --repo
|
|
800
|
+
'disambiguate with --repo <namespace>/<slug>');
|
|
724
801
|
}
|
|
725
802
|
return first.id;
|
|
726
803
|
}
|
|
@@ -6,6 +6,7 @@ const USAGE = 'usage: seq-studio pipeline migrate <status|start|resume|cancel> -
|
|
|
6
6
|
function printStatus(detail) {
|
|
7
7
|
console.log(`${LOG} migration ${detail.migrationId} (${detail.runId}): ${detail.status}`);
|
|
8
8
|
console.log(`${LOG} ${detail.repo} → ${detail.environment}`);
|
|
9
|
+
console.log(`${LOG} mode: ${detail.executionMode === 'in_place' ? 'in-place' : 'temporary copies'}`);
|
|
9
10
|
if (detail.statusDetail)
|
|
10
11
|
console.log(`${LOG} ${detail.statusDetail}`);
|
|
11
12
|
for (const phase of detail.phases)
|
|
@@ -18,9 +19,13 @@ function printStatus(detail) {
|
|
|
18
19
|
if (detail.cancelRequested && !['cancelled', 'succeeded'].includes(detail.status))
|
|
19
20
|
console.log(`${LOG} cancellation requested; the worker stops at a safe checkpoint`);
|
|
20
21
|
if (detail.status === 'recovery_required')
|
|
21
|
-
console.log(`${LOG} ${detail.publicationStarted ? '
|
|
22
|
+
console.log(`${LOG} ${detail.publicationStarted ? 'live data changes have begun; ' : ''}resource reservations are retained for recovery`);
|
|
22
23
|
}
|
|
23
24
|
export async function runPipelineMigrationCommand(args) {
|
|
25
|
+
if (args.flags['in-place'] !== undefined || args.flags['skip-copy'] !== undefined) {
|
|
26
|
+
console.error(`${LOG} execution mode is fixed by the approved plan; choose --in-place during pipeline plan`);
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
24
29
|
const runId = args.flags['run-id'];
|
|
25
30
|
const action = args.positional[0];
|
|
26
31
|
const planHash = args.flags['plan-hash'];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
interface ClientOptions {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
token: string;
|
|
4
|
+
}
|
|
5
|
+
export interface StageRef {
|
|
6
|
+
id: string;
|
|
7
|
+
slug: string;
|
|
8
|
+
repo: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AttachableSecret {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
orgId: string;
|
|
14
|
+
currentUserAccess: string | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A declared source credential with nothing attached on the target: either
|
|
18
|
+
* unresolved, or resolved the legacy way on a stage never deployed there (a
|
|
19
|
+
* new stage, whose \`get_credential\` needs an attachment to work).
|
|
20
|
+
*/
|
|
21
|
+
export interface MissingStageCredential {
|
|
22
|
+
stage: StageRef;
|
|
23
|
+
symbolic: string;
|
|
24
|
+
/** Convention name (`abrigo_oauth` → `ABRIGO_OAUTH`), from the stage detail. */
|
|
25
|
+
managedSecretName: string;
|
|
26
|
+
/** The target's secret org (what the legacy lookup reads), when it has one. */
|
|
27
|
+
secretOrgId: string | null;
|
|
28
|
+
}
|
|
29
|
+
/** The credential name a secret binds to when none is given: `ABRIGO_OAUTH` → `abrigo_oauth`. */
|
|
30
|
+
export declare function symbolicForSecretName(name: string): string;
|
|
31
|
+
export declare function resolveStage({ client, slug, repo, }: {
|
|
32
|
+
client: ClientOptions;
|
|
33
|
+
slug: string;
|
|
34
|
+
repo?: string;
|
|
35
|
+
}): Promise<StageRef>;
|
|
36
|
+
export declare function attachSecretToStage({ client, stageId, deployTarget, symbolic, secretId, }: {
|
|
37
|
+
client: ClientOptions;
|
|
38
|
+
stageId: string;
|
|
39
|
+
deployTarget: string;
|
|
40
|
+
symbolic: string;
|
|
41
|
+
secretId: string;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
export interface StageBinding {
|
|
44
|
+
deployTarget: string;
|
|
45
|
+
symbolic: string;
|
|
46
|
+
secretId: string;
|
|
47
|
+
secretName: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function listStageBindings({ client, stageId }: {
|
|
50
|
+
client: ClientOptions;
|
|
51
|
+
stageId: string;
|
|
52
|
+
}): Promise<StageBinding[]>;
|
|
53
|
+
export declare function detachSecretFromStage({ client, stageId, deployTarget, symbolic, }: {
|
|
54
|
+
client: ClientOptions;
|
|
55
|
+
stageId: string;
|
|
56
|
+
deployTarget: string;
|
|
57
|
+
symbolic: string;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Source credentials the CLI should attach on `deployTarget`, across a repo's
|
|
61
|
+
* stages (see `needsAttachment`). The stage detail reads the most recently
|
|
62
|
+
* planned spec, so right after a plan these match what it just planned.
|
|
63
|
+
*/
|
|
64
|
+
export declare function findMissingStageCredentials({ client, repo, stageIds, deployTarget, }: {
|
|
65
|
+
client: ClientOptions;
|
|
66
|
+
repo: string;
|
|
67
|
+
/** Only these stages — the ones the plan covered. */
|
|
68
|
+
stageIds: readonly string[];
|
|
69
|
+
deployTarget: string;
|
|
70
|
+
}): Promise<MissingStageCredential[]>;
|
|
71
|
+
export interface ReconcileResult {
|
|
72
|
+
attached: MissingStageCredential[];
|
|
73
|
+
unresolved: Array<MissingStageCredential & {
|
|
74
|
+
reason: string;
|
|
75
|
+
}>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Attach, as the caller, the managed secret named by convention for each
|
|
79
|
+
* missing credential — what `functions deploy` does for a manifest's secrets.
|
|
80
|
+
* Never creates secrets or writes values; a missing, ambiguous or
|
|
81
|
+
* non-editable secret is reported with how to fix it.
|
|
82
|
+
*/
|
|
83
|
+
export declare function reconcileStageCredentials({ client, repo, stageIds, deployTarget, secrets, }: {
|
|
84
|
+
client: ClientOptions;
|
|
85
|
+
repo: string;
|
|
86
|
+
stageIds: readonly string[];
|
|
87
|
+
deployTarget: string;
|
|
88
|
+
/** The caller's visible secrets (`GET /api/managed-secrets`). */
|
|
89
|
+
secrets: readonly AttachableSecret[];
|
|
90
|
+
}): Promise<ReconcileResult>;
|
|
91
|
+
export declare function printReconcileResult({ result, deployTarget }: {
|
|
92
|
+
result: ReconcileResult;
|
|
93
|
+
deployTarget: string;
|
|
94
|
+
}): void;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { deleteJson, getJson, postJson } from '../atlas-client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Managed secrets attached to Managed Pipelines stages — the pipelines side of
|
|
4
|
+
* `seq-studio secrets attach --fn`. A stage declares `source.credential:
|
|
5
|
+
* <symbolic>` in its spec; an attachment binds that credential, for one deploy
|
|
6
|
+
* target, to a managed secret. Deploy copies the secret's version into the
|
|
7
|
+
* stage's Databricks scope and the job reads it with
|
|
8
|
+
* `pipeline_runtime.get_credential("<symbolic>")`.
|
|
9
|
+
*
|
|
10
|
+
* Attaching is the permission check (editor on the secret, run as the caller),
|
|
11
|
+
* exactly as for functions. Nothing here reads or prints a secret value.
|
|
12
|
+
*/
|
|
13
|
+
const LOG = '[seq-studio]';
|
|
14
|
+
const EDIT_ACCESS = new Set(['editor', 'admin', 'owner']);
|
|
15
|
+
/** The credential name a secret binds to when none is given: `ABRIGO_OAUTH` → `abrigo_oauth`. */
|
|
16
|
+
export function symbolicForSecretName(name) {
|
|
17
|
+
return name.toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
export async function resolveStage({ client, slug, repo, }) {
|
|
20
|
+
const params = new URLSearchParams({ slug, limit: '10' });
|
|
21
|
+
if (repo)
|
|
22
|
+
params.set('repo', repo);
|
|
23
|
+
const { stages } = await getJson({
|
|
24
|
+
...client,
|
|
25
|
+
path: `/api/data-pipelines/stages?${params}`,
|
|
26
|
+
});
|
|
27
|
+
if (stages.length === 0) {
|
|
28
|
+
throw new Error(`pipeline stage "${slug}"${repo ? ` in ${repo}` : ''} not found. A stage is registered by its first ` +
|
|
29
|
+
'`seq-studio pipeline plan`, even one that fails for a missing credential.');
|
|
30
|
+
}
|
|
31
|
+
if (stages.length > 1) {
|
|
32
|
+
const repos = stages.map((stage) => stage.repo).join(', ');
|
|
33
|
+
throw new Error(`pipeline stage "${slug}" exists in several repos (${repos}). Pass --repo <namespace>/<slug>.`);
|
|
34
|
+
}
|
|
35
|
+
return stages[0];
|
|
36
|
+
}
|
|
37
|
+
export async function attachSecretToStage({ client, stageId, deployTarget, symbolic, secretId, }) {
|
|
38
|
+
await postJson({
|
|
39
|
+
...client,
|
|
40
|
+
path: `/api/data-pipelines/stages/${encodeURIComponent(stageId)}/secret-bindings`,
|
|
41
|
+
body: { deployTarget, symbolic, secretId },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export async function listStageBindings({ client, stageId }) {
|
|
45
|
+
const { bindings } = await getJson({
|
|
46
|
+
...client,
|
|
47
|
+
path: `/api/data-pipelines/stages/${encodeURIComponent(stageId)}/secret-bindings`,
|
|
48
|
+
});
|
|
49
|
+
return bindings;
|
|
50
|
+
}
|
|
51
|
+
export async function detachSecretFromStage({ client, stageId, deployTarget, symbolic, }) {
|
|
52
|
+
const params = new URLSearchParams({ deployTarget, symbolic });
|
|
53
|
+
await deleteJson({
|
|
54
|
+
...client,
|
|
55
|
+
path: `/api/data-pipelines/stages/${encodeURIComponent(stageId)}/secret-bindings?${params}`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** Only ingestion stages declare source credentials. */
|
|
59
|
+
async function listRepoIngestionStages({ client, repo }) {
|
|
60
|
+
const out = [];
|
|
61
|
+
const limit = 200;
|
|
62
|
+
for (let offset = 0;; offset += limit) {
|
|
63
|
+
const params = new URLSearchParams({ repo, type: 'ingestion', limit: String(limit), offset: String(offset) });
|
|
64
|
+
const page = await getJson({
|
|
65
|
+
...client,
|
|
66
|
+
path: `/api/data-pipelines/stages?${params}`,
|
|
67
|
+
});
|
|
68
|
+
out.push(...page.stages);
|
|
69
|
+
if (page.stages.length === 0 || out.length >= page.pagination.total)
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Whether the CLI should attach this credential: nothing resolves it, or only
|
|
75
|
+
* the legacy name lookup does on a stage never deployed to the target. A
|
|
76
|
+
* deployed legacy stage is left alone — moving it is a deliberate migration.
|
|
77
|
+
*/
|
|
78
|
+
function needsAttachment({ bindingSource, deployedOnTarget, }) {
|
|
79
|
+
if (bindingSource === 'missing')
|
|
80
|
+
return true;
|
|
81
|
+
return (bindingSource === 'registry' || bindingSource === 'env') && !deployedOnTarget;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Source credentials the CLI should attach on `deployTarget`, across a repo's
|
|
85
|
+
* stages (see `needsAttachment`). The stage detail reads the most recently
|
|
86
|
+
* planned spec, so right after a plan these match what it just planned.
|
|
87
|
+
*/
|
|
88
|
+
export async function findMissingStageCredentials({ client, repo, stageIds, deployTarget, }) {
|
|
89
|
+
const missing = [];
|
|
90
|
+
const planned = new Set(stageIds);
|
|
91
|
+
const stages = (await listRepoIngestionStages({ client, repo })).filter((stage) => planned.has(stage.id));
|
|
92
|
+
for (const stage of stages) {
|
|
93
|
+
const detail = await getJson({
|
|
94
|
+
...client,
|
|
95
|
+
path: `/api/data-pipelines/stages/${encodeURIComponent(stage.id)}`,
|
|
96
|
+
});
|
|
97
|
+
const statuses = detail.credentials.byEnvironment.find((entry) => entry.environment === deployTarget);
|
|
98
|
+
const deployedOnTarget = detail.environments.some((entry) => entry.environment === deployTarget && entry.activeDurable !== null);
|
|
99
|
+
for (const requirement of detail.credentials.requirements) {
|
|
100
|
+
if (!requirement.roles.includes('source'))
|
|
101
|
+
continue;
|
|
102
|
+
const status = statuses?.credentials.find((credential) => credential.symbolic === requirement.symbolic);
|
|
103
|
+
if (!needsAttachment({ bindingSource: status?.bindingSource, deployedOnTarget }))
|
|
104
|
+
continue;
|
|
105
|
+
missing.push({
|
|
106
|
+
stage,
|
|
107
|
+
symbolic: requirement.symbolic,
|
|
108
|
+
managedSecretName: requirement.managedSecretName,
|
|
109
|
+
secretOrgId: statuses?.secretOrgId ?? null,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return missing;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Attach, as the caller, the managed secret named by convention for each
|
|
117
|
+
* missing credential — what `functions deploy` does for a manifest's secrets.
|
|
118
|
+
* Never creates secrets or writes values; a missing, ambiguous or
|
|
119
|
+
* non-editable secret is reported with how to fix it.
|
|
120
|
+
*/
|
|
121
|
+
export async function reconcileStageCredentials({ client, repo, stageIds, deployTarget, secrets, }) {
|
|
122
|
+
const result = { attached: [], unresolved: [] };
|
|
123
|
+
for (const credential of await findMissingStageCredentials({ client, repo, stageIds, deployTarget })) {
|
|
124
|
+
// Only the target's own org, as the legacy lookup does; picking another
|
|
125
|
+
// org's same-named secret stays an explicit `secrets attach --org`.
|
|
126
|
+
const named = secrets.filter((secret) => secret.name === credential.managedSecretName);
|
|
127
|
+
const matches = credential.secretOrgId ? named.filter((secret) => secret.orgId === credential.secretOrgId) : named;
|
|
128
|
+
if (matches.length !== 1) {
|
|
129
|
+
result.unresolved.push({ ...credential, reason: unresolvedReason({ credential, named, matches }) });
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const [secret] = matches;
|
|
133
|
+
if (!secret || !EDIT_ACCESS.has(secret.currentUserAccess ?? '')) {
|
|
134
|
+
result.unresolved.push({ ...credential, reason: `you are not an editor on ${credential.managedSecretName}` });
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
await attachSecretToStage({
|
|
138
|
+
client,
|
|
139
|
+
stageId: credential.stage.id,
|
|
140
|
+
deployTarget,
|
|
141
|
+
symbolic: credential.symbolic,
|
|
142
|
+
secretId: secret.id,
|
|
143
|
+
});
|
|
144
|
+
result.attached.push(credential);
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
function unresolvedReason({ credential, named, matches, }) {
|
|
149
|
+
const name = credential.managedSecretName;
|
|
150
|
+
if (matches.length > 1)
|
|
151
|
+
return `${name} exists in several orgs (${matches.map((m) => m.orgId).join(', ')})`;
|
|
152
|
+
if (named.length > 0) {
|
|
153
|
+
return `no ${name} in org ${credential.secretOrgId} (found in ${named.map((m) => m.orgId).join(', ')}; attach it explicitly with --org)`;
|
|
154
|
+
}
|
|
155
|
+
return `no managed secret named ${name} that you can see`;
|
|
156
|
+
}
|
|
157
|
+
export function printReconcileResult({ result, deployTarget }) {
|
|
158
|
+
for (const { stage, symbolic, managedSecretName } of result.attached) {
|
|
159
|
+
console.log(`${LOG} attached ${managedSecretName} to ${stage.slug} (${symbolic}) for ${deployTarget}`);
|
|
160
|
+
}
|
|
161
|
+
for (const { stage, symbolic, managedSecretName, reason } of result.unresolved) {
|
|
162
|
+
console.error(`${LOG} ${stage.slug}: credential ${symbolic} has nothing attached for ${deployTarget} — ${reason}. ` +
|
|
163
|
+
`Create it (seq-studio secrets create ${managedSecretName}, then secrets set), or attach another: ` +
|
|
164
|
+
`seq-studio secrets attach <NAME> --stage ${stage.slug} --credential ${symbolic} --target ${deployTarget}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -8,4 +8,4 @@ export declare const STAGE_TYPES: readonly ["ingestion", "transformation", "serv
|
|
|
8
8
|
export type StageTemplateType = (typeof STAGE_TYPES)[number];
|
|
9
9
|
export declare function renderStageTemplate(name: string, type: StageTemplateType): string;
|
|
10
10
|
/** Serving stages are declarative — no entrypoint stub. */
|
|
11
|
-
export declare function renderEntrypointStub(name: string): string;
|
|
11
|
+
export declare function renderEntrypointStub(name: string, type?: Exclude<StageTemplateType, 'serving'>): string;
|