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: #9061 secret migration could fail and --yes was not working #9246

Merged
merged 2 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions packages/amplify-cli-core/src/deploymentSecretsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ export const mergeDeploymentSecrets = (deploymentSecretsModifier: deploymentSecr
environments: {},
};
_.set(newDeploymentAppSecret, ['environments', envName, category, resource, keyName], value);

const filteredSecrets = currentDeploymentSecrets.appSecrets?.filter(appSecret => appSecret.rootStackId !== rootStackId) || [];

return {
appSecrets: [...currentDeploymentSecrets.appSecrets.filter(appSecret => appSecret.rootStackId !== rootStackId), newDeploymentAppSecret],
appSecrets: [...filteredSecrets, newDeploymentAppSecret],
};
};

Expand All @@ -20,7 +23,8 @@ export const removeFromDeploymentSecrets = (deploymentSecretsModifier: deploymen
if (secretsByAppId) {
recursiveOmit(secretsByAppId.environments, [envName, category, resource, keyName]);
if (Object.keys(secretsByAppId.environments).length === 0) {
currentDeploymentSecrets.appSecrets = currentDeploymentSecrets.appSecrets.filter(r => r.rootStackId !== rootStackId);
currentDeploymentSecrets.appSecrets =
currentDeploymentSecrets.appSecrets?.filter(appSecret => appSecret.rootStackId !== rootStackId) || [];
}
}
return currentDeploymentSecrets;
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-cli/src/input-params-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { $TSAny, $TSContext, JSONUtilities } from 'amplify-cli-core';
import { $TSAny, $TSContext, $TSObject, JSONUtilities } from 'amplify-cli-core';

export function normalizeInputParams(context: $TSContext) {
export function normalizeInputParams(context: $TSContext): $TSObject {
const inputParams = {};
Object.keys(context.parameters.options).forEach(key => {
const normalizedKey = normalizeKey(key);
Expand Down
14 changes: 13 additions & 1 deletion packages/amplify-cli/src/utils/headless-input-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import readline from 'readline';
import _ from 'lodash';
attilah marked this conversation as resolved.
Show resolved Hide resolved
import { Context } from '../domain/context';
import { normalizeInputParams } from '../input-params-manager';
import { $TSContext } from 'amplify-cli-core';

const headlessPayloadReadTimeoutMillis = 2000;

Expand Down Expand Up @@ -29,4 +32,13 @@ export const readHeadlessPayload = async (): Promise<string> => {
});
};

export const isYesFlagSet = (context: Context): boolean => context?.exeInfo?.inputParams?.yes;
export const isYesFlagSet = (context: Context): boolean => {
if (context?.exeInfo?.inputParams) {
return context.exeInfo.inputParams.yes;
}

// No exeInfo is constructed, get the yes flag from the input directly.
const inputParams = normalizeInputParams(context as unknown as $TSContext);

return inputParams?.yes;
};
2 changes: 1 addition & 1 deletion packages/amplify-cli/src/utils/team-provider-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { moveSecretsFromTeamProviderToDeployment } from './move-secrets-to-deplo
const message = `Amplify has been upgraded to handle secrets more securely by migrating some values in ${chalk.red(
PathConstants.TeamProviderInfoFileName,
)} to ${chalk.green(PathConstants.DeploymentSecretsFileName)}
You can create a back up of the ${chalk.red(PathConstants.TeamProviderInfoFileName)} file before proceeding.`;
You can create a backup of the ${chalk.red(PathConstants.TeamProviderInfoFileName)} file before proceeding.`;
const hostedUIProviderCredsField = 'hostedUIProviderCreds';

// return true if the current state of the app does not contain secrets in the team provider info
Expand Down