Skip to content

Commit

Permalink
(fix) amplify status crashes when auth is legacy (aws-amplify#8769)
Browse files Browse the repository at this point in the history
Co-authored-by: Sachin Panemangalore <sachinrp@amazon.com>
  • Loading branch information
2 people authored and akshbhu committed Nov 10, 2021
1 parent fef6d1c commit 37b823d
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { $TSContext } from 'amplify-cli-core';
import { ProviderUtils } from '../import/types';
import { $TSContext, AmplifyCategories, JSONUtilities, stateManager } from 'amplify-cli-core';
import * as path from 'path';
import { getSupportedServices } from '../../supported-services';
import { ServiceQuestionHeadlessResult } from '../service-walkthrough-types/cognito-user-input-types';
import { AuthInputState } from '../auth-inputs-manager/auth-input-state';
import { ProviderUtils } from '../import/types';
import { CognitoConfiguration } from '../service-walkthrough-types/awsCognito-user-input-types';
import { ServiceQuestionHeadlessResult } from '../service-walkthrough-types/cognito-user-input-types';
import { existsSync } from 'fs-extra';

export type UserPoolMessageConfiguration = {
mfaConfiguration?: string;
Expand Down Expand Up @@ -32,12 +34,25 @@ const getProviderPlugin = (context: $TSContext): ProviderUtils => {

return context.amplify.getPluginInstance(context, provider);
};
export const loadResourceParameters = async (context: $TSContext, resourceName: string): Promise<UserPoolMessageConfiguration> => {
const cliState = new AuthInputState(resourceName);
const userPoolMessageConfig = (await cliState.loadResourceParameters(
context,
cliState.getCLIInputPayload(),
)) as UserPoolMessageConfiguration;

async function loadResourceParametersLegacyCode(authResourceName: string): Promise<UserPoolMessageConfiguration> {
const legacyParameters = await stateManager.getResourceParametersJson(undefined, 'auth', authResourceName);
let userPoolMessageConfig: UserPoolMessageConfiguration = {
mfaConfiguration: legacyParameters.mfaConfiguration,
mfaTypes: legacyParameters.mfaTypes,
usernameAttributes: legacyParameters.usernameAttributes,
};
return userPoolMessageConfig;
}
export const loadResourceParameters = async (context: $TSContext, authResourceName: string): Promise<UserPoolMessageConfiguration> => {
const cliState = new AuthInputState(authResourceName);
let userPoolMessageConfig;
try {
userPoolMessageConfig = (await cliState.loadResourceParameters(context, cliState.getCLIInputPayload())) as UserPoolMessageConfiguration;
} catch (error) {
//Generated with legacy code - needs migration
userPoolMessageConfig = await loadResourceParametersLegacyCode(authResourceName);
}
return userPoolMessageConfig;
};

Expand Down

0 comments on commit 37b823d

Please sign in to comment.