Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto migrate auth for headless flows #8735

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ test('migration gets called when cli-inputs doesnt exist', async () => {
});

const mockContext = {
amplify : {
getImportedAuthProperties : jest.fn().mockReturnValue({ imported : false })
}
}
amplify: {
getImportedAuthProperties: jest.fn().mockReturnValue({ imported: false }),
},
input: {
options: {},
},
};

await checkAuthResourceMigration(mockContext as unknown as $TSContext, 'mockResource');
expect(migrateResourceToSupportOverride).toBeCalled();
Expand All @@ -79,10 +82,10 @@ test('migration doesnt called when cli-inputs exist', async () => {
jest.spyOn(AuthInputState.prototype, 'cliInputFileExists').mockImplementation(() => true);
jest.spyOn(AuthInputState.prototype, 'getCLIInputPayload');
const mockContext = {
amplify : {
getImportedAuthProperties : jest.fn().mockReturnValue({ imported : false })
}
}
amplify: {
getImportedAuthProperties: jest.fn().mockReturnValue({ imported: false }),
},
};

await checkAuthResourceMigration(mockContext as unknown as $TSContext, 'mockResource');
expect(migrateResourceToSupportOverride).not.toBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { migrateResourceToSupportOverride } from './migrate-override-resource';

export const checkAuthResourceMigration = async (context: $TSContext, authName: string) => {
// check if its imported auth
const { imported} = context.amplify.getImportedAuthProperties(context);
if(!imported){
const { imported } = context.amplify.getImportedAuthProperties(context);
if (!imported) {
const cliState = new AuthInputState(authName);
if (!cliState.cliInputFileExists()) {
printer.debug('Cli-inputs.json doesnt exist');
// put spinner here
const isMigrate = await prompter.yesOrNo(`Do you want to migrate this ${authName} to support overrides?`, true);
if (isMigrate) {
const headlessMigrate = context.input.options?.yes || context.input.options?.forcePush || context.input.options?.headless;
kaustavghosh06 marked this conversation as resolved.
Show resolved Hide resolved
if (headlessMigrate || (await prompter.yesOrNo(`Do you want to migrate this ${authName} to support overrides?`, true))) {
// generate cli-inputs for migration from parameters.json
await migrateResourceToSupportOverride(authName);
// fetch cli Inputs again
Expand Down