@geekmidas/cli 10.0.0-alpha.97 → 10.0.0-alpha.99
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/dist/{GoDaddyProvider-AqNu60WQ.mjs → GoDaddyProvider-206NguW1.mjs} +2 -2
- package/dist/{GoDaddyProvider-AqNu60WQ.mjs.map → GoDaddyProvider-206NguW1.mjs.map} +1 -1
- package/dist/{GoDaddyProvider-B4R_QFl8.cjs → GoDaddyProvider-D1aQy2i1.cjs} +2 -2
- package/dist/{GoDaddyProvider-B4R_QFl8.cjs.map → GoDaddyProvider-D1aQy2i1.cjs.map} +1 -1
- package/dist/{LegacyStateStore-B-aRqRdD.cjs → LegacyStateStore-CgJEr1G7.cjs} +3 -3
- package/dist/{LegacyStateStore-B-aRqRdD.cjs.map → LegacyStateStore-CgJEr1G7.cjs.map} +1 -1
- package/dist/{LegacyStateStore-8F05-BOo.mjs → LegacyStateStore-wmFfdzuh.mjs} +3 -3
- package/dist/{LegacyStateStore-8F05-BOo.mjs.map → LegacyStateStore-wmFfdzuh.mjs.map} +1 -1
- package/dist/{LocalStateStore-B_bRI8M7.cjs → LocalStateStore-BD14kra9.cjs} +2 -2
- package/dist/{LocalStateStore-B_bRI8M7.cjs.map → LocalStateStore-BD14kra9.cjs.map} +1 -1
- package/dist/{LocalStateStore-B_mfgcO8.mjs → LocalStateStore-C5mNp91D.mjs} +2 -2
- package/dist/{LocalStateStore-B_mfgcO8.mjs.map → LocalStateStore-C5mNp91D.mjs.map} +1 -1
- package/dist/{S3StateStore-CMN0Uzdp.mjs → S3StateStore-CEGbsDHi.mjs} +10 -9
- package/dist/S3StateStore-CEGbsDHi.mjs.map +1 -0
- package/dist/{S3StateStore-zK9zcd9f.cjs → S3StateStore-Csu_kJCy.cjs} +11 -10
- package/dist/S3StateStore-Csu_kJCy.cjs.map +1 -0
- package/dist/{SSMStateStore-Cv7VcMak.mjs → SSMStateStore-Bd62qwp4.mjs} +2 -2
- package/dist/{SSMStateStore-Cv7VcMak.mjs.map → SSMStateStore-Bd62qwp4.mjs.map} +1 -1
- package/dist/{SSMStateStore-C489DnR6.cjs → SSMStateStore-Rp21jtP5.cjs} +2 -2
- package/dist/{SSMStateStore-C489DnR6.cjs.map → SSMStateStore-Rp21jtP5.cjs.map} +1 -1
- package/dist/{add-BA5d4pA0.mjs → add-DyIEYI97.mjs} +4 -4
- package/dist/{add-BA5d4pA0.mjs.map → add-DyIEYI97.mjs.map} +1 -1
- package/dist/{add-HXzTCy_I.cjs → add-Iuo3ao5E.cjs} +5 -5
- package/dist/{add-HXzTCy_I.cjs.map → add-Iuo3ao5E.cjs.map} +1 -1
- package/dist/{aws-Dz2bYxK1.mjs → aws-8QQ8n-t6.mjs} +2 -2
- package/dist/{aws-Dz2bYxK1.mjs.map → aws-8QQ8n-t6.mjs.map} +1 -1
- package/dist/{aws-BTReGjpY.cjs → aws-DY9NqQIT.cjs} +2 -2
- package/dist/{aws-BTReGjpY.cjs.map → aws-DY9NqQIT.cjs.map} +1 -1
- package/dist/{awsStore-BWa1KNY-.mjs → awsStore-Bx5nCFnS.mjs} +8 -6
- package/dist/awsStore-Bx5nCFnS.mjs.map +1 -0
- package/dist/{awsStore-B5We7bMg.cjs → awsStore-u3ehhMoY.cjs} +8 -6
- package/dist/awsStore-u3ehhMoY.cjs.map +1 -0
- package/dist/{bundler-SX3Uy8qT.cjs → bundler-Bgoq8IyR.cjs} +5 -5
- package/dist/{bundler-SX3Uy8qT.cjs.map → bundler-Bgoq8IyR.cjs.map} +1 -1
- package/dist/{bundler-CBomFsnd.mjs → bundler-Q6Kp8b0r.mjs} +5 -5
- package/dist/{bundler-CBomFsnd.mjs.map → bundler-Q6Kp8b0r.mjs.map} +1 -1
- package/dist/{cli-D7z1lQtO.mjs → cli-B9BudUV0.mjs} +2 -4
- package/dist/cli-B9BudUV0.mjs.map +1 -0
- package/dist/{cli-1l0L9LCA.cjs → cli-W2DMRIbP.cjs} +2 -4
- package/dist/cli-W2DMRIbP.cjs.map +1 -0
- package/dist/compose-CIrFNWHb.cjs +3147 -0
- package/dist/compose-CIrFNWHb.cjs.map +1 -0
- package/dist/compose-CLsRcHkA.mjs +3052 -0
- package/dist/compose-CLsRcHkA.mjs.map +1 -0
- package/dist/{config-xIWIaDhW.d.cts → config-BVdHfj8b.d.cts} +4 -4
- package/dist/{config-D-k0gaAr.d.mts.map → config-BVdHfj8b.d.cts.map} +1 -1
- package/dist/{config-D-k0gaAr.d.mts → config-D2OqCmAM.d.mts} +4 -4
- package/dist/{config-xIWIaDhW.d.cts.map → config-D2OqCmAM.d.mts.map} +1 -1
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +3 -3
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs +1 -1
- package/dist/deploy/public.cjs +9 -8
- package/dist/deploy/public.cjs.map +1 -1
- package/dist/deploy/public.d.cts +5 -16
- package/dist/deploy/public.d.cts.map +1 -1
- package/dist/deploy/public.d.mts +5 -16
- package/dist/deploy/public.d.mts.map +1 -1
- package/dist/deploy/public.mjs +8 -7
- package/dist/deploy/public.mjs.map +1 -1
- package/dist/{deploy-Cu_HyWoJ.cjs → deploy-CbJMJsgX.cjs} +26 -62
- package/dist/deploy-CbJMJsgX.cjs.map +1 -0
- package/dist/{deploy-LY-20Yeb.mjs → deploy-n_IB8r6H.mjs} +17 -59
- package/dist/deploy-n_IB8r6H.mjs.map +1 -0
- package/dist/{discover-CbJCQq4J.d.mts → discover-Caf6Hnv1.d.cts} +2 -2
- package/dist/{discover-CbJCQq4J.d.mts.map → discover-Caf6Hnv1.d.cts.map} +1 -1
- package/dist/{discover-RCW5mBXb.d.cts → discover-Cd5M2jPv.d.mts} +2 -2
- package/dist/{discover-RCW5mBXb.d.cts.map → discover-Cd5M2jPv.d.mts.map} +1 -1
- package/dist/{dns-BbTOzmVp.mjs → dns-C_LPS3qV.mjs} +3 -3
- package/dist/{dns-BbTOzmVp.mjs.map → dns-C_LPS3qV.mjs.map} +1 -1
- package/dist/{dns-BFnoawgh.cjs → dns-kp8To8Qj.cjs} +3 -3
- package/dist/{dns-BFnoawgh.cjs.map → dns-kp8To8Qj.cjs.map} +1 -1
- package/dist/{dokploy-LR94sBVI.mjs → dokploy-Dl_kNVeE.mjs} +2 -2
- package/dist/{dokploy-LR94sBVI.mjs.map → dokploy-Dl_kNVeE.mjs.map} +1 -1
- package/dist/{dokploy-CKgSww82.cjs → dokploy-gRIae9Ht.cjs} +2 -2
- package/dist/{dokploy-CKgSww82.cjs.map → dokploy-gRIae9Ht.cjs.map} +1 -1
- package/dist/{encryption-C0plOf4a.mjs → encryption-C3DcVZQs.mjs} +3 -3
- package/dist/{encryption-C0plOf4a.mjs.map → encryption-C3DcVZQs.mjs.map} +1 -1
- package/dist/{encryption-CUyw-8sc.cjs → encryption-CmQvQOSe.cjs} +3 -3
- package/dist/{encryption-CUyw-8sc.cjs.map → encryption-CmQvQOSe.cjs.map} +1 -1
- package/dist/{engine-DqbqQhck.mjs → engine-DBXuhHyf.mjs} +5 -4
- package/dist/{engine-DqbqQhck.mjs.map → engine-DBXuhHyf.mjs.map} +1 -1
- package/dist/{engine-D8TeraDK.cjs → engine-Dk19Mxc4.cjs} +27 -26
- package/dist/{engine-D8TeraDK.cjs.map → engine-Dk19Mxc4.cjs.map} +1 -1
- package/dist/{github-DC4SIqV1.cjs → github-Ds2RYnSU.cjs} +43 -20
- package/dist/github-Ds2RYnSU.cjs.map +1 -0
- package/dist/{github-zgaBOQvh.mjs → github-RawRLERq.mjs} +42 -19
- package/dist/github-RawRLERq.mjs.map +1 -0
- package/dist/identity-CBXr4wNi.mjs +129 -0
- package/dist/identity-CBXr4wNi.mjs.map +1 -0
- package/dist/identity-CbLfgQNT.cjs +182 -0
- package/dist/identity-CbLfgQNT.cjs.map +1 -0
- package/dist/{index-ClqOsbBl.d.mts → index-BU4G20G6.d.cts} +2 -2
- package/dist/{index-ClqOsbBl.d.mts.map → index-BU4G20G6.d.cts.map} +1 -1
- package/dist/{index-DgOBAEl5.d.cts → index-yDbd1WcM.d.mts} +2 -2
- package/dist/{index-DgOBAEl5.d.cts.map → index-yDbd1WcM.d.mts.map} +1 -1
- package/dist/index.cjs +156 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +153 -148
- package/dist/index.mjs.map +1 -1
- package/dist/{migrate-BJ8aLOWk.mjs → migrate-CZIGT3kB.mjs} +3 -3
- package/dist/{migrate-BJ8aLOWk.mjs.map → migrate-CZIGT3kB.mjs.map} +1 -1
- package/dist/migrate-CxZYzF_u.cjs +181 -0
- package/dist/migrate-CxZYzF_u.cjs.map +1 -0
- package/dist/migrate-DR1x96I4.mjs +181 -0
- package/dist/migrate-DR1x96I4.mjs.map +1 -0
- package/dist/{migrate-CWq8-s21.cjs → migrate-DjrTwWJA.cjs} +3 -3
- package/dist/{migrate-CWq8-s21.cjs.map → migrate-DjrTwWJA.cjs.map} +1 -1
- package/dist/openapi.cjs +1 -1
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.mjs +1 -1
- package/dist/{projectBucket-BFp-SFee.mjs → projectBucket-BYOxRnHY.mjs} +2 -2
- package/dist/{projectBucket-BFp-SFee.mjs.map → projectBucket-BYOxRnHY.mjs.map} +1 -1
- package/dist/{projectBucket-Cho9DpSh.cjs → projectBucket-CDu5rXjp.cjs} +2 -2
- package/dist/{projectBucket-Cho9DpSh.cjs.map → projectBucket-CDu5rXjp.cjs.map} +1 -1
- package/dist/reconcile/public.d.cts +2 -2
- package/dist/reconcile/public.d.mts +2 -2
- package/dist/{resolve-6EYNqYdr.mjs → resolve-CNYbGH8g.mjs} +3 -3
- package/dist/{resolve-6EYNqYdr.mjs.map → resolve-CNYbGH8g.mjs.map} +1 -1
- package/dist/{resolve-C8VkR4oW.cjs → resolve-DC98Rl1t.cjs} +3 -3
- package/dist/{resolve-C8VkR4oW.cjs.map → resolve-DC98Rl1t.cjs.map} +1 -1
- package/dist/{rollback-BsThTeSN.mjs → rollback-BkIkE8Qe.mjs} +5 -5
- package/dist/{rollback-BsThTeSN.mjs.map → rollback-BkIkE8Qe.mjs.map} +1 -1
- package/dist/{rollback-CvGfm4DX.cjs → rollback-DBfLvC8k.cjs} +5 -5
- package/dist/{rollback-CvGfm4DX.cjs.map → rollback-DBfLvC8k.cjs.map} +1 -1
- package/dist/{runtime-CaW4QqF2.d.cts → runtime-CLz3bf07.d.mts} +2 -2
- package/dist/{runtime-CaW4QqF2.d.cts.map → runtime-CLz3bf07.d.mts.map} +1 -1
- package/dist/{runtime-K5uxp6HE.d.mts → runtime-CUWf0IUk.d.cts} +2 -2
- package/dist/{runtime-K5uxp6HE.d.mts.map → runtime-CUWf0IUk.d.cts.map} +1 -1
- package/dist/s3-BwhQk3QM.mjs +215 -0
- package/dist/s3-BwhQk3QM.mjs.map +1 -0
- package/dist/s3-DLp0V-Ox.cjs +215 -0
- package/dist/s3-DLp0V-Ox.cjs.map +1 -0
- package/dist/{sandbox-D8cfZUAA.d.cts → sandbox-CfpLWTPP.d.mts} +2 -2
- package/dist/{sandbox-B_BkfmTP.d.mts.map → sandbox-CfpLWTPP.d.mts.map} +1 -1
- package/dist/{sandbox-B_BkfmTP.d.mts → sandbox-D1XeNEJ9.d.cts} +2 -2
- package/dist/{sandbox-D8cfZUAA.d.cts.map → sandbox-D1XeNEJ9.d.cts.map} +1 -1
- package/dist/{secretsManager-C6wm-9uZ.mjs → secretsManager-CQORubp9.mjs} +2 -2
- package/dist/{secretsManager-C6wm-9uZ.mjs.map → secretsManager-CQORubp9.mjs.map} +1 -1
- package/dist/{secretsManager-Cwwgs81g.cjs → secretsManager-RAGcEDX1.cjs} +2 -2
- package/dist/{secretsManager-Cwwgs81g.cjs.map → secretsManager-RAGcEDX1.cjs.map} +1 -1
- package/dist/{seeds-BQlj9Fsg.cjs → seeds-BNHSpjNP.cjs} +22 -166
- package/dist/seeds-BNHSpjNP.cjs.map +1 -0
- package/dist/{seeds-BsJRUL1K.mjs → seeds-C4bZ8L-T.mjs} +23 -119
- package/dist/seeds-C4bZ8L-T.mjs.map +1 -0
- package/dist/{sniffer-DVsvP8s-.mjs → sniffer-BIBm9dAb.mjs} +7 -7
- package/dist/{sniffer-DVsvP8s-.mjs.map → sniffer-BIBm9dAb.mjs.map} +1 -1
- package/dist/{sniffer-CeUKUoHn.cjs → sniffer-Cylp9W2D.cjs} +7 -7
- package/dist/{sniffer-CeUKUoHn.cjs.map → sniffer-Cylp9W2D.cjs.map} +1 -1
- package/dist/{stages-DEmn7qI8.mjs → stages-CcS9vnNu.mjs} +5 -18
- package/dist/stages-CcS9vnNu.mjs.map +1 -0
- package/dist/{stages-BpDXFPGg.cjs → stages-DdBV7msu.cjs} +5 -18
- package/dist/stages-DdBV7msu.cjs.map +1 -0
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.d.cts +2 -2
- package/dist/target/public.d.mts +2 -2
- package/dist/target/public.mjs +1 -1
- package/dist/{types-4vPS_YFX.d.cts → types-BhThob0H.d.mts} +90 -21
- package/dist/types-BhThob0H.d.mts.map +1 -0
- package/dist/{types-CFsEyFb1.d.mts → types-DwoLHelT.d.cts} +91 -20
- package/dist/types-DwoLHelT.d.cts.map +1 -0
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.d.cts +2 -2
- package/dist/workspace/index.d.mts +2 -2
- package/dist/workspace/index.mjs +1 -1
- package/dist/{workspace-Bv4xROeu.mjs → workspace-D5CpOp1y.mjs} +77 -5
- package/dist/workspace-D5CpOp1y.mjs.map +1 -0
- package/dist/{workspace-C1M-S4al.cjs → workspace-DRjdu1OY.cjs} +88 -4
- package/dist/workspace-DRjdu1OY.cjs.map +1 -0
- package/package.json +15 -15
- package/dist/S3StateStore-CMN0Uzdp.mjs.map +0 -1
- package/dist/S3StateStore-zK9zcd9f.cjs.map +0 -1
- package/dist/awsStore-B5We7bMg.cjs.map +0 -1
- package/dist/awsStore-BWa1KNY-.mjs.map +0 -1
- package/dist/cli-1l0L9LCA.cjs.map +0 -1
- package/dist/cli-D7z1lQtO.mjs.map +0 -1
- package/dist/compose-C39XupJu.cjs +0 -1558
- package/dist/compose-C39XupJu.cjs.map +0 -1
- package/dist/compose-DgWrNd2k.mjs +0 -1511
- package/dist/compose-DgWrNd2k.mjs.map +0 -1
- package/dist/deploy-Cu_HyWoJ.cjs.map +0 -1
- package/dist/deploy-LY-20Yeb.mjs.map +0 -1
- package/dist/dns-Bmbhmz41.mjs +0 -44
- package/dist/dns-Bmbhmz41.mjs.map +0 -1
- package/dist/dns-Dro_vbk9.cjs +0 -55
- package/dist/dns-Dro_vbk9.cjs.map +0 -1
- package/dist/github-DC4SIqV1.cjs.map +0 -1
- package/dist/github-zgaBOQvh.mjs.map +0 -1
- package/dist/migrate-C230QeXU.mjs +0 -94
- package/dist/migrate-C230QeXU.mjs.map +0 -1
- package/dist/migrate-CsMrI7Dk.cjs +0 -94
- package/dist/migrate-CsMrI7Dk.cjs.map +0 -1
- package/dist/secrets-BTY6JhTp.cjs +0 -47
- package/dist/secrets-BTY6JhTp.cjs.map +0 -1
- package/dist/secrets-HzKNTWg9.mjs +0 -36
- package/dist/secrets-HzKNTWg9.mjs.map +0 -1
- package/dist/seeds-BQlj9Fsg.cjs.map +0 -1
- package/dist/seeds-BsJRUL1K.mjs.map +0 -1
- package/dist/stack-BQOyqaVG.mjs +0 -1201
- package/dist/stack-BQOyqaVG.mjs.map +0 -1
- package/dist/stack-Clzi40EE.cjs +0 -1308
- package/dist/stack-Clzi40EE.cjs.map +0 -1
- package/dist/stages-BpDXFPGg.cjs.map +0 -1
- package/dist/stages-DEmn7qI8.mjs.map +0 -1
- package/dist/types-4vPS_YFX.d.cts.map +0 -1
- package/dist/types-CFsEyFb1.d.mts.map +0 -1
- package/dist/workspace-Bv4xROeu.mjs.map +0 -1
- package/dist/workspace-C1M-S4al.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollback-
|
|
1
|
+
{"version":3,"file":"rollback-BkIkE8Qe.mjs","names":[],"sources":["../src/target/dokploy/rollback.ts"],"sourcesContent":["/**\n * `gkm deploy:rollback`: a stage's apps put back on the release before the\n * one they run, by hand — for a release that passed its checks and turned out\n * wrong anyway.\n *\n * One app by default, because an app is what usually broke: rolling the API\n * back over a site fix that shipped beside it undoes the fix too. `atomic`\n * rolls back every app that has a release to go back to, for apps that only\n * work together — an API and the site built against its newer contract.\n *\n * It restores images and nothing else. The environment an app runs with is\n * the stage's, resolved on every deploy, and migrations are forward-only: a\n * migration that the older code cannot run against is undone by a new\n * migration, never by a rollback.\n */\n\nimport { resolve } from 'node:path';\nimport { findWorkspaceRoot, loadWorkspaceConfig } from '../../config';\nimport {\n\ttype CredentialProvider,\n\tstoredCredentials,\n} from '../../deploy/credentials';\nimport { DeployJournal } from '../../deploy/journal';\nimport {\n\tassertStateOutlivesRun,\n\tcreateStateStore,\n} from '../../deploy/StateStore';\nimport {\n\tasDokployState,\n\tcreateEmptyState,\n\ttype ReleasedImage,\n\trecordRollback,\n} from '../../deploy/state';\nimport { GkmError } from '../../errors';\nimport { LocalSandbox } from '../../sandbox/local';\nimport { type Sandbox, withSandbox } from '../../sandbox/sandbox';\nimport { assertDeployedStage } from '../../workspace/stages';\nimport { dokployApi, restoreImage, verifySettings } from './engine';\n\nexport interface RollbackInput {\n\t/** The project: the directory holding `gkm.config.ts`, or one inside it. */\n\tcwd: string;\n\tstage: string;\n\t/** The app to roll back. */\n\tapp?: string;\n\t/** Every app with an earlier release, instead of one. */\n\tatomic?: boolean;\n\t/** Defaults to the environment, then the logins `gkm login` stored. */\n\tcredentials?: CredentialProvider;\n\tsignal?: AbortSignal;\n\t/** Each progress line. Defaults to none. */\n\tlog?: (line: string) => void;\n\t/** Where the config is loaded. Defaults to a `LocalSandbox` on the project. */\n\tsandbox?: Sandbox;\n}\n\n/** One app rolled back. */\nexport interface RolledBack {\n\tapp: string;\n\tfrom: ReleasedImage;\n\tto: ReleasedImage;\n}\n\n/** Neither an app nor every app was asked for. */\nexport class RollbackNeedsApp extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** The apps that have a release to go back to. */\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`Say what to roll back: --app <name> for one app (${apps.join(', ') || 'none has an earlier release'}), ` +\n\t\t\t\t`or --atomic for every app of \"${stage}\" together.`,\n\t\t);\n\t\tthis.name = 'RollbackNeedsApp';\n\t}\n}\n\n/** An app has no release before the one it runs. */\nexport class NothingToRollBack extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly app: string,\n\t) {\n\t\tsuper(\n\t\t\t`\"${app}\" has no earlier release on \"${stage}\" to roll back to: it has been released once, ` +\n\t\t\t\t'or every earlier release was itself rolled back. Deploy the version you want instead.',\n\t\t);\n\t\tthis.name = 'NothingToRollBack';\n\t}\n}\n\n/** The stage was never deployed through Dokploy from this state. */\nexport class StageNeverDeployed extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`\"${stage}\" has no deploy state, so there is nothing to roll back. ` +\n\t\t\t\t'Check the stage name, and that `state` in gkm.config.ts points at the store the deploys write to.',\n\t\t);\n\t\tthis.name = 'StageNeverDeployed';\n\t}\n}\n\n/**\n * Roll a stage's app — or, `atomic`, all of them — back to its previous\n * release, holding the stage's lock as a deploy does.\n */\nexport async function rollbackStage(\n\tinput: RollbackInput,\n): Promise<RolledBack[]> {\n\tconst signal = input.signal ?? new AbortController().signal;\n\tconst log = input.log ?? (() => {});\n\tconst credentials = input.credentials ?? storedCredentials();\n\tconst sandbox =\n\t\tinput.sandbox ??\n\t\tnew LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });\n\n\treturn withSandbox(sandbox, async () => {\n\t\tconst { workspace } = await loadWorkspaceConfig(resolve(input.cwd), {\n\t\t\tsandbox,\n\t\t});\n\t\tassertDeployedStage(workspace.stages, input.stage);\n\t\tassertStateOutlivesRun(workspace, input.stage, 'deploy:rollback');\n\n\t\tconst store = await createStateStore({\n\t\t\tconfig: workspace.state,\n\t\t\tworkspaceRoot: workspace.root,\n\t\t\tworkspaceName: workspace.name,\n\t\t\tnamespace: workspace.deploy?.namespace,\n\t\t});\n\t\tif (!(await store.read(input.stage))) {\n\t\t\tthrow new StageNeverDeployed(input.stage);\n\t\t}\n\n\t\tconst lock = await store.lock(input.stage, { operation: 'rollback' });\n\t\ttry {\n\t\t\tconst journal = await DeployJournal.open(\n\t\t\t\tstore,\n\t\t\t\tinput.stage,\n\t\t\t\t() => createEmptyState(input.stage, '', ''),\n\t\t\t\tasDokployState,\n\t\t\t);\n\t\t\tconst { state } = journal;\n\t\t\tconst releases = state.releases ?? {};\n\t\t\tconst restorable = Object.keys(releases).filter(\n\t\t\t\t(app) => releases[app]!.previous,\n\t\t\t);\n\n\t\t\tlet apps: string[];\n\t\t\tif (input.atomic) {\n\t\t\t\tapps = restorable;\n\t\t\t\tif (apps.length === 0) {\n\t\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t\t}\n\t\t\t} else if (input.app) {\n\t\t\t\tif (!releases[input.app]?.previous) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, input.app);\n\t\t\t\t}\n\t\t\t\tapps = [input.app];\n\t\t\t} else {\n\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t}\n\n\t\t\tconst { api } = await dokployApi(workspace, { credentials, signal });\n\t\t\tconst verify = verifySettings(workspace.deploy.dokploy?.verify);\n\t\t\tconst rolled: RolledBack[] = [];\n\n\t\t\tfor (const app of apps) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tconst { current, previous } = releases[app]!;\n\t\t\t\tconst applicationId = state.applications[app];\n\t\t\t\tif (!previous || !applicationId) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, app);\n\t\t\t\t}\n\n\t\t\t\tlog(`⏪ ${app}: ${current.ref} → ${previous.ref}`);\n\t\t\t\tawait restoreImage(api, {\n\t\t\t\t\tapplicationId,\n\t\t\t\t\timage: previous,\n\t\t\t\t\tregistryId: state.registryId,\n\t\t\t\t\tverify,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\trecordRollback(state, app, previous);\n\t\t\t\tawait journal.save();\n\t\t\t\tlog(` ✓ ${app} is running ${previous.ref}`);\n\t\t\t\trolled.push({ app, from: current, to: previous });\n\t\t\t}\n\n\t\t\treturn rolled;\n\t\t} finally {\n\t\t\tawait lock.release();\n\t\t}\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,IAAa,mBAAb,cAAsC,SAAS;CAEpC;CAEA;CAHV,YACC,OAEA,MACC;EACD,MACC,oDAAoD,KAAK,KAAK,IAAI,KAAK,8BAA8B,mCACnE,MAAM,YACzC;EAPS,KAAA,QAAA;EAEA,KAAA,OAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,oBAAb,cAAuC,SAAS;CAErC;CACA;CAFV,YACC,OACA,KACC;EACD,MACC,IAAI,IAAI,+BAA+B,MAAM,oIAE9C;EANS,KAAA,QAAA;EACA,KAAA,MAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,qBAAb,cAAwC,SAAS;CAC3B;CAArB,YAAY,OAAwB;EACnC,MACC,IAAI,MAAM,6JAEX;EAJoB,KAAA,QAAA;EAKpB,KAAK,OAAO;CACb;AACD;;;;;AAMA,eAAsB,cACrB,OACwB;CACxB,MAAM,SAAS,MAAM,UAAU,IAAI,gBAAgB,CAAC,CAAC;CACrD,MAAM,MAAM,MAAM,cAAc,CAAC;CACjC,MAAM,cAAc,MAAM,eAAe,kBAAkB;CAC3D,MAAM,UACL,MAAM,WACN,IAAI,aAAa,EAAE,MAAM,kBAAkB,QAAQ,MAAM,GAAG,CAAC,EAAE,CAAC;CAEjE,OAAO,YAAY,SAAS,YAAY;EACvC,MAAM,EAAE,cAAc,MAAM,oBAAoB,QAAQ,MAAM,GAAG,GAAG,EACnE,QACD,CAAC;EACD,oBAAo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,IAAI,kBAAkB,MAAM,OAAO,GAAG;IAG7C,IAAI,KAAK,IAAI,IAAI,QAAQ,IAAI,KAAK,SAAS,KAAK;IAChD,MAAM,aAAa,KAAK;KACvB;KACA,OAAO;KACP,YAAY,MAAM;KAClB;KACA;IACD,CAAC;IACD,eAAe,OAAO,KAAK,QAAQ;IACnC,MAAM,QAAQ,KAAK;IACnB,IAAI,QAAQ,IAAI,cAAc,SAAS,KAAK;IAC5C,OAAO,KAAK;KAAE;KAAK,MAAM;KAAS,IAAI;IAAS,CAAC;GACjD;GAEA,OAAO;EACR,UAAU;GACT,MAAM,KAAK,QAAQ;EACpB;CACD,CAAC;AACF"}
|
|
@@ -2,12 +2,12 @@ const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
|
2
2
|
const require_errors = require("./errors-DMC4Umsb.cjs");
|
|
3
3
|
const require_credentials = require("./credentials-Zqr3QQYB.cjs");
|
|
4
4
|
const require_sandbox = require("./sandbox-CHv3OYXg.cjs");
|
|
5
|
-
const require_workspace = require("./workspace-
|
|
5
|
+
const require_workspace = require("./workspace-DRjdu1OY.cjs");
|
|
6
6
|
const require_config = require("./config.cjs");
|
|
7
|
-
const require_seeds = require("./seeds-
|
|
7
|
+
const require_seeds = require("./seeds-BNHSpjNP.cjs");
|
|
8
8
|
const require_local = require("./local-DNhnkugT.cjs");
|
|
9
|
-
const require_sniffer = require("./sniffer-
|
|
10
|
-
const require_engine = require("./engine-
|
|
9
|
+
const require_sniffer = require("./sniffer-Cylp9W2D.cjs");
|
|
10
|
+
const require_engine = require("./engine-Dk19Mxc4.cjs");
|
|
11
11
|
let node_path = require("node:path");
|
|
12
12
|
//#region src/target/dokploy/rollback.ts
|
|
13
13
|
/**
|
|
@@ -162,4 +162,4 @@ Object.defineProperty(exports, "rollback_exports", {
|
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
//# sourceMappingURL=rollback-
|
|
165
|
+
//# sourceMappingURL=rollback-DBfLvC8k.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollback-
|
|
1
|
+
{"version":3,"file":"rollback-DBfLvC8k.cjs","names":["GkmError","storedCredentials","LocalSandbox","findWorkspaceRoot","resolve","withSandbox","loadWorkspaceConfig","createStateStore","DeployJournal","createEmptyState","asDokployState","dokployApi","verifySettings","restoreImage"],"sources":["../src/target/dokploy/rollback.ts"],"sourcesContent":["/**\n * `gkm deploy:rollback`: a stage's apps put back on the release before the\n * one they run, by hand — for a release that passed its checks and turned out\n * wrong anyway.\n *\n * One app by default, because an app is what usually broke: rolling the API\n * back over a site fix that shipped beside it undoes the fix too. `atomic`\n * rolls back every app that has a release to go back to, for apps that only\n * work together — an API and the site built against its newer contract.\n *\n * It restores images and nothing else. The environment an app runs with is\n * the stage's, resolved on every deploy, and migrations are forward-only: a\n * migration that the older code cannot run against is undone by a new\n * migration, never by a rollback.\n */\n\nimport { resolve } from 'node:path';\nimport { findWorkspaceRoot, loadWorkspaceConfig } from '../../config';\nimport {\n\ttype CredentialProvider,\n\tstoredCredentials,\n} from '../../deploy/credentials';\nimport { DeployJournal } from '../../deploy/journal';\nimport {\n\tassertStateOutlivesRun,\n\tcreateStateStore,\n} from '../../deploy/StateStore';\nimport {\n\tasDokployState,\n\tcreateEmptyState,\n\ttype ReleasedImage,\n\trecordRollback,\n} from '../../deploy/state';\nimport { GkmError } from '../../errors';\nimport { LocalSandbox } from '../../sandbox/local';\nimport { type Sandbox, withSandbox } from '../../sandbox/sandbox';\nimport { assertDeployedStage } from '../../workspace/stages';\nimport { dokployApi, restoreImage, verifySettings } from './engine';\n\nexport interface RollbackInput {\n\t/** The project: the directory holding `gkm.config.ts`, or one inside it. */\n\tcwd: string;\n\tstage: string;\n\t/** The app to roll back. */\n\tapp?: string;\n\t/** Every app with an earlier release, instead of one. */\n\tatomic?: boolean;\n\t/** Defaults to the environment, then the logins `gkm login` stored. */\n\tcredentials?: CredentialProvider;\n\tsignal?: AbortSignal;\n\t/** Each progress line. Defaults to none. */\n\tlog?: (line: string) => void;\n\t/** Where the config is loaded. Defaults to a `LocalSandbox` on the project. */\n\tsandbox?: Sandbox;\n}\n\n/** One app rolled back. */\nexport interface RolledBack {\n\tapp: string;\n\tfrom: ReleasedImage;\n\tto: ReleasedImage;\n}\n\n/** Neither an app nor every app was asked for. */\nexport class RollbackNeedsApp extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** The apps that have a release to go back to. */\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`Say what to roll back: --app <name> for one app (${apps.join(', ') || 'none has an earlier release'}), ` +\n\t\t\t\t`or --atomic for every app of \"${stage}\" together.`,\n\t\t);\n\t\tthis.name = 'RollbackNeedsApp';\n\t}\n}\n\n/** An app has no release before the one it runs. */\nexport class NothingToRollBack extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly app: string,\n\t) {\n\t\tsuper(\n\t\t\t`\"${app}\" has no earlier release on \"${stage}\" to roll back to: it has been released once, ` +\n\t\t\t\t'or every earlier release was itself rolled back. Deploy the version you want instead.',\n\t\t);\n\t\tthis.name = 'NothingToRollBack';\n\t}\n}\n\n/** The stage was never deployed through Dokploy from this state. */\nexport class StageNeverDeployed extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`\"${stage}\" has no deploy state, so there is nothing to roll back. ` +\n\t\t\t\t'Check the stage name, and that `state` in gkm.config.ts points at the store the deploys write to.',\n\t\t);\n\t\tthis.name = 'StageNeverDeployed';\n\t}\n}\n\n/**\n * Roll a stage's app — or, `atomic`, all of them — back to its previous\n * release, holding the stage's lock as a deploy does.\n */\nexport async function rollbackStage(\n\tinput: RollbackInput,\n): Promise<RolledBack[]> {\n\tconst signal = input.signal ?? new AbortController().signal;\n\tconst log = input.log ?? (() => {});\n\tconst credentials = input.credentials ?? storedCredentials();\n\tconst sandbox =\n\t\tinput.sandbox ??\n\t\tnew LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });\n\n\treturn withSandbox(sandbox, async () => {\n\t\tconst { workspace } = await loadWorkspaceConfig(resolve(input.cwd), {\n\t\t\tsandbox,\n\t\t});\n\t\tassertDeployedStage(workspace.stages, input.stage);\n\t\tassertStateOutlivesRun(workspace, input.stage, 'deploy:rollback');\n\n\t\tconst store = await createStateStore({\n\t\t\tconfig: workspace.state,\n\t\t\tworkspaceRoot: workspace.root,\n\t\t\tworkspaceName: workspace.name,\n\t\t\tnamespace: workspace.deploy?.namespace,\n\t\t});\n\t\tif (!(await store.read(input.stage))) {\n\t\t\tthrow new StageNeverDeployed(input.stage);\n\t\t}\n\n\t\tconst lock = await store.lock(input.stage, { operation: 'rollback' });\n\t\ttry {\n\t\t\tconst journal = await DeployJournal.open(\n\t\t\t\tstore,\n\t\t\t\tinput.stage,\n\t\t\t\t() => createEmptyState(input.stage, '', ''),\n\t\t\t\tasDokployState,\n\t\t\t);\n\t\t\tconst { state } = journal;\n\t\t\tconst releases = state.releases ?? {};\n\t\t\tconst restorable = Object.keys(releases).filter(\n\t\t\t\t(app) => releases[app]!.previous,\n\t\t\t);\n\n\t\t\tlet apps: string[];\n\t\t\tif (input.atomic) {\n\t\t\t\tapps = restorable;\n\t\t\t\tif (apps.length === 0) {\n\t\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t\t}\n\t\t\t} else if (input.app) {\n\t\t\t\tif (!releases[input.app]?.previous) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, input.app);\n\t\t\t\t}\n\t\t\t\tapps = [input.app];\n\t\t\t} else {\n\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t}\n\n\t\t\tconst { api } = await dokployApi(workspace, { credentials, signal });\n\t\t\tconst verify = verifySettings(workspace.deploy.dokploy?.verify);\n\t\t\tconst rolled: RolledBack[] = [];\n\n\t\t\tfor (const app of apps) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tconst { current, previous } = releases[app]!;\n\t\t\t\tconst applicationId = state.applications[app];\n\t\t\t\tif (!previous || !applicationId) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, app);\n\t\t\t\t}\n\n\t\t\t\tlog(`⏪ ${app}: ${current.ref} → ${previous.ref}`);\n\t\t\t\tawait restoreImage(api, {\n\t\t\t\t\tapplicationId,\n\t\t\t\t\timage: previous,\n\t\t\t\t\tregistryId: state.registryId,\n\t\t\t\t\tverify,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\trecordRollback(state, app, previous);\n\t\t\t\tawait journal.save();\n\t\t\t\tlog(` ✓ ${app} is running ${previous.ref}`);\n\t\t\t\trolled.push({ app, from: current, to: previous });\n\t\t\t}\n\n\t\t\treturn rolled;\n\t\t} finally {\n\t\t\tawait lock.release();\n\t\t}\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,IAAa,mBAAb,cAAsCA,eAAAA,SAAS;CAEpC;CAEA;CAHV,YACC,OAEA,MACC;EACD,MACC,oDAAoD,KAAK,KAAK,IAAI,KAAK,8BAA8B,mCACnE,MAAM,YACzC;EAPS,KAAA,QAAA;EAEA,KAAA,OAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,oBAAb,cAAuCA,eAAAA,SAAS;CAErC;CACA;CAFV,YACC,OACA,KACC;EACD,MACC,IAAI,IAAI,+BAA+B,MAAM,oIAE9C;EANS,KAAA,QAAA;EACA,KAAA,MAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,qBAAb,cAAwCA,eAAAA,SAAS;CAC3B;CAArB,YAAY,OAAwB;EACnC,MACC,IAAI,MAAM,6JAEX;EAJoB,KAAA,QAAA;EAKpB,KAAK,OAAO;CACb;AACD;;;;;AAMA,eAAsB,cACrB,OACwB;CACxB,MAAM,SAAS,MAAM,UAAU,IAAI,gBAAgB,CAAC,CAAC;CACrD,MAAM,MAAM,MAAM,cAAc,CAAC;CACjC,MAAM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GAAG;IAEnD,OAAO,CAAC,MAAM,GAAG;GAClB,OACC,MAAM,IAAI,iBAAiB,MAAM,OAAO,UAAU;GAGnD,MAAM,EAAE,QAAQ,MAAMC,eAAAA,WAAW,WAAW;IAAE;IAAa;GAAO,CAAC;GACnE,MAAM,SAASC,eAAAA,eAAe,UAAU,OAAO,SAAS,MAAM;GAC9D,MAAM,SAAuB,CAAC;GAE9B,KAAK,MAAM,OAAO,MAAM;IACvB,OAAO,eAAe;IACtB,MAAM,EAAE,SAAS,aAAa,SAAS;IACvC,MAAM,gBAAgB,MAAM,aAAa;IACzC,IAAI,CAAC,YAAY,CAAC,eACjB,MAAM,IAAI,kBAAkB,MAAM,OAAO,GAAG;IAG7C,IAAI,KAAK,IAAI,IAAI,QAAQ,IAAI,KAAK,SAAS,KAAK;IAChD,MAAMC,eAAAA,aAAa,KAAK;KACvB;KACA,OAAO;KACP,YAAY,MAAM;KAClB;KACA;IACD,CAAC;IACD,cAAA,eAAe,OAAO,KAAK,QAAQ;IACnC,MAAM,QAAQ,KAAK;IACnB,IAAI,QAAQ,IAAI,cAAc,SAAS,KAAK;IAC5C,OAAO,KAAK;KAAE;KAAK,MAAM;KAAS,IAAI;IAAS,CAAC;GACjD;GAEA,OAAO;EACR,UAAU;GACT,MAAM,KAAK,QAAQ;EACpB;CACD,CAAC;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as DeployRuntime, et as TargetOptionsIssue, jt as GkmError } from "./types-
|
|
1
|
+
import { K as DeployRuntime, et as TargetOptionsIssue, jt as GkmError } from "./types-BhThob0H.mjs";
|
|
2
2
|
//#region src/target/builtins.d.ts
|
|
3
3
|
/** A target name that is neither built in nor in `deploy.targets`. */
|
|
4
4
|
declare class UnknownDeployTarget extends GkmError {
|
|
@@ -79,4 +79,4 @@ declare class TargetRuntimeUndeclared extends GkmError {
|
|
|
79
79
|
}
|
|
80
80
|
//#endregion
|
|
81
81
|
export { TargetRuntimeMismatch as a, DeployTargetNotYetSupported as c, TargetPackageInvalid as i, UnknownDeployTarget as l, InvalidTargetOptions as n, ProviderRemoved as o, TargetEntryInvalid as r, TargetPackageNotFound as s, TargetRuntimeUndeclared as t };
|
|
82
|
-
//# sourceMappingURL=runtime-
|
|
82
|
+
//# sourceMappingURL=runtime-CLz3bf07.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-
|
|
1
|
+
{"version":3,"file":"runtime-CLz3bf07.d.mts","names":[],"sources":["../src/target/builtins.ts","../src/target/package.ts","../src/target/provider.ts","../src/target/resolve.ts","../src/target/runtime.ts"],"mappings":";;;cAgEa,4BAA4B;WAE9B;;WAEA;EAHV,YACU,gBAEA;;EAAA;;;cAUE,oCAAoC;WAEtC;;WAEA;EAHV,YACU,gBAEA;;EAAA;;;;;cCrDE,8BAA8B;WAEhC;WACA;WACA;EAHV,YACU,gBACA,qBACA;;;;;cCZE,wBAAwB;WAE1B;;WAEA;EAHV,YACU,kBAEA;;EAAA;;;;;cCoCE,6BAA6B;WAE/B;WACA;EAFV,YACU,gBACA;;;cAUE,2BAA2B;WAClB;EAArB,YAAqB;;;cAST,8BAA8B;WAEhC;WACA;WACA,UAAU;WACV,QAAQ;EAJlB,YACU,gBACA,qBACA,UAAU,eACV,QAAQ;;;cAUN,6BAA6B;WAE/B;WACA,iBAAiB;EAF3B,YACU,gBACA,iBAAiB;;;;;cC1Ef,gCAAgC;WAElC;WACA;;WAEA;EAJV,YACU,gBACA,qBAEA;;EAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as DeployRuntime, et as TargetOptionsIssue, jt as GkmError } from "./types-
|
|
1
|
+
import { K as DeployRuntime, et as TargetOptionsIssue, jt as GkmError } from "./types-DwoLHelT.cjs";
|
|
2
2
|
//#region src/target/builtins.d.ts
|
|
3
3
|
/** A target name that is neither built in nor in `deploy.targets`. */
|
|
4
4
|
declare class UnknownDeployTarget extends GkmError {
|
|
@@ -79,4 +79,4 @@ declare class TargetRuntimeUndeclared extends GkmError {
|
|
|
79
79
|
}
|
|
80
80
|
//#endregion
|
|
81
81
|
export { TargetRuntimeMismatch as a, DeployTargetNotYetSupported as c, TargetPackageInvalid as i, UnknownDeployTarget as l, InvalidTargetOptions as n, ProviderRemoved as o, TargetEntryInvalid as r, TargetPackageNotFound as s, TargetRuntimeUndeclared as t };
|
|
82
|
-
//# sourceMappingURL=runtime-
|
|
82
|
+
//# sourceMappingURL=runtime-CUWf0IUk.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-
|
|
1
|
+
{"version":3,"file":"runtime-CUWf0IUk.d.cts","names":[],"sources":["../src/target/builtins.ts","../src/target/package.ts","../src/target/provider.ts","../src/target/resolve.ts","../src/target/runtime.ts"],"mappings":";;;cAgEa,4BAA4B;WAE9B;;WAEA;EAHV,YACU,gBAEA;;EAAA;;;cAUE,oCAAoC;WAEtC;;WAEA;EAHV,YACU,gBAEA;;EAAA;;;;;cCrDE,8BAA8B;WAEhC;WACA;WACA;EAHV,YACU,gBACA,qBACA;;;;;cCZE,wBAAwB;WAE1B;;WAEA;EAHV,YACU,kBAEA;;EAAA;;;;;cCoCE,6BAA6B;WAE/B;WACA;EAFV,YACU,gBACA;;;cAUE,2BAA2B;WAClB;EAArB,YAAqB;;;cAST,8BAA8B;WAEhC;WACA;WACA,UAAU;WACV,QAAQ;EAJlB,YACU,gBACA,qBACA,UAAU,eACV,QAAQ;;;cAUN,6BAA6B;WAE/B;WACA,iBAAiB;EAF3B,YACU,gBACA,iBAAiB;;;;;cC1Ef,gCAAgC;WAElC;WACA;;WAEA;EAJV,YACU,gBACA,qBAEA;;EAAA"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { t as GkmError } from "./errors-D8Gwp5kU.mjs";
|
|
2
|
+
import { pt as s3SecretsKey } from "./workspace-D5CpOp1y.mjs";
|
|
3
|
+
import { a as projectBucketName, i as findProjectBucket, n as callerAccountId, r as ensureProjectBucket } from "./projectBucket-BYOxRnHY.mjs";
|
|
4
|
+
import { r as withStageCredentials, t as awsClientConfig } from "./awsStore-Bx5nCFnS.mjs";
|
|
5
|
+
import { GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
6
|
+
import { STSClient } from "@aws-sdk/client-sts";
|
|
7
|
+
//#region src/secrets/s3.ts
|
|
8
|
+
/**
|
|
9
|
+
* A stage's secrets in S3: one object per stage,
|
|
10
|
+
* `<prefix>/<project>/<stage>/secrets.json`, in the project bucket beside the
|
|
11
|
+
* deploy state (`providers/projectBucket.ts`) — or in a bucket the config
|
|
12
|
+
* names, which must exist.
|
|
13
|
+
*
|
|
14
|
+
* Encrypted at rest with SSE-S3, asked for on every write although the
|
|
15
|
+
* project bucket defaults to it, so no KMS key is another place to keep. The
|
|
16
|
+
* bucket's versioning keeps every past document. Unlike an SSM parameter
|
|
17
|
+
* there is no size to outgrow.
|
|
18
|
+
*
|
|
19
|
+
* The project bucket is created by the first write, never by a read: a stage
|
|
20
|
+
* whose bucket or object does not exist yet has no secrets. Every write is
|
|
21
|
+
* conditional — `If-Match` on the ETag this store last read for the stage,
|
|
22
|
+
* `If-None-Match: *` when it read none — so two `secrets:set` runs at once
|
|
23
|
+
* cannot each overwrite the other's key: the second is refused with
|
|
24
|
+
* {@link StageSecretsChanged}.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Another run wrote the stage's secrets after this one read them. Nothing was
|
|
28
|
+
* written: the change is to be made again, on top of theirs.
|
|
29
|
+
*/
|
|
30
|
+
var StageSecretsChanged = class extends GkmError {
|
|
31
|
+
stage;
|
|
32
|
+
location;
|
|
33
|
+
constructor(stage, location) {
|
|
34
|
+
super(`The secrets for stage "${stage}" at ${location} changed after this command read them — another secrets command or deploy wrote them first. Nothing was written; run the command again to make the change on top of theirs.`);
|
|
35
|
+
this.stage = stage;
|
|
36
|
+
this.location = location;
|
|
37
|
+
this.name = "StageSecretsChanged";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/** A conditional write that lost: the object is not what the write assumed. */
|
|
41
|
+
function lostRace(error) {
|
|
42
|
+
const { name, $metadata } = error;
|
|
43
|
+
return name === "PreconditionFailed" || name === "ConditionalRequestConflict" || $metadata?.httpStatusCode === 412 || $metadata?.httpStatusCode === 409;
|
|
44
|
+
}
|
|
45
|
+
function notFound(error) {
|
|
46
|
+
const { name, $metadata } = error;
|
|
47
|
+
return name === "NoSuchKey" || name === "NotFound" || $metadata?.httpStatusCode === 404;
|
|
48
|
+
}
|
|
49
|
+
var S3SecretsStore = class {
|
|
50
|
+
options;
|
|
51
|
+
name = "s3";
|
|
52
|
+
clients;
|
|
53
|
+
/** The bucket's name, once known. */
|
|
54
|
+
bucketName;
|
|
55
|
+
/** Whether the bucket is known to exist. */
|
|
56
|
+
exists = false;
|
|
57
|
+
/** The ETag each stage was last read at — null: read, and not there. */
|
|
58
|
+
etags = /* @__PURE__ */ new Map();
|
|
59
|
+
constructor(options) {
|
|
60
|
+
this.options = options;
|
|
61
|
+
if (options.bucket) {
|
|
62
|
+
this.bucketName = options.bucket;
|
|
63
|
+
this.exists = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The bucket's name; the project bucket's is known after the first call. */
|
|
67
|
+
get bucket() {
|
|
68
|
+
return this.bucketName ?? projectBucketName(this.options.identity.scope, "<account id>");
|
|
69
|
+
}
|
|
70
|
+
/** Where a stage's secrets are kept: `s3://<bucket>/<key>`. */
|
|
71
|
+
location(stage) {
|
|
72
|
+
return `s3://${this.bucket}/${this.key(stage)}`;
|
|
73
|
+
}
|
|
74
|
+
key(stage) {
|
|
75
|
+
return s3SecretsKey(this.options.prefix, this.options.project, stage);
|
|
76
|
+
}
|
|
77
|
+
async client() {
|
|
78
|
+
if (this.clients) return this.clients;
|
|
79
|
+
const base = await awsClientConfig(this.options);
|
|
80
|
+
const endpoint = base.endpoint ?? process.env.AWS_ENDPOINT_URL_S3 ?? process.env.AWS_ENDPOINT_URL;
|
|
81
|
+
const credentials = this.options.credentials ?? base.credentials;
|
|
82
|
+
this.clients = {
|
|
83
|
+
s3: new S3Client({
|
|
84
|
+
region: base.region,
|
|
85
|
+
...endpoint ? {
|
|
86
|
+
endpoint,
|
|
87
|
+
forcePathStyle: true
|
|
88
|
+
} : {},
|
|
89
|
+
...credentials ? { credentials } : {}
|
|
90
|
+
}),
|
|
91
|
+
sts: new STSClient({
|
|
92
|
+
region: base.region,
|
|
93
|
+
...base.endpoint ? { endpoint: base.endpoint } : {},
|
|
94
|
+
...credentials ? { credentials } : {}
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
return this.clients;
|
|
98
|
+
}
|
|
99
|
+
/** One AWS call, a missing or expired credential refused by name. */
|
|
100
|
+
call(stage, access, run) {
|
|
101
|
+
return withStageCredentials({
|
|
102
|
+
stage,
|
|
103
|
+
store: this.name,
|
|
104
|
+
profile: this.options.profile,
|
|
105
|
+
access
|
|
106
|
+
}, run);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The bucket, or null for a project bucket that does not exist yet and is
|
|
110
|
+
* not to be created (a read).
|
|
111
|
+
*/
|
|
112
|
+
async use(stage, create) {
|
|
113
|
+
const { s3, sts } = await this.client();
|
|
114
|
+
if (this.exists) return {
|
|
115
|
+
s3,
|
|
116
|
+
bucket: this.bucketName
|
|
117
|
+
};
|
|
118
|
+
const access = create ? "write" : "read";
|
|
119
|
+
this.bucketName ??= projectBucketName(this.options.identity.scope, await this.call(stage, access, () => callerAccountId(sts)));
|
|
120
|
+
const bucket = this.bucketName;
|
|
121
|
+
if (create) await this.call(stage, access, () => ensureProjectBucket(s3, {
|
|
122
|
+
bucket,
|
|
123
|
+
region: this.options.region,
|
|
124
|
+
identity: this.options.identity
|
|
125
|
+
}));
|
|
126
|
+
else if (await this.call(stage, access, () => findProjectBucket(s3, bucket)) === "none") return {
|
|
127
|
+
s3,
|
|
128
|
+
bucket: null
|
|
129
|
+
};
|
|
130
|
+
this.exists = true;
|
|
131
|
+
return {
|
|
132
|
+
s3,
|
|
133
|
+
bucket
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @throws {StageSecretsUnreadable} when there are no AWS credentials to
|
|
138
|
+
* read it with, or they have expired
|
|
139
|
+
*/
|
|
140
|
+
async read(stage) {
|
|
141
|
+
const { s3, bucket } = await this.use(stage, false);
|
|
142
|
+
if (!bucket) {
|
|
143
|
+
this.etags.set(stage, null);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const response = await this.call(stage, "read", () => s3.send(new GetObjectCommand({
|
|
148
|
+
Bucket: bucket,
|
|
149
|
+
Key: this.key(stage)
|
|
150
|
+
})));
|
|
151
|
+
const body = await response.Body.transformToString("utf-8");
|
|
152
|
+
this.remember(stage, response.ETag);
|
|
153
|
+
return JSON.parse(body);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!notFound(error)) throw error;
|
|
156
|
+
this.etags.set(stage, null);
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Replace the stage's secrets — on the condition that they are still what
|
|
162
|
+
* this store last read. A stage never read here is replaced as it is now.
|
|
163
|
+
*
|
|
164
|
+
* @throws {StageSecretsChanged} when another run wrote them in between
|
|
165
|
+
* @throws {StageSecretsUnreadable} when there are no AWS credentials to
|
|
166
|
+
* write it with, or they have expired
|
|
167
|
+
*/
|
|
168
|
+
async write(stage, secrets) {
|
|
169
|
+
const { s3, bucket } = await this.use(stage, true);
|
|
170
|
+
const Bucket = bucket;
|
|
171
|
+
const Key = this.key(stage);
|
|
172
|
+
const expected = this.etags.has(stage) ? this.etags.get(stage) ?? null : await this.currentEtag(s3, stage, Bucket, Key);
|
|
173
|
+
try {
|
|
174
|
+
const { ETag } = await this.call(stage, "write", () => s3.send(new PutObjectCommand({
|
|
175
|
+
Bucket,
|
|
176
|
+
Key,
|
|
177
|
+
Body: JSON.stringify(secrets),
|
|
178
|
+
ContentType: "application/json",
|
|
179
|
+
ServerSideEncryption: "AES256",
|
|
180
|
+
...expected === null ? { IfNoneMatch: "*" } : { IfMatch: expected }
|
|
181
|
+
})));
|
|
182
|
+
this.remember(stage, ETag);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (lostRace(error)) {
|
|
185
|
+
this.etags.delete(stage);
|
|
186
|
+
throw new StageSecretsChanged(stage, `s3://${Bucket}/${Key}`);
|
|
187
|
+
}
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The ETag the stage is now at. Some S3-compatible servers answer without
|
|
193
|
+
* one: then nothing is remembered, and the next write asks for it first.
|
|
194
|
+
*/
|
|
195
|
+
remember(stage, etag) {
|
|
196
|
+
if (etag) this.etags.set(stage, etag);
|
|
197
|
+
else this.etags.delete(stage);
|
|
198
|
+
}
|
|
199
|
+
async currentEtag(s3, stage, Bucket, Key) {
|
|
200
|
+
try {
|
|
201
|
+
const { ETag } = await this.call(stage, "write", () => s3.send(new HeadObjectCommand({
|
|
202
|
+
Bucket,
|
|
203
|
+
Key
|
|
204
|
+
})));
|
|
205
|
+
return ETag ?? null;
|
|
206
|
+
} catch (error) {
|
|
207
|
+
if (notFound(error)) return null;
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
//#endregion
|
|
213
|
+
export { S3SecretsStore };
|
|
214
|
+
|
|
215
|
+
//# sourceMappingURL=s3-BwhQk3QM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-BwhQk3QM.mjs","names":[],"sources":["../src/secrets/s3.ts"],"sourcesContent":["/**\n * A stage's secrets in S3: one object per stage,\n * `<prefix>/<project>/<stage>/secrets.json`, in the project bucket beside the\n * deploy state (`providers/projectBucket.ts`) — or in a bucket the config\n * names, which must exist.\n *\n * Encrypted at rest with SSE-S3, asked for on every write although the\n * project bucket defaults to it, so no KMS key is another place to keep. The\n * bucket's versioning keeps every past document. Unlike an SSM parameter\n * there is no size to outgrow.\n *\n * The project bucket is created by the first write, never by a read: a stage\n * whose bucket or object does not exist yet has no secrets. Every write is\n * conditional — `If-Match` on the ETag this store last read for the stage,\n * `If-None-Match: *` when it read none — so two `secrets:set` runs at once\n * cannot each overwrite the other's key: the second is refused with\n * {@link StageSecretsChanged}.\n */\n\nimport {\n\tGetObjectCommand,\n\tHeadObjectCommand,\n\tPutObjectCommand,\n\tS3Client,\n\ttype S3ClientConfig,\n} from '@aws-sdk/client-s3';\nimport { STSClient } from '@aws-sdk/client-sts';\nimport type { DeployIdentity } from '../deploy/identity.js';\nimport { GkmError } from '../errors';\nimport {\n\tcallerAccountId,\n\tensureProjectBucket,\n\tfindProjectBucket,\n\tprojectBucketName,\n} from '../providers/projectBucket.js';\nimport {\n\ttype AwsStoreOptions,\n\tawsClientConfig,\n\twithStageCredentials,\n} from './awsStore.js';\nimport { s3SecretsKey } from './providers.js';\nimport type { SecretsStore } from './store.js';\nimport type { StageSecrets } from './types.js';\n\nexport interface S3SecretsStoreOptions extends AwsStoreOptions {\n\t/** The deploy identity: the project bucket's name and its tag. */\n\tidentity: Pick<DeployIdentity, 'scope' | 'key'>;\n\t/** A bucket that exists; omitted, the project bucket. */\n\tbucket?: string;\n\t/** Key prefix inside the bucket, without a trailing slash. */\n\tprefix: string;\n\t/** For tests: credentials to use instead of the default chain. */\n\tcredentials?: S3ClientConfig['credentials'];\n}\n\n/**\n * Another run wrote the stage's secrets after this one read them. Nothing was\n * written: the change is to be made again, on top of theirs.\n */\nexport class StageSecretsChanged extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** `s3://<bucket>/<key>` */\n\t\treadonly location: string,\n\t) {\n\t\tsuper(\n\t\t\t`The secrets for stage \"${stage}\" at ${location} changed after this command read them — ` +\n\t\t\t\t'another secrets command or deploy wrote them first. Nothing was written; run the command ' +\n\t\t\t\t'again to make the change on top of theirs.',\n\t\t);\n\t\tthis.name = 'StageSecretsChanged';\n\t}\n}\n\ninterface S3Failure {\n\tname?: string;\n\t$metadata?: { httpStatusCode?: number };\n}\n\n/** A conditional write that lost: the object is not what the write assumed. */\nfunction lostRace(error: unknown): boolean {\n\tconst { name, $metadata } = error as S3Failure;\n\treturn (\n\t\tname === 'PreconditionFailed' ||\n\t\tname === 'ConditionalRequestConflict' ||\n\t\t$metadata?.httpStatusCode === 412 ||\n\t\t$metadata?.httpStatusCode === 409\n\t);\n}\n\nfunction notFound(error: unknown): boolean {\n\tconst { name, $metadata } = error as S3Failure;\n\treturn (\n\t\tname === 'NoSuchKey' ||\n\t\tname === 'NotFound' ||\n\t\t$metadata?.httpStatusCode === 404\n\t);\n}\n\nexport class S3SecretsStore implements SecretsStore {\n\treadonly name = 's3';\n\n\tprivate clients?: { s3: S3Client; sts: STSClient };\n\t/** The bucket's name, once known. */\n\tprivate bucketName?: string;\n\t/** Whether the bucket is known to exist. */\n\tprivate exists = false;\n\t/** The ETag each stage was last read at — null: read, and not there. */\n\tprivate readonly etags = new Map<string, string | null>();\n\n\tconstructor(private readonly options: S3SecretsStoreOptions) {\n\t\tif (options.bucket) {\n\t\t\tthis.bucketName = options.bucket;\n\t\t\tthis.exists = true;\n\t\t}\n\t}\n\n\t/** The bucket's name; the project bucket's is known after the first call. */\n\tget bucket(): string {\n\t\treturn (\n\t\t\tthis.bucketName ??\n\t\t\tprojectBucketName(this.options.identity.scope, '<account id>')\n\t\t);\n\t}\n\n\t/** Where a stage's secrets are kept: `s3://<bucket>/<key>`. */\n\tlocation(stage: string): string {\n\t\treturn `s3://${this.bucket}/${this.key(stage)}`;\n\t}\n\n\tprivate key(stage: string): string {\n\t\treturn s3SecretsKey(this.options.prefix, this.options.project, stage);\n\t}\n\n\tprivate async client(): Promise<{ s3: S3Client; sts: STSClient }> {\n\t\tif (this.clients) return this.clients;\n\t\tconst base = await awsClientConfig(this.options);\n\t\tconst endpoint =\n\t\t\tbase.endpoint ??\n\t\t\tprocess.env.AWS_ENDPOINT_URL_S3 ??\n\t\t\tprocess.env.AWS_ENDPOINT_URL;\n\t\tconst credentials = this.options.credentials ?? base.credentials;\n\t\tthis.clients = {\n\t\t\ts3: new S3Client({\n\t\t\t\tregion: base.region,\n\t\t\t\t...(endpoint ? { endpoint, forcePathStyle: true } : {}),\n\t\t\t\t...(credentials ? { credentials } : {}),\n\t\t\t}),\n\t\t\tsts: new STSClient({\n\t\t\t\tregion: base.region,\n\t\t\t\t...(base.endpoint ? { endpoint: base.endpoint } : {}),\n\t\t\t\t...(credentials ? { credentials } : {}),\n\t\t\t}),\n\t\t};\n\t\treturn this.clients;\n\t}\n\n\t/** One AWS call, a missing or expired credential refused by name. */\n\tprivate call<T>(\n\t\tstage: string,\n\t\taccess: 'read' | 'write',\n\t\trun: () => Promise<T>,\n\t): Promise<T> {\n\t\treturn withStageCredentials(\n\t\t\t{ stage, store: this.name, profile: this.options.profile, access },\n\t\t\trun,\n\t\t);\n\t}\n\n\t/**\n\t * The bucket, or null for a project bucket that does not exist yet and is\n\t * not to be created (a read).\n\t */\n\tprivate async use(\n\t\tstage: string,\n\t\tcreate: boolean,\n\t): Promise<{ s3: S3Client; bucket: string | null }> {\n\t\tconst { s3, sts } = await this.client();\n\t\tif (this.exists) return { s3, bucket: this.bucketName! };\n\t\tconst access = create ? 'write' : 'read';\n\t\tthis.bucketName ??= projectBucketName(\n\t\t\tthis.options.identity.scope,\n\t\t\tawait this.call(stage, access, () => callerAccountId(sts)),\n\t\t);\n\t\tconst bucket = this.bucketName;\n\t\tif (create) {\n\t\t\tawait this.call(stage, access, () =>\n\t\t\t\tensureProjectBucket(s3, {\n\t\t\t\t\tbucket,\n\t\t\t\t\tregion: this.options.region,\n\t\t\t\t\tidentity: this.options.identity,\n\t\t\t\t}),\n\t\t\t);\n\t\t} else if (\n\t\t\t(await this.call(stage, access, () => findProjectBucket(s3, bucket))) ===\n\t\t\t'none'\n\t\t) {\n\t\t\treturn { s3, bucket: null };\n\t\t}\n\t\tthis.exists = true;\n\t\treturn { s3, bucket };\n\t}\n\n\t/**\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * read it with, or they have expired\n\t */\n\tasync read(stage: string): Promise<StageSecrets | null> {\n\t\tconst { s3, bucket } = await this.use(stage, false);\n\t\tif (!bucket) {\n\t\t\tthis.etags.set(stage, null);\n\t\t\treturn null;\n\t\t}\n\t\ttry {\n\t\t\tconst response = await this.call(stage, 'read', () =>\n\t\t\t\ts3.send(new GetObjectCommand({ Bucket: bucket, Key: this.key(stage) })),\n\t\t\t);\n\t\t\tconst body = await (\n\t\t\t\tresponse.Body as {\n\t\t\t\t\ttransformToString(encoding: string): Promise<string>;\n\t\t\t\t}\n\t\t\t).transformToString('utf-8');\n\t\t\tthis.remember(stage, response.ETag);\n\t\t\treturn JSON.parse(body) as StageSecrets;\n\t\t} catch (error) {\n\t\t\tif (!notFound(error)) throw error;\n\t\t\tthis.etags.set(stage, null);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Replace the stage's secrets — on the condition that they are still what\n\t * this store last read. A stage never read here is replaced as it is now.\n\t *\n\t * @throws {StageSecretsChanged} when another run wrote them in between\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * write it with, or they have expired\n\t */\n\tasync write(stage: string, secrets: StageSecrets): Promise<void> {\n\t\tconst { s3, bucket } = await this.use(stage, true);\n\t\tconst Bucket = bucket!;\n\t\tconst Key = this.key(stage);\n\t\tconst expected = this.etags.has(stage)\n\t\t\t? (this.etags.get(stage) ?? null)\n\t\t\t: await this.currentEtag(s3, stage, Bucket, Key);\n\n\t\ttry {\n\t\t\tconst { ETag } = await this.call(stage, 'write', () =>\n\t\t\t\ts3.send(\n\t\t\t\t\tnew PutObjectCommand({\n\t\t\t\t\t\tBucket,\n\t\t\t\t\t\tKey,\n\t\t\t\t\t\tBody: JSON.stringify(secrets),\n\t\t\t\t\t\tContentType: 'application/json',\n\t\t\t\t\t\tServerSideEncryption: 'AES256',\n\t\t\t\t\t\t...(expected === null\n\t\t\t\t\t\t\t? { IfNoneMatch: '*' }\n\t\t\t\t\t\t\t: { IfMatch: expected }),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\t\t\tthis.remember(stage, ETag);\n\t\t} catch (error) {\n\t\t\tif (lostRace(error)) {\n\t\t\t\tthis.etags.delete(stage);\n\t\t\t\tthrow new StageSecretsChanged(stage, `s3://${Bucket}/${Key}`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * The ETag the stage is now at. Some S3-compatible servers answer without\n\t * one: then nothing is remembered, and the next write asks for it first.\n\t */\n\tprivate remember(stage: string, etag: string | undefined): void {\n\t\tif (etag) this.etags.set(stage, etag);\n\t\telse this.etags.delete(stage);\n\t}\n\n\tprivate async currentEtag(\n\t\ts3: S3Client,\n\t\tstage: string,\n\t\tBucket: string,\n\t\tKey: string,\n\t): Promise<string | null> {\n\t\ttry {\n\t\t\tconst { ETag } = await this.call(stage, 'write', () =>\n\t\t\t\ts3.send(new HeadObjectCommand({ Bucket, Key })),\n\t\t\t);\n\t\t\treturn ETag ?? null;\n\t\t} catch (error) {\n\t\t\tif (notFound(error)) return null;\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,sBAAb,cAAyC,SAAS;CAEvC;CAEA;CAHV,YACC,OAEA,UACC;EACD,MACC,0BAA0B,MAAM,OAAO,SAAS,4KAGjD;EARS,KAAA,QAAA;EAEA,KAAA,WAAA;EAOT,KAAK,OAAO;CACb;AACD;;AAQA,SAAS,SAAS,OAAyB;CAC1C,MAAM,EAAE,MAAM,cAAc;CAC5B,OACC,SAAS,wBACT,SAAS,gCACT,WAAW,mBAAmB,OAC9B,WAAW,mBAAmB;AAEhC;AAEA,SAAS,SAAS,OAAyB;CAC1C,MAAM,EAAE,MAAM,cAAc;C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K,IAAI,OAAO,IAAI;EACjD,MAAM,SAAS;EACf,MAAM,MAAM,KAAK,IAAI,KAAK;EAC1B,MAAM,WAAW,KAAK,MAAM,IAAI,KAAK,IACjC,KAAK,MAAM,IAAI,KAAK,KAAK,OAC1B,MAAM,KAAK,YAAY,IAAI,OAAO,QAAQ,GAAG;EAEhD,IAAI;GACH,MAAM,EAAE,SAAS,MAAM,KAAK,KAAK,OAAO,eACvC,GAAG,KACF,IAAI,iBAAiB;IACpB;IACA;IACA,MAAM,KAAK,UAAU,OAAO;IAC5B,aAAa;IACb,sBAAsB;IACtB,GAAI,aAAa,OACd,EAAE,aAAa,IAAI,IACnB,EAAE,SAAS,SAAS;GACxB,CAAC,CACF,CACD;GACA,KAAK,SAAS,OAAO,IAAI;EAC1B,SAAS,OAAO;GACf,IAAI,SAAS,KAAK,GAAG;IACpB,KAAK,MAAM,OAAO,KAAK;IACvB,MAAM,IAAI,oBAAoB,OAAO,QAAQ,OAAO,GAAG,KAAK;GAC7D;GACA,MAAM;EACP;CACD;;;;;CAMA,SAAiB,OAAe,MAAgC;EAC/D,IAAI,MAAM,KAAK,MAAM,IAAI,OAAO,IAAI;OAC/B,KAAK,MAAM,OAAO,KAAK;CAC7B;CAEA,MAAc,YACb,IACA,OACA,QACA,KACyB;EACzB,IAAI;GACH,MAAM,EAAE,SAAS,MAAM,KAAK,KAAK,OAAO,eACvC,GAAG,KAAK,IAAI,kBAAkB;IAAE;IAAQ;GAAI,CAAC,CAAC,CAC/C;GACA,OAAO,QAAQ;EAChB,SAAS,OAAO;GACf,IAAI,SAAS,KAAK,GAAG,OAAO;GAC5B,MAAM;EACP;CACD;AACD"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
const require_errors = require("./errors-DMC4Umsb.cjs");
|
|
2
|
+
const require_workspace = require("./workspace-DRjdu1OY.cjs");
|
|
3
|
+
const require_projectBucket = require("./projectBucket-CDu5rXjp.cjs");
|
|
4
|
+
const require_awsStore = require("./awsStore-u3ehhMoY.cjs");
|
|
5
|
+
let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
|
|
6
|
+
let _aws_sdk_client_sts = require("@aws-sdk/client-sts");
|
|
7
|
+
//#region src/secrets/s3.ts
|
|
8
|
+
/**
|
|
9
|
+
* A stage's secrets in S3: one object per stage,
|
|
10
|
+
* `<prefix>/<project>/<stage>/secrets.json`, in the project bucket beside the
|
|
11
|
+
* deploy state (`providers/projectBucket.ts`) — or in a bucket the config
|
|
12
|
+
* names, which must exist.
|
|
13
|
+
*
|
|
14
|
+
* Encrypted at rest with SSE-S3, asked for on every write although the
|
|
15
|
+
* project bucket defaults to it, so no KMS key is another place to keep. The
|
|
16
|
+
* bucket's versioning keeps every past document. Unlike an SSM parameter
|
|
17
|
+
* there is no size to outgrow.
|
|
18
|
+
*
|
|
19
|
+
* The project bucket is created by the first write, never by a read: a stage
|
|
20
|
+
* whose bucket or object does not exist yet has no secrets. Every write is
|
|
21
|
+
* conditional — `If-Match` on the ETag this store last read for the stage,
|
|
22
|
+
* `If-None-Match: *` when it read none — so two `secrets:set` runs at once
|
|
23
|
+
* cannot each overwrite the other's key: the second is refused with
|
|
24
|
+
* {@link StageSecretsChanged}.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Another run wrote the stage's secrets after this one read them. Nothing was
|
|
28
|
+
* written: the change is to be made again, on top of theirs.
|
|
29
|
+
*/
|
|
30
|
+
var StageSecretsChanged = class extends require_errors.GkmError {
|
|
31
|
+
stage;
|
|
32
|
+
location;
|
|
33
|
+
constructor(stage, location) {
|
|
34
|
+
super(`The secrets for stage "${stage}" at ${location} changed after this command read them — another secrets command or deploy wrote them first. Nothing was written; run the command again to make the change on top of theirs.`);
|
|
35
|
+
this.stage = stage;
|
|
36
|
+
this.location = location;
|
|
37
|
+
this.name = "StageSecretsChanged";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/** A conditional write that lost: the object is not what the write assumed. */
|
|
41
|
+
function lostRace(error) {
|
|
42
|
+
const { name, $metadata } = error;
|
|
43
|
+
return name === "PreconditionFailed" || name === "ConditionalRequestConflict" || $metadata?.httpStatusCode === 412 || $metadata?.httpStatusCode === 409;
|
|
44
|
+
}
|
|
45
|
+
function notFound(error) {
|
|
46
|
+
const { name, $metadata } = error;
|
|
47
|
+
return name === "NoSuchKey" || name === "NotFound" || $metadata?.httpStatusCode === 404;
|
|
48
|
+
}
|
|
49
|
+
var S3SecretsStore = class {
|
|
50
|
+
options;
|
|
51
|
+
name = "s3";
|
|
52
|
+
clients;
|
|
53
|
+
/** The bucket's name, once known. */
|
|
54
|
+
bucketName;
|
|
55
|
+
/** Whether the bucket is known to exist. */
|
|
56
|
+
exists = false;
|
|
57
|
+
/** The ETag each stage was last read at — null: read, and not there. */
|
|
58
|
+
etags = /* @__PURE__ */ new Map();
|
|
59
|
+
constructor(options) {
|
|
60
|
+
this.options = options;
|
|
61
|
+
if (options.bucket) {
|
|
62
|
+
this.bucketName = options.bucket;
|
|
63
|
+
this.exists = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The bucket's name; the project bucket's is known after the first call. */
|
|
67
|
+
get bucket() {
|
|
68
|
+
return this.bucketName ?? require_projectBucket.projectBucketName(this.options.identity.scope, "<account id>");
|
|
69
|
+
}
|
|
70
|
+
/** Where a stage's secrets are kept: `s3://<bucket>/<key>`. */
|
|
71
|
+
location(stage) {
|
|
72
|
+
return `s3://${this.bucket}/${this.key(stage)}`;
|
|
73
|
+
}
|
|
74
|
+
key(stage) {
|
|
75
|
+
return require_workspace.s3SecretsKey(this.options.prefix, this.options.project, stage);
|
|
76
|
+
}
|
|
77
|
+
async client() {
|
|
78
|
+
if (this.clients) return this.clients;
|
|
79
|
+
const base = await require_awsStore.awsClientConfig(this.options);
|
|
80
|
+
const endpoint = base.endpoint ?? process.env.AWS_ENDPOINT_URL_S3 ?? process.env.AWS_ENDPOINT_URL;
|
|
81
|
+
const credentials = this.options.credentials ?? base.credentials;
|
|
82
|
+
this.clients = {
|
|
83
|
+
s3: new _aws_sdk_client_s3.S3Client({
|
|
84
|
+
region: base.region,
|
|
85
|
+
...endpoint ? {
|
|
86
|
+
endpoint,
|
|
87
|
+
forcePathStyle: true
|
|
88
|
+
} : {},
|
|
89
|
+
...credentials ? { credentials } : {}
|
|
90
|
+
}),
|
|
91
|
+
sts: new _aws_sdk_client_sts.STSClient({
|
|
92
|
+
region: base.region,
|
|
93
|
+
...base.endpoint ? { endpoint: base.endpoint } : {},
|
|
94
|
+
...credentials ? { credentials } : {}
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
return this.clients;
|
|
98
|
+
}
|
|
99
|
+
/** One AWS call, a missing or expired credential refused by name. */
|
|
100
|
+
call(stage, access, run) {
|
|
101
|
+
return require_awsStore.withStageCredentials({
|
|
102
|
+
stage,
|
|
103
|
+
store: this.name,
|
|
104
|
+
profile: this.options.profile,
|
|
105
|
+
access
|
|
106
|
+
}, run);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The bucket, or null for a project bucket that does not exist yet and is
|
|
110
|
+
* not to be created (a read).
|
|
111
|
+
*/
|
|
112
|
+
async use(stage, create) {
|
|
113
|
+
const { s3, sts } = await this.client();
|
|
114
|
+
if (this.exists) return {
|
|
115
|
+
s3,
|
|
116
|
+
bucket: this.bucketName
|
|
117
|
+
};
|
|
118
|
+
const access = create ? "write" : "read";
|
|
119
|
+
this.bucketName ??= require_projectBucket.projectBucketName(this.options.identity.scope, await this.call(stage, access, () => require_projectBucket.callerAccountId(sts)));
|
|
120
|
+
const bucket = this.bucketName;
|
|
121
|
+
if (create) await this.call(stage, access, () => require_projectBucket.ensureProjectBucket(s3, {
|
|
122
|
+
bucket,
|
|
123
|
+
region: this.options.region,
|
|
124
|
+
identity: this.options.identity
|
|
125
|
+
}));
|
|
126
|
+
else if (await this.call(stage, access, () => require_projectBucket.findProjectBucket(s3, bucket)) === "none") return {
|
|
127
|
+
s3,
|
|
128
|
+
bucket: null
|
|
129
|
+
};
|
|
130
|
+
this.exists = true;
|
|
131
|
+
return {
|
|
132
|
+
s3,
|
|
133
|
+
bucket
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @throws {StageSecretsUnreadable} when there are no AWS credentials to
|
|
138
|
+
* read it with, or they have expired
|
|
139
|
+
*/
|
|
140
|
+
async read(stage) {
|
|
141
|
+
const { s3, bucket } = await this.use(stage, false);
|
|
142
|
+
if (!bucket) {
|
|
143
|
+
this.etags.set(stage, null);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const response = await this.call(stage, "read", () => s3.send(new _aws_sdk_client_s3.GetObjectCommand({
|
|
148
|
+
Bucket: bucket,
|
|
149
|
+
Key: this.key(stage)
|
|
150
|
+
})));
|
|
151
|
+
const body = await response.Body.transformToString("utf-8");
|
|
152
|
+
this.remember(stage, response.ETag);
|
|
153
|
+
return JSON.parse(body);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!notFound(error)) throw error;
|
|
156
|
+
this.etags.set(stage, null);
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Replace the stage's secrets — on the condition that they are still what
|
|
162
|
+
* this store last read. A stage never read here is replaced as it is now.
|
|
163
|
+
*
|
|
164
|
+
* @throws {StageSecretsChanged} when another run wrote them in between
|
|
165
|
+
* @throws {StageSecretsUnreadable} when there are no AWS credentials to
|
|
166
|
+
* write it with, or they have expired
|
|
167
|
+
*/
|
|
168
|
+
async write(stage, secrets) {
|
|
169
|
+
const { s3, bucket } = await this.use(stage, true);
|
|
170
|
+
const Bucket = bucket;
|
|
171
|
+
const Key = this.key(stage);
|
|
172
|
+
const expected = this.etags.has(stage) ? this.etags.get(stage) ?? null : await this.currentEtag(s3, stage, Bucket, Key);
|
|
173
|
+
try {
|
|
174
|
+
const { ETag } = await this.call(stage, "write", () => s3.send(new _aws_sdk_client_s3.PutObjectCommand({
|
|
175
|
+
Bucket,
|
|
176
|
+
Key,
|
|
177
|
+
Body: JSON.stringify(secrets),
|
|
178
|
+
ContentType: "application/json",
|
|
179
|
+
ServerSideEncryption: "AES256",
|
|
180
|
+
...expected === null ? { IfNoneMatch: "*" } : { IfMatch: expected }
|
|
181
|
+
})));
|
|
182
|
+
this.remember(stage, ETag);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (lostRace(error)) {
|
|
185
|
+
this.etags.delete(stage);
|
|
186
|
+
throw new StageSecretsChanged(stage, `s3://${Bucket}/${Key}`);
|
|
187
|
+
}
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The ETag the stage is now at. Some S3-compatible servers answer without
|
|
193
|
+
* one: then nothing is remembered, and the next write asks for it first.
|
|
194
|
+
*/
|
|
195
|
+
remember(stage, etag) {
|
|
196
|
+
if (etag) this.etags.set(stage, etag);
|
|
197
|
+
else this.etags.delete(stage);
|
|
198
|
+
}
|
|
199
|
+
async currentEtag(s3, stage, Bucket, Key) {
|
|
200
|
+
try {
|
|
201
|
+
const { ETag } = await this.call(stage, "write", () => s3.send(new _aws_sdk_client_s3.HeadObjectCommand({
|
|
202
|
+
Bucket,
|
|
203
|
+
Key
|
|
204
|
+
})));
|
|
205
|
+
return ETag ?? null;
|
|
206
|
+
} catch (error) {
|
|
207
|
+
if (notFound(error)) return null;
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
//#endregion
|
|
213
|
+
exports.S3SecretsStore = S3SecretsStore;
|
|
214
|
+
|
|
215
|
+
//# sourceMappingURL=s3-DLp0V-Ox.cjs.map
|