mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
* feat: Remove Console Login * fix: Update login tests to remove console login options * feat: Remove Console login options * feat: Remove console onboarding * fix: Remove console tests * chore: Remove remaining console flags * fix: Remove console deploy unit test * fix: Interactive Setup tests * fix: Update generate-payload tests
75 lines
2.4 KiB
JavaScript
75 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
const inquirer = require('@serverless/utils/inquirer');
|
|
const { StepHistory } = require('@serverless/utils/telemetry');
|
|
const log = require('@serverless/utils/log').log.get('onboarding');
|
|
const { resolveInitialContext } = require('./utils');
|
|
const { awsRequest } = require('./utils');
|
|
|
|
const steps = {
|
|
service: require('./service'),
|
|
dashboardLogin: require('./dashboard-login'),
|
|
dashboardSetOrg: require('./dashboard-set-org'),
|
|
awsCredentials: require('./aws-credentials'),
|
|
deploy: require('./deploy'),
|
|
};
|
|
|
|
const resolveAwsAccountId = async (context) => {
|
|
try {
|
|
return (await awsRequest(context, 'STS', 'getCallerIdentity')).Account;
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
module.exports = async (context) => {
|
|
const stepsDetails = new Map(
|
|
Object.entries(steps).map(([stepName, step]) => {
|
|
return [stepName, { configuredQuestions: step.configuredQuestions }];
|
|
})
|
|
);
|
|
const { commandUsage, options } = context;
|
|
const history = new Map();
|
|
context = { ...context, inquirer, history };
|
|
|
|
commandUsage.stepsHistory = history;
|
|
commandUsage.stepsHistory.toJSON = () => {
|
|
return Array.from(stepsDetails.entries()).map(([step, stepDetails]) => {
|
|
const stepHistory = history.get(step);
|
|
return {
|
|
name: step,
|
|
...stepDetails,
|
|
history: stepHistory ? stepHistory.toJSON() : [],
|
|
};
|
|
});
|
|
};
|
|
|
|
const initialContext = resolveInitialContext(context);
|
|
commandUsage.initialContext = initialContext;
|
|
context.initial = initialContext;
|
|
context.awsAccountId = await resolveAwsAccountId(context);
|
|
context.isOnboarding = !options.dev;
|
|
context.isDashboard = initialContext.isDashboardEnabled;
|
|
|
|
for (const [stepName, step] of Object.entries(steps)) {
|
|
delete context.stepHistory;
|
|
delete context.inapplicabilityReasonCode;
|
|
const stepData = await step.isApplicable(context);
|
|
if (stepData) log.debug('%s: applicable: %o', stepName, stepData);
|
|
else log.debug('%s: not applicable: %s', stepName, context.inapplicabilityReasonCode);
|
|
Object.assign(stepsDetails.get(stepName), {
|
|
isApplicable: Boolean(stepData),
|
|
inapplicabilityReasonCode: context.inapplicabilityReasonCode,
|
|
timestamp: Date.now(),
|
|
});
|
|
if (stepData) {
|
|
log.notice();
|
|
context.stepHistory = new StepHistory();
|
|
context.history.set(stepName, context.stepHistory);
|
|
await step.run(context, stepData);
|
|
}
|
|
}
|
|
|
|
return context;
|
|
};
|