Skip to content

Commit

Permalink
fix: hostedUIProviderCreds Not found and check for localenv (#6099)
Browse files Browse the repository at this point in the history
* fix: hostedUIProviderCresNot found

* Some formatting for readibility

* style: trailing spaces

Co-authored-by: Attila Hajdrik <attila@eyedea.hu>
  • Loading branch information
ammarkarachi and attilah committed Dec 11, 2020
1 parent f425924 commit 874ceaa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe('test migration code', () => {
getTeamProviderInfo: mockGetTeamProviderInfo,
getLocalEnvInfo: mockGetLocalEnvInfo,
getResourceParametersJson: mockGetResourceParameterJson,
localEnvInfoExists: jest.fn().mockReturnValue(true),
},
pathManager: {
findProjectRoot: jest.fn().mockReturnValue(true),
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-cli/src/__tests__/test-aborting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('test SIGINT with execute', () => {
stateManager: {
getMeta: jest.fn(),
projectConfigExists: jest.fn(),
localEnvInfoExists: jest.fn().mockReturnValue(true),
},
FeatureFlags: {
initialize: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ function loadEnvResourceParametersFromDeploymentSecrets(context: $TSContext, cat
const deploymentSecretByAppId = _.find(deploymentSecrets.appSecrets, appSecret => appSecret.rootStackId === rootStackId);
if (deploymentSecretByAppId) {
return _.get(deploymentSecretByAppId.environments, [currentEnv, category, resource]);
} else {
const parameters = stateManager.getResourceParametersJson(undefined, category, resource);
//set empty default if no hostedUIProviderCreds found
if (parameters && parameters.hostedUI) {
return _.set({}, hostedUIProviderCredsField, '[]');
}
}
} catch (e) {}
return {};
Expand Down
19 changes: 15 additions & 4 deletions packages/amplify-cli/src/utils/team-provider-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ const hostedUIProviderCredsField = 'hostedUIProviderCreds';
export const migrateTeamProviderInfo = async (context: Context): Promise<boolean> => {
// check if command executed in proj root and team provider has secrets

if (!isPulling(context) && pathManager.findProjectRoot()) {
if (!isInvalidEnvOrPulling(context) && pathManager.findProjectRoot()) {
const authResourceName = teamProviderInfoGetAuthResourceNameHasSecrets();
if (!authResourceName) return true;

if (!authResourceName) {
return true;
}

if (isYesFlagSet(context) || (await context.prompt.confirm(message))) {
const authParams = stateManager.getResourceParametersJson(undefined, 'auth', authResourceName);

moveSecretsFromTeamProviderToDeployment();

await externalAuthEnable(context, undefined, undefined, authParams);
} else {
return false;
Expand All @@ -32,8 +38,13 @@ export const migrateTeamProviderInfo = async (context: Context): Promise<boolean
return true;
};

function isPulling(context: Context): boolean {
function isInvalidEnvOrPulling(context: Context): boolean {
if (!stateManager.localEnvInfoExists()) {
return true;
}

const isPulling = context.input.command === 'pull' || context.input.command === 'init' || context.input.command === 'env';

return isPulling;
}

Expand All @@ -42,9 +53,9 @@ function teamProviderInfoGetAuthResourceNameHasSecrets(): any | undefined {
const teamProviderInfo = stateManager.getTeamProviderInfo();
const { envName } = stateManager.getLocalEnvInfo();
const authResources = _.get(teamProviderInfo, [envName, 'categories', 'auth']);

if (authResources) {
return _.find(Object.keys(authResources), resource => _.has(authResources, [resource, hostedUIProviderCredsField]));
}
}
return;
}

0 comments on commit 874ceaa

Please sign in to comment.