@geek-fun/serverlessinsight 0.8.2 → 0.8.3
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/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +14 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +14 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +348 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +14 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +114 -0
- package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
- package/README.md +26 -18
- package/README.zh-CN.md +19 -6
- package/dist/package.json +3 -1
- package/dist/src/commands/deploy.js +87 -4
- package/dist/src/commands/destroy.js +61 -10
- package/dist/src/commands/forceUnlock.js +8 -0
- package/dist/src/commands/index.js +34 -2
- package/dist/src/commands/login.js +195 -0
- package/dist/src/commands/logout.js +17 -0
- package/dist/src/commands/show.js +15 -7
- package/dist/src/commands/whoami.js +20 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +327 -30
- package/dist/src/common/aliyunClient/esOperations.js +43 -29
- package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
- package/dist/src/common/aliyunClient/ossOperations.js +165 -13
- package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
- package/dist/src/common/aliyunClient/slsOperations.js +56 -26
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +9 -4
- package/dist/src/common/credentialStore.js +94 -0
- package/dist/src/common/credentials.js +2 -0
- package/dist/src/common/eventQueue.js +208 -0
- package/dist/src/common/hashUtils.js +87 -11
- package/dist/src/common/imsClient.js +1 -0
- package/dist/src/common/index.js +3 -0
- package/dist/src/common/lockManager.js +61 -54
- package/dist/src/common/logger.js +2 -0
- package/dist/src/common/polling.js +54 -0
- package/dist/src/common/reportResourceEvent.js +8 -0
- package/dist/src/common/runtimeMapper.js +11 -12
- package/dist/src/common/stateBackend/index.js +10 -1
- package/dist/src/common/stateBackend/localStateBackend.js +4 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +6 -3
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +135 -13
- package/dist/src/common/tencentClient/cosOperations.js +180 -3
- package/dist/src/common/tencentClient/esOperations.js +110 -46
- package/dist/src/common/tencentClient/index.js +22 -1
- package/dist/src/common/tencentClient/scfOperations.js +255 -133
- package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
- package/dist/src/common/triggerMapper.js +36 -0
- package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
- package/dist/src/common/volcengineClient/iamOperations.js +58 -48
- package/dist/src/common/volcengineClient/index.js +46 -21
- package/dist/src/common/volcengineClient/stsOperations.js +32 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +229 -178
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +84 -0
- package/dist/src/lang/zh-CN.js +84 -0
- package/dist/src/parser/eventParser.js +2 -0
- package/dist/src/parser/functionParser.js +96 -65
- package/dist/src/parser/index.js +7 -4
- package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +14 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +216 -124
- package/dist/src/stack/aliyunStack/apigwTypes.js +16 -3
- package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
- package/dist/src/stack/aliyunStack/deployer.js +2 -2
- package/dist/src/stack/aliyunStack/destroyer.js +2 -2
- package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +327 -64
- package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +267 -219
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
- package/dist/src/stack/alreadyExists.js +26 -0
- package/dist/src/stack/ownershipTag.js +40 -0
- package/dist/src/stack/rfsStack/index.js +3 -1
- package/dist/src/stack/scfStack/cosExecutor.js +39 -1
- package/dist/src/stack/scfStack/cosPlanner.js +11 -1
- package/dist/src/stack/scfStack/cosResource.js +167 -64
- package/dist/src/stack/scfStack/deployer.js +2 -2
- package/dist/src/stack/scfStack/destroyer.js +2 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
- package/dist/src/stack/scfStack/scfExecutor.js +39 -1
- package/dist/src/stack/scfStack/scfPlanner.js +12 -2
- package/dist/src/stack/scfStack/scfResource.js +484 -14
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
- package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
- package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
- package/dist/src/stack/volcengineStack/apigwResource.js +418 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +76 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +1 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
- package/dist/src/stack/volcengineStack/tosResource.js +82 -27
- package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +71 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +148 -98
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
- package/dist/src/types/domains/backend.js +1 -0
- package/dist/src/types/domains/state.js +29 -1
- package/dist/src/validator/eventSchema.js +10 -0
- package/dist/src/validator/functionSchema.js +37 -12
- package/dist/src/validator/iacSchema.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
|
@@ -32,9 +32,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
39
|
exports.deploy = void 0;
|
|
37
40
|
const readline = __importStar(require("node:readline"));
|
|
41
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
38
42
|
const stack_1 = require("../stack");
|
|
39
43
|
const common_1 = require("../common");
|
|
40
44
|
const stateBackend_1 = require("../common/stateBackend");
|
|
@@ -74,7 +78,12 @@ const deploy = async (options) => {
|
|
|
74
78
|
const context = (0, common_1.getContext)();
|
|
75
79
|
const iac = (0, parser_1.revalYaml)(iacLocation, context);
|
|
76
80
|
(0, common_1.setIac)(iac);
|
|
77
|
-
const backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
|
|
81
|
+
const backend = (0, stateBackend_1.createStateBackend)(iac.backend, { ...context, siApiKey: options.siApiKey });
|
|
82
|
+
// ADR-005: wire the backend's event reporter into the global context so
|
|
83
|
+
// executors can emit per-resource deployment events via context.reportEvent.
|
|
84
|
+
if (backend.reportEvent) {
|
|
85
|
+
context.reportEvent = backend.reportEvent;
|
|
86
|
+
}
|
|
78
87
|
common_1.logger.info(lang_1.lang.__('GENERATING_PLAN'));
|
|
79
88
|
let planResult;
|
|
80
89
|
if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
|
|
@@ -101,9 +110,83 @@ const deploy = async (options) => {
|
|
|
101
110
|
}
|
|
102
111
|
common_1.logger.info(lang_1.lang.__('DEPLOYING_STACK'));
|
|
103
112
|
common_1.logger.info(lang_1.lang.__('ACQUIRING_LOCK'));
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
// Release the active lock on SIGINT/SIGTERM so Ctrl+C doesn't leave a stale
|
|
114
|
+
// lock behind. Best-effort: the local backend release is synchronous (unlink)
|
|
115
|
+
// and completes before exit; remote backends may be cut short, and their lock
|
|
116
|
+
// is then recovered via the stale/dead-PID detection path.
|
|
117
|
+
const activeSignals = ['SIGINT', 'SIGTERM'];
|
|
118
|
+
const signalHandlers = new Map();
|
|
119
|
+
let currentLockId = null;
|
|
120
|
+
let released = false;
|
|
121
|
+
const releaseOnSignal = () => {
|
|
122
|
+
if (released)
|
|
123
|
+
return;
|
|
124
|
+
released = true;
|
|
125
|
+
if (currentLockId) {
|
|
126
|
+
void backend.releaseLock(currentLockId).catch(() => {
|
|
127
|
+
// best-effort release — ignore failures on the exit path
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// ADR-005: drain any buffered deployment events before exiting so the
|
|
131
|
+
// console timeline is as complete as possible even on Ctrl+C.
|
|
132
|
+
const flushPromise = backend.flushEvents?.();
|
|
133
|
+
if (flushPromise) {
|
|
134
|
+
void flushPromise.finally(() => process.exit(130));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
process.exit(130);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
for (const sig of activeSignals) {
|
|
141
|
+
const handler = () => releaseOnSignal();
|
|
142
|
+
process.on(sig, handler);
|
|
143
|
+
signalHandlers.set(sig, handler);
|
|
144
|
+
}
|
|
145
|
+
// ADR-005: replay event-queue files orphaned by a previous interrupted run.
|
|
146
|
+
await backend.replayOrphanedEvents?.();
|
|
147
|
+
try {
|
|
148
|
+
await backend.withLock('deploy', async () => {
|
|
149
|
+
try {
|
|
150
|
+
await (0, stack_1.deployStack)(iac, backend);
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
// The deployment FAILED, but the console still needs the plan
|
|
154
|
+
// (what we attempted) + the partial state (what succeeded) to render
|
|
155
|
+
// a meaningful Changes / State JSON / error view. Attach them to the
|
|
156
|
+
// error; withLock's fail branch forwards them.
|
|
157
|
+
const failure = err;
|
|
158
|
+
try {
|
|
159
|
+
const partialState = await backend.loadState(iac.provider.name, iac.app, iac.service, options.stage ?? 'dev');
|
|
160
|
+
failure.stateJson = partialState ?? {};
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// state may be unreadable mid-failure — plan alone is still useful
|
|
164
|
+
}
|
|
165
|
+
failure.plan = { items: planResult.items };
|
|
166
|
+
throw failure;
|
|
167
|
+
}
|
|
168
|
+
// Read back the final state so the deployment record can link it
|
|
169
|
+
// (console shows Changes + State JSON from the plan and state).
|
|
170
|
+
const finalState = await backend.loadState(iac.provider.name, iac.app, iac.service, options.stage ?? 'dev');
|
|
171
|
+
return {
|
|
172
|
+
plan: { items: planResult.items },
|
|
173
|
+
stateJson: finalState ?? {},
|
|
174
|
+
contentHash: node_crypto_1.default
|
|
175
|
+
.createHash('sha256')
|
|
176
|
+
.update(JSON.stringify(finalState ?? {}))
|
|
177
|
+
.digest('hex'),
|
|
178
|
+
resourceCount: Object.keys(finalState?.resources ?? {}).length,
|
|
179
|
+
};
|
|
180
|
+
}, {}, (lockId) => {
|
|
181
|
+
currentLockId = lockId;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
for (const [sig, handler] of signalHandlers) {
|
|
186
|
+
process.removeListener(sig, handler);
|
|
187
|
+
}
|
|
188
|
+
signalHandlers.clear();
|
|
189
|
+
}
|
|
107
190
|
common_1.logger.info(lang_1.lang.__('STACK_DEPLOYED'));
|
|
108
191
|
};
|
|
109
192
|
exports.deploy = deploy;
|
|
@@ -27,19 +27,70 @@ const destroyStack = async (options) => {
|
|
|
27
27
|
region: context.region,
|
|
28
28
|
}));
|
|
29
29
|
const backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
// Initialize backend stage/deployment context before withLock. SaaS backends
|
|
31
|
+
// need loadState() to provision the deployment and set the active stage.
|
|
32
|
+
await backend.loadState(iac.provider.name, context.app, context.service, context.stage);
|
|
33
|
+
// ADR-005: wire the backend's event reporter into the global context so
|
|
34
|
+
// executors can emit per-resource deployment events via context.reportEvent.
|
|
35
|
+
if (backend.reportEvent) {
|
|
36
|
+
context.reportEvent = backend.reportEvent;
|
|
37
|
+
}
|
|
38
|
+
// Release the active lock on SIGINT/SIGTERM so Ctrl+C doesn't leave a stale
|
|
39
|
+
// lock behind. Best-effort: the local backend release is synchronous (unlink)
|
|
40
|
+
// and completes before exit; remote backends may be cut short, and their lock
|
|
41
|
+
// is then recovered via the stale/dead-PID detection path.
|
|
42
|
+
const activeSignals = ['SIGINT', 'SIGTERM'];
|
|
43
|
+
const signalHandlers = new Map();
|
|
44
|
+
let currentLockId = null;
|
|
45
|
+
let released = false;
|
|
46
|
+
const releaseOnSignal = () => {
|
|
47
|
+
if (released)
|
|
48
|
+
return;
|
|
49
|
+
released = true;
|
|
50
|
+
if (currentLockId) {
|
|
51
|
+
void backend.releaseLock(currentLockId).catch(() => {
|
|
52
|
+
// best-effort release — ignore failures on the exit path
|
|
53
|
+
});
|
|
33
54
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
await (0, volcengineStack_1.destroyVolcengineStack)(backend);
|
|
55
|
+
// ADR-005: drain buffered deployment events before exiting.
|
|
56
|
+
const flushPromise = backend.flushEvents?.();
|
|
57
|
+
if (flushPromise) {
|
|
58
|
+
void flushPromise.finally(() => process.exit(130));
|
|
39
59
|
}
|
|
40
60
|
else {
|
|
41
|
-
|
|
61
|
+
process.exit(130);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
for (const sig of activeSignals) {
|
|
65
|
+
const handler = () => releaseOnSignal();
|
|
66
|
+
process.on(sig, handler);
|
|
67
|
+
signalHandlers.set(sig, handler);
|
|
68
|
+
}
|
|
69
|
+
// ADR-005: replay event-queue files orphaned by a previous interrupted run.
|
|
70
|
+
await backend.replayOrphanedEvents?.();
|
|
71
|
+
try {
|
|
72
|
+
await backend.withLock('destroy', async () => {
|
|
73
|
+
if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
|
|
74
|
+
await (0, scfStack_1.destroyTencentStack)(backend);
|
|
75
|
+
}
|
|
76
|
+
else if (iac.provider.name === common_1.ProviderEnum.ALIYUN) {
|
|
77
|
+
await (0, aliyunStack_1.destroyAliyunStack)(backend);
|
|
78
|
+
}
|
|
79
|
+
else if (iac.provider.name === common_1.ProviderEnum.VOLCENGINE) {
|
|
80
|
+
await (0, volcengineStack_1.destroyVolcengineStack)(backend);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new Error(`Unsupported provider: ${iac.provider.name}`);
|
|
84
|
+
}
|
|
85
|
+
}, {}, (lockId) => {
|
|
86
|
+
currentLockId = lockId;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
for (const [sig, handler] of signalHandlers) {
|
|
91
|
+
process.removeListener(sig, handler);
|
|
42
92
|
}
|
|
43
|
-
|
|
93
|
+
signalHandlers.clear();
|
|
94
|
+
}
|
|
44
95
|
};
|
|
45
96
|
exports.destroyStack = destroyStack;
|
|
@@ -9,6 +9,8 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const common_1 = require("../common");
|
|
11
11
|
const stateBackend_1 = require("../common/stateBackend");
|
|
12
|
+
const types_1 = require("../types");
|
|
13
|
+
const credentialStore_1 = require("../common/credentialStore");
|
|
12
14
|
const constants_1 = require("../common/constants");
|
|
13
15
|
const lockManager_1 = require("../common/lockManager");
|
|
14
16
|
const lang_1 = require("../lang");
|
|
@@ -39,6 +41,12 @@ const forceUnlockCommand = async (lockId, options = {}) => {
|
|
|
39
41
|
}, false);
|
|
40
42
|
const context = (0, common_1.getContext)();
|
|
41
43
|
const iac = (0, parser_1.revalYaml)(iacLocation, context);
|
|
44
|
+
if (!iac.backend || iac.backend.type === types_1.StateBackendType.SAAS) {
|
|
45
|
+
common_1.logger.info(lang_1.lang.__('SAAS_FORCE_UNLOCK_NOT_SUPPORTED', {
|
|
46
|
+
consoleUrl: (0, credentialStore_1.getConsoleUrl)(),
|
|
47
|
+
}));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
42
50
|
backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
|
|
43
51
|
}
|
|
44
52
|
else {
|
|
@@ -10,8 +10,19 @@ const local_1 = require("./local");
|
|
|
10
10
|
const plan_1 = require("./plan");
|
|
11
11
|
const forceUnlock_1 = require("./forceUnlock");
|
|
12
12
|
const show_1 = require("./show");
|
|
13
|
+
const login_1 = require("./login");
|
|
14
|
+
const logout_1 = require("./logout");
|
|
15
|
+
const whoami_1 = require("./whoami");
|
|
13
16
|
const lang_1 = require("../lang");
|
|
14
17
|
const parser_1 = require("../parser");
|
|
18
|
+
const MAX_ERROR_MESSAGE_LENGTH = 2000;
|
|
19
|
+
const truncateErrorMessage = (message) => {
|
|
20
|
+
if (!message)
|
|
21
|
+
return '';
|
|
22
|
+
return message.length > MAX_ERROR_MESSAGE_LENGTH
|
|
23
|
+
? `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH)}… (truncated ${message.length} chars)`
|
|
24
|
+
: message;
|
|
25
|
+
};
|
|
15
26
|
// Global error handler
|
|
16
27
|
const handleCommandError = (error, commandName) => {
|
|
17
28
|
// Skip logging if already logged by handlePartialFailure
|
|
@@ -19,7 +30,7 @@ const handleCommandError = (error, commandName) => {
|
|
|
19
30
|
// Log error message as string to preserve newlines
|
|
20
31
|
common_1.logger.error(lang_1.lang.__('COMMAND_FAILED', {
|
|
21
32
|
commandName,
|
|
22
|
-
error: error?.message || 'Unknown error occurred',
|
|
33
|
+
error: truncateErrorMessage(error?.message) || 'Unknown error occurred',
|
|
23
34
|
}));
|
|
24
35
|
}
|
|
25
36
|
if (error?.stack && process.env.DEBUG) {
|
|
@@ -56,6 +67,25 @@ const actionWrapper = (commandName, handler) => {
|
|
|
56
67
|
};
|
|
57
68
|
const program = new commander_1.Command();
|
|
58
69
|
program.name('si').description('CLI for ServerlessInsight').version((0, common_1.getVersion)());
|
|
70
|
+
program
|
|
71
|
+
.command('login')
|
|
72
|
+
.description('authenticate with ServerlessInsight Console')
|
|
73
|
+
.option('--si-api-key <key>', 'authenticate with an existing API key')
|
|
74
|
+
.action(actionWrapper('login', async ({ siApiKey }) => {
|
|
75
|
+
await (0, login_1.login)({ siApiKey });
|
|
76
|
+
}));
|
|
77
|
+
program
|
|
78
|
+
.command('logout')
|
|
79
|
+
.description('revoke API key and clear local credentials')
|
|
80
|
+
.action(actionWrapper('logout', async () => {
|
|
81
|
+
await (0, logout_1.logout)();
|
|
82
|
+
}));
|
|
83
|
+
program
|
|
84
|
+
.command('whoami')
|
|
85
|
+
.description('show current login status')
|
|
86
|
+
.action(actionWrapper('whoami', async () => {
|
|
87
|
+
await (0, whoami_1.whoami)();
|
|
88
|
+
}));
|
|
59
89
|
program
|
|
60
90
|
.command('show')
|
|
61
91
|
.description('show deployed resources from state')
|
|
@@ -117,13 +147,14 @@ program
|
|
|
117
147
|
.option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
|
|
118
148
|
.option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
|
|
119
149
|
.option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
|
|
150
|
+
.option('--si-api-key <key>', 'ServerlessInsight API key (overrides SI_API_KEY env)')
|
|
120
151
|
.option('-y, --auto-approve', 'skip interactive approval of plan before deploying')
|
|
121
152
|
.option('-p, --parameter <key=value>', 'override parameters', (value, previous) => {
|
|
122
153
|
const [key, val] = value.split('=');
|
|
123
154
|
previous[key] = val;
|
|
124
155
|
return previous;
|
|
125
156
|
}, {})
|
|
126
|
-
.action(actionWrapper('deploy', async ({ stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken, autoApprove, }) => {
|
|
157
|
+
.action(actionWrapper('deploy', async ({ stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken, siApiKey, autoApprove, }) => {
|
|
127
158
|
await (0, deploy_1.deploy)({
|
|
128
159
|
stage,
|
|
129
160
|
parameters: parameter,
|
|
@@ -133,6 +164,7 @@ program
|
|
|
133
164
|
accessKeyId,
|
|
134
165
|
accessKeySecret,
|
|
135
166
|
securityToken,
|
|
167
|
+
siApiKey,
|
|
136
168
|
autoApprove,
|
|
137
169
|
});
|
|
138
170
|
}));
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.login = void 0;
|
|
40
|
+
const readline = __importStar(require("node:readline"));
|
|
41
|
+
const node_http_1 = require("node:http");
|
|
42
|
+
const open_1 = __importDefault(require("open"));
|
|
43
|
+
const common_1 = require("../common");
|
|
44
|
+
const apiClient_1 = require("../common/apiClient");
|
|
45
|
+
const credentialStore_1 = require("../common/credentialStore");
|
|
46
|
+
const lang_1 = require("../lang");
|
|
47
|
+
const ask = (query) => {
|
|
48
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
rl.question(query, (answer) => {
|
|
51
|
+
rl.close();
|
|
52
|
+
resolve(answer);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const loginWithKey = async (apiKey, consoleUrl) => {
|
|
57
|
+
if (!(0, credentialStore_1.validateApiKeyFormat)(apiKey)) {
|
|
58
|
+
common_1.logger.error(lang_1.lang.__('LOGIN_KEY_FORMAT_INVALID'));
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
common_1.logger.info(lang_1.lang.__('LOGIN_VALIDATING_KEY'));
|
|
62
|
+
try {
|
|
63
|
+
const result = await (0, apiClient_1.validateApiKey)(apiKey, consoleUrl);
|
|
64
|
+
(0, credentialStore_1.saveCredentials)({
|
|
65
|
+
apiKey,
|
|
66
|
+
consoleUrl,
|
|
67
|
+
orgId: result.orgId,
|
|
68
|
+
orgName: result.orgName,
|
|
69
|
+
userEmail: result.userEmail,
|
|
70
|
+
});
|
|
71
|
+
common_1.logger.info(lang_1.lang.__('LOGIN_SUCCESS_KEY', { orgName: result.orgName }));
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
common_1.logger.error(lang_1.lang.__('LOGIN_KEY_INVALID'));
|
|
76
|
+
common_1.logger.debug(error instanceof Error ? error.message : String(error));
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const loginWithBrowser = async (consoleUrl) => {
|
|
81
|
+
const randomPort = Math.floor(Math.random() * 79) + 54321; // 54321-54399
|
|
82
|
+
let apiKey = null;
|
|
83
|
+
common_1.logger.info(lang_1.lang.__('LOGIN_STARTING_SERVER'));
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
const uiUrl = (0, credentialStore_1.resolveConsoleUiUrl)({ consoleUrl });
|
|
86
|
+
const server = (0, node_http_1.createServer)(async (req, res) => {
|
|
87
|
+
if (!req.url)
|
|
88
|
+
return;
|
|
89
|
+
const url = new URL(req.url, `http://127.0.0.1:${randomPort}`);
|
|
90
|
+
const key = url.searchParams.get('api_key');
|
|
91
|
+
if (key && url.pathname === '/callback') {
|
|
92
|
+
apiKey = key;
|
|
93
|
+
const appId = url.searchParams.get('app_id') ?? '';
|
|
94
|
+
const target = appId ? `${uiUrl}/${appId}/membership/api-keys` : uiUrl;
|
|
95
|
+
const escapedTarget = target
|
|
96
|
+
.replace(/&/g, '&')
|
|
97
|
+
.replace(/"/g, '"')
|
|
98
|
+
.replace(/</g, '<')
|
|
99
|
+
.replace(/>/g, '>');
|
|
100
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
101
|
+
res.end(`<!DOCTYPE html>
|
|
102
|
+
<html lang="en">
|
|
103
|
+
<head>
|
|
104
|
+
<meta charset="utf-8" />
|
|
105
|
+
<title>Authorization received</title>
|
|
106
|
+
<meta http-equiv="refresh" content="3; url=${escapedTarget}" />
|
|
107
|
+
</head>
|
|
108
|
+
<body style="font-family: system-ui, sans-serif; display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0; background: #fafafa;">
|
|
109
|
+
<div style="text-align: center; padding: 24px;">
|
|
110
|
+
<h1 style="font-size: 20px; margin-bottom: 8px;">Authorization received ✅</h1>
|
|
111
|
+
<p style="color: #666; font-size: 14px;">You may close this window.</p>
|
|
112
|
+
<p style="color: #666; font-size: 13px; margin-top: 16px;">
|
|
113
|
+
Redirecting to Console in 3 seconds...
|
|
114
|
+
<a href="${escapedTarget}">Go now</a>
|
|
115
|
+
</p>
|
|
116
|
+
</div>
|
|
117
|
+
</body>
|
|
118
|
+
</html>`);
|
|
119
|
+
clearTimeout(timeoutTimer);
|
|
120
|
+
server.closeAllConnections();
|
|
121
|
+
server.close();
|
|
122
|
+
const orgId = url.searchParams.get('org_id') || '';
|
|
123
|
+
const orgName = url.searchParams.get('org_name') || '';
|
|
124
|
+
const userEmail = url.searchParams.get('user_email') || '';
|
|
125
|
+
(0, credentialStore_1.saveCredentials)({ apiKey, consoleUrl, orgId, orgName, userEmail });
|
|
126
|
+
common_1.logger.info(lang_1.lang.__('LOGIN_SUCCESS', { userEmail, orgName }));
|
|
127
|
+
resolve(true);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
131
|
+
res.end('Waiting for authorization...');
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
server.listen(randomPort, '127.0.0.1', () => {
|
|
135
|
+
const redirectUri = `http://127.0.0.1:${randomPort}/callback`;
|
|
136
|
+
const fullUrl = `${uiUrl}/cli/authorize?redirect_uri=${encodeURIComponent(redirectUri)}`;
|
|
137
|
+
common_1.logger.info(lang_1.lang.__('LOGIN_OPENING_BROWSER'));
|
|
138
|
+
try {
|
|
139
|
+
(0, open_1.default)(fullUrl).catch(() => {
|
|
140
|
+
common_1.logger.warn(lang_1.lang.__('LOGIN_BROWSER_UNAVAILABLE', { url: fullUrl }));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
common_1.logger.warn(lang_1.lang.__('LOGIN_BROWSER_UNAVAILABLE', { url: fullUrl }));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const timeoutTimer = setTimeout(() => {
|
|
148
|
+
if (apiKey === null) {
|
|
149
|
+
server.closeAllConnections();
|
|
150
|
+
server.close();
|
|
151
|
+
common_1.logger.error(lang_1.lang.__('LOGIN_TIMEOUT'));
|
|
152
|
+
resolve(false);
|
|
153
|
+
}
|
|
154
|
+
}, 300_000);
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
const login = async (options) => {
|
|
158
|
+
const consoleUrl = (0, credentialStore_1.resolveConsoleUrl)((0, credentialStore_1.loadCredentials)() ?? undefined);
|
|
159
|
+
// Check if already logged in
|
|
160
|
+
const existingCreds = (0, credentialStore_1.loadCredentials)();
|
|
161
|
+
if (existingCreds) {
|
|
162
|
+
const answer = await ask(lang_1.lang.__('LOGIN_ALREADY_LOGGED_IN', {
|
|
163
|
+
userEmail: existingCreds.userEmail || '',
|
|
164
|
+
orgName: existingCreds.orgName || '',
|
|
165
|
+
}));
|
|
166
|
+
if (answer.toLowerCase() !== 'y' && answer.toLowerCase() !== 'yes') {
|
|
167
|
+
common_1.logger.info(lang_1.lang.__('LOGIN_CANCELLED'));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
(0, credentialStore_1.deleteCredentials)();
|
|
171
|
+
}
|
|
172
|
+
// If --si-api-key provided, use it directly
|
|
173
|
+
if (options.siApiKey) {
|
|
174
|
+
await loginWithKey(options.siApiKey, consoleUrl);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
// If SI_API_KEY env var set, use it
|
|
178
|
+
if (process.env.SI_API_KEY) {
|
|
179
|
+
await loginWithKey(process.env.SI_API_KEY, consoleUrl);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// Interactive prompt
|
|
183
|
+
console.log(`\n ${lang_1.lang.__('LOGIN_CHOOSE_METHOD')}\n`);
|
|
184
|
+
console.log(` 1. ${lang_1.lang.__('LOGIN_OPTION_BROWSER')}`);
|
|
185
|
+
console.log(` 2. ${lang_1.lang.__('LOGIN_OPTION_API_KEY')}\n`);
|
|
186
|
+
const choice = await ask(lang_1.lang.__('LOGIN_SELECT_CHOICE'));
|
|
187
|
+
if (choice.trim() === '2') {
|
|
188
|
+
const key = await ask(lang_1.lang.__('LOGIN_ENTER_API_KEY'));
|
|
189
|
+
await loginWithKey(key.trim(), consoleUrl);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
await loginWithBrowser(consoleUrl);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
exports.login = login;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logout = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
const credentialStore_1 = require("../common/credentialStore");
|
|
6
|
+
const lang_1 = require("../lang");
|
|
7
|
+
const logout = async () => {
|
|
8
|
+
const creds = (0, credentialStore_1.loadCredentials)();
|
|
9
|
+
if (!creds) {
|
|
10
|
+
common_1.logger.info(lang_1.lang.__('LOGOUT_NOT_LOGGED_IN'));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
common_1.logger.info(lang_1.lang.__('LOGOUT_DELETING_CREDENTIALS'));
|
|
14
|
+
(0, credentialStore_1.deleteCredentials)();
|
|
15
|
+
common_1.logger.info(lang_1.lang.__('LOGOUT_SUCCESS'));
|
|
16
|
+
};
|
|
17
|
+
exports.logout = logout;
|
|
@@ -178,26 +178,34 @@ const show = async (options) => {
|
|
|
178
178
|
let lockInfo;
|
|
179
179
|
let stateLocation;
|
|
180
180
|
let usingRemoteBackend = false;
|
|
181
|
-
const
|
|
182
|
-
|
|
181
|
+
const backendType = options.iac?.backend?.type;
|
|
182
|
+
const shouldUseRemoteBackend = backendType === backend_1.StateBackendType.BUCKET_STORE ||
|
|
183
|
+
backendType === backend_1.StateBackendType.SAAS ||
|
|
184
|
+
!backendType;
|
|
185
|
+
if (shouldUseRemoteBackend) {
|
|
183
186
|
try {
|
|
184
187
|
const backend = (0, stateBackend_1.createStateBackend)(options.iac.backend, context);
|
|
185
188
|
state = await backend.loadState(context.provider, context.app, context.service, stage);
|
|
186
189
|
lockInfo = await backend.readLock();
|
|
187
190
|
usingRemoteBackend = true;
|
|
188
|
-
stateLocation =
|
|
191
|
+
stateLocation =
|
|
192
|
+
backendType === backend_1.StateBackendType.SAAS || !backendType
|
|
193
|
+
? 'Console (SaaS state)'
|
|
194
|
+
: getBackendLocationString(options.iac.backend);
|
|
189
195
|
}
|
|
190
196
|
catch (error) {
|
|
191
|
-
|
|
197
|
+
if (backendType === backend_1.StateBackendType.SAAS || !backendType) {
|
|
198
|
+
logger_1.logger.warn(`SaaS backend unavailable: ${error}. Using local state.`);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
logger_1.logger.warn(`Failed to load state from remote backend: ${error}. Using local state.`);
|
|
202
|
+
}
|
|
192
203
|
state = loadLocalState(context.provider, context.app, context.service, stage, baseDir);
|
|
193
204
|
lockInfo = readLocalLock(context.app, context.service, baseDir);
|
|
194
205
|
stateLocation = (0, common_1.getStatePath)(context.app, context.service, baseDir);
|
|
195
206
|
}
|
|
196
207
|
}
|
|
197
208
|
else {
|
|
198
|
-
if (shouldUseRemoteBackend && !(0, common_1.hasCredentials)(context)) {
|
|
199
|
-
logger_1.logger.warn('Remote backend configured but credentials not available. Falling back to local state.');
|
|
200
|
-
}
|
|
201
209
|
state = loadLocalState(context.provider, context.app, context.service, stage, baseDir);
|
|
202
210
|
lockInfo = readLocalLock(context.app, context.service, baseDir);
|
|
203
211
|
stateLocation = (0, common_1.getStatePath)(context.app, context.service, baseDir);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whoami = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
const credentialStore_1 = require("../common/credentialStore");
|
|
6
|
+
const lang_1 = require("../lang");
|
|
7
|
+
const whoami = async () => {
|
|
8
|
+
const creds = (0, credentialStore_1.loadCredentials)();
|
|
9
|
+
if (!creds) {
|
|
10
|
+
common_1.logger.info(lang_1.lang.__('WHOAMI_NOT_LOGGED_IN'));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
common_1.logger.info('');
|
|
14
|
+
common_1.logger.info(` ${lang_1.lang.__('WHOAMI_LOGGED_IN', { userEmail: creds.userEmail || '(unknown)' })}`);
|
|
15
|
+
common_1.logger.info(` ${lang_1.lang.__('WHOAMI_ORG', { orgName: creds.orgName || creds.orgId })}`);
|
|
16
|
+
common_1.logger.info(` ${lang_1.lang.__('WHOAMI_CONSOLE', { url: creds.consoleUrl })}`);
|
|
17
|
+
common_1.logger.info(` ${lang_1.lang.__('WHOAMI_API_KEY', { keyPrefix: creds.apiKey.slice(0, 12) })} ${lang_1.lang.__('WHOAMI_KEY_ACTIVE')}`);
|
|
18
|
+
common_1.logger.info('');
|
|
19
|
+
};
|
|
20
|
+
exports.whoami = whoami;
|