Skip to content

Commit

Permalink
(fix) s3 add with no-auth resource should succeed (aws-amplify#8520)
Browse files Browse the repository at this point in the history
Co-authored-by: Sachin Panemangalore <sachinrp@amazon.com>
  • Loading branch information
sachscode and Sachin Panemangalore committed Nov 10, 2021
1 parent 9bea739 commit 3971af5
Showing 1 changed file with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { $TSAny, $TSContext} from "amplify-cli-core";
import { printer } from "amplify-prompts";
import { AmplifyCategories } from "amplify-cli-core";
import { $TSAny, $TSContext } from 'amplify-cli-core';
import { printer } from 'amplify-prompts';
import { AmplifyCategories } from 'amplify-cli-core';

/* This file contains all functions interacting with AUTH category */

Expand All @@ -11,27 +11,35 @@ import { AmplifyCategories } from "amplify-cli-core";
* @param context used to fetch all auth resources used by storage(S3)
* @returns Name of the auth resource used by S3
*/
export async function getAuthResourceARN( context : $TSContext ) : Promise<string> {
let authResources = (await context.amplify.getResourceStatus('auth')).allResources;
authResources = authResources.filter((resource: $TSAny) => resource.service === 'Cognito');
if (authResources.length === 0) {
throw new Error('No auth resource found. Please add it using amplify add auth');
}
return authResources[0].resourceName as string;
export async function getAuthResourceARN(context: $TSContext): Promise<string> {
let authResources = (await context.amplify.getResourceStatus('auth')).allResources;
authResources = authResources.filter((resource: $TSAny) => resource.service === 'Cognito');
if (authResources.length === 0) {
throw new Error('No auth resource found. Please add it using amplify add auth');
}
return authResources[0].resourceName as string;
}
/**
* Migrate all Auth resources used by Storage(S3) for Override feature.
* @param context - used to fetch auth resources and to migrate auth resources for override-feature.
*/
export async function migrateAuthDependencyResource( context : $TSContext ) {
const authResourceName = await getAuthResourceARN(context);
export async function migrateAuthDependencyResource(context: $TSContext) {
let authResourceName = undefined;
try {
authResourceName = await getAuthResourceARN(context);
} catch (error) {
//No auth resources to migrate - new project
return;
}
if (authResourceName) {
try {
await context.amplify.invokePluginMethod(context,
AmplifyCategories.AUTH, undefined,
'migrateAuthResource',
[context, authResourceName ]);
await context.amplify.invokePluginMethod(context, AmplifyCategories.AUTH, undefined, 'migrateAuthResource', [
context,
authResourceName,
]);
} catch (error) {
printer.error(error as string);
throw error;
}
}
}

0 comments on commit 3971af5

Please sign in to comment.