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

Parameter change approval #104

Merged
merged 6 commits into from
Apr 16, 2018
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
11 changes: 6 additions & 5 deletions src/approval/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import configureAWS from '../configureAWS';
import {logger} from '../logger';
import {diff} from '../diff';
import {GlobalArguments} from '../cli';
import {SUCCESS, FAILURE, INTERRUPT} from '../statusCodes';

export type RequestArguments = GlobalArguments & {
argsfile: string;
Expand Down Expand Up @@ -44,10 +45,10 @@ export async function request(argv: RequestArguments): Promise<number> {
}
}

return 0;
return SUCCESS;
} else {
logError(`\`ApprovedTemplateLocation\` must be provided in ${argv.argsfile}`);
return 1;
return FAILURE;
}

}
Expand Down Expand Up @@ -132,17 +133,17 @@ export async function review(argv: ReviewArguments): Promise<number> {

console.log();
logSuccess(`Template has been successfully approved!`);
return 0;
return SUCCESS;
} else {
return 130;
return INTERRUPT;
}

} else {
throw new Error(e);
}
}

return 0;
return SUCCESS;
}

function logSuccess(text: string) {
Expand Down
3 changes: 2 additions & 1 deletion src/cfn/convertStackToIidy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import def from '../default';
import {getKMSAliasForParameter} from '../params';

import {GlobalArguments} from '../cli';
import {SUCCESS} from '../statusCodes';

function parameterizeEnv(s0: string, environments = ['development', 'integration', 'staging', 'production']): string {
let s = s0;
Expand Down Expand Up @@ -219,5 +220,5 @@ export async function convertStackToIIDY(argv: ConvertStackArguments): Promise<n

fs.writeFileSync(pathmod.join(outputDir, 'stack-args.yaml'), yaml.dump(outputDoc));
// TODO write iidy-environment.yaml and related files
return 0;
return SUCCESS;
}
41 changes: 21 additions & 20 deletions src/cfn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {AWSRegion} from '../aws-regions';
import timeout from '../timeout';
import def from '../default';
import {diff} from '../diff';
import {SUCCESS, FAILURE, INTERRUPT} from '../statusCodes';

import {readFromImportLocation, transform, PreprocessOptions} from '../preprocess';
import {getKMSAliasForParameter} from '../params';
Expand Down Expand Up @@ -752,7 +753,7 @@ async function listStacks(showTags = false, tagsFilter?: [string, string][]) {
spinner.stop();
if (stacks.length === 0) {
console.log('No stacks found');
return 0;
return SUCCESS;
}

const timePadding = 24;
Expand Down Expand Up @@ -993,15 +994,15 @@ function showFinalComandSummary(wasSuccessful: boolean): number {
console.log(formatSectionHeading(sprintf(`%-${COLUMN2_START}s`, 'Command Summary:')),
cli.black(cli.bgGreenBright('Success')),
'👍')
return 0;
return SUCCESS;
} else {
console.log(
formatSectionHeading(sprintf(`%-${COLUMN2_START}s`, 'Command Summary:')),
cli.bgRedBright('Failure'),
' (╯°□°)╯︵ ┻━┻ ',
'Fix and try again.'
)
return 1;
return FAILURE;
}
}

Expand Down Expand Up @@ -1136,7 +1137,7 @@ abstract class AbstractCloudFormationStackCommand {
logger.error('Template version has not been approved or the current IAM principal does not have permission to access it. Run:');
logger.error(` iidy template-approval request ${this.argsfile}`);
logger.error('to begin the approval process.');
return 1;
return FAILURE;
}
const createStackOutput = await this.cfn.createStack(createStackInput).promise();
await this._updateStackTerminationPolicy();
Expand All @@ -1150,7 +1151,7 @@ abstract class AbstractCloudFormationStackCommand {
logger.error('Template version has not been approved or the current IAM principal does not have permission to access it. Run:');
logger.error(` iidy template-approval request ${this.argsfile}`);
logger.error('to being the approval process.');
return 1;
return FAILURE;
}
if (this.argv.stackPolicyDuringUpdate) {
const {
Expand All @@ -1166,7 +1167,7 @@ abstract class AbstractCloudFormationStackCommand {
} catch (e) {
if (e.message === 'No updates are to be performed.') {
logger.info('No changes detected so no stack update needed.');
return 0;
return SUCCESS;
} else {
throw e;
}
Expand Down Expand Up @@ -1303,7 +1304,7 @@ class CreateChangeSet extends AbstractCloudFormationStackCommand {
if (changeSet.Status === 'FAILED') {
logger.error(changeSet.StatusReason as string, 'Deleting failed changeset.');
await this.cfn.deleteChangeSet({ChangeSetName, StackName}).promise();
return 1;
return FAILURE;
}
console.log();

Expand All @@ -1321,7 +1322,7 @@ class CreateChangeSet extends AbstractCloudFormationStackCommand {
console.log();
}
showFinalComandSummary(true);
return 0;
return SUCCESS;
}

async _waitForChangeSetCreateComplete() {
Expand Down Expand Up @@ -1379,7 +1380,7 @@ class EstimateStackCost extends AbstractCloudFormationStackCommand {
await stackArgsToCreateStackInput(this.stackArgs, this.argsfile, this.environment, this.stackName)
const estimateResp = await this.cfn.estimateTemplateCost({TemplateBody, TemplateURL, Parameters}).promise();
console.log('Stack cost estimator: ', estimateResp.Url);
return 0;
return SUCCESS;
}
}

Expand Down Expand Up @@ -1444,7 +1445,7 @@ export async function updateStackMain(argv: GenericCLIArguments): Promise<number
return createChangesetResult;
} else {
logger.info('No changes to apply');
return 0;
return SUCCESS;
}
}
console.log()
Expand All @@ -1461,7 +1462,7 @@ export async function updateStackMain(argv: GenericCLIArguments): Promise<number
} else {
console.log(`You can do so later using\n`
+ ` iidy exec-changeset -s ${changeSetRunner.stackName} ${changeSetRunner.argsfile} ${changeSetRunner.changeSetName}`);
return 130;
return INTERRUPT;
}
} else {
return new UpdateStack(argv, await loadStackArgs(argv)).run();
Expand All @@ -1477,7 +1478,7 @@ export async function createChangesetMain(argv: GenericCLIArguments): Promise<nu
await watchStack(changesetRunner.stackName, new Date(), DEFAULT_EVENT_POLL_INTERVAL, argv.watchInactivityTimeout);
console.log();
await summarizeCompletedStackOperation(changesetRunner.stackName);
return 0;
return SUCCESS;
} else {
return changesetExitCode;
}
Expand All @@ -1490,7 +1491,7 @@ export async function listStacksMain(argv: GenericCLIArguments): Promise<number>
return [key, value.join('=')] as [string, string];
});
await listStacks(argv.tags, tagsFilter);
return 0;
return SUCCESS;
}


Expand Down Expand Up @@ -1522,7 +1523,7 @@ export async function watchStackMain(argv: GenericCLIArguments): Promise<number>
await watchStack(StackId, startTime, DEFAULT_EVENT_POLL_INTERVAL, argv.inactivityTimeout);
console.log();
await summarizeCompletedStackOperation(StackId);
return 0;
return SUCCESS;
}

export async function describeStackMain(argv: GenericCLIArguments): Promise<number> {
Expand All @@ -1541,7 +1542,7 @@ export async function describeStackMain(argv: GenericCLIArguments): Promise<numb
await showStackEvents(StackName, eventCount, stackEventsPromise);
console.log();
await summarizeCompletedStackOperation(StackId, stackPromise);
return 0;
return SUCCESS;
}

export async function getStackInstancesMain(argv: GenericCLIArguments): Promise<number> {
Expand Down Expand Up @@ -1582,7 +1583,7 @@ export async function getStackInstancesMain(argv: GenericCLIArguments): Promise<
console.log(
cli.blackBright(
`https://console.aws.amazon.com/ec2/v2/home?region=${region}#Instances:tag:aws:cloudformation:stack-name=${StackName};sort=desc:launchTime`));
return 0;
return SUCCESS;
}

export async function getStackTemplateMain(argv: GenericCLIArguments): Promise<number> {
Expand Down Expand Up @@ -1610,7 +1611,7 @@ export async function getStackTemplateMain(argv: GenericCLIArguments): Promise<n
default:
console.log(output.TemplateBody);
}
return 0;
return SUCCESS;
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -1631,10 +1632,10 @@ export async function deleteStackMain(argv: GenericCLIArguments): Promise<number
auth_arn = ${cli.blackBright(iamIdent.Arn)}`;
if (argv.failIfAbsent) {
logger.error(msg);
return 1;
return FAILURE;
} else {
logger.info(msg);
return 0;
return SUCCESS;
}
}
console.log();
Expand Down Expand Up @@ -1670,7 +1671,7 @@ export async function deleteStackMain(argv: GenericCLIArguments): Promise<number
const {StackStatus} = await getStackDescription(StackId);
return showFinalComandSummary(StackStatus === 'DELETE_COMPLETE');
} else {
return 130;
return INTERRUPT;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as cli from 'cli-color';
import timeout from './timeout';
import {transform} from './preprocess';
import * as yaml from './yaml';
import {SUCCESS} from './statusCodes';

type Banner = {
type: 'banner',
Expand Down Expand Up @@ -67,7 +68,7 @@ class DemoRunner {
// TODO check result
child_process.execSync(`rm -r "${this.tmpdir.name}"`, {cwd: this.tmpdir.name});
}
return 0;
return SUCCESS;
}

_unpackFiles(files: {[key: string]: string}) {
Expand Down
3 changes: 2 additions & 1 deletion src/initStackArgs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import {Arguments} from 'yargs';
import {SUCCESS} from './statusCodes';

export async function initStackArgs(argv: Arguments): Promise<number> {

Expand Down Expand Up @@ -83,5 +84,5 @@ NotificationARNs:
console.log("cfn-template.yaml has been created!");
}

return 0;
return SUCCESS;
}
16 changes: 16 additions & 0 deletions src/params/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {description, Handler, wrapCommandHandler} from '../cli';

export interface ParamCommands {
setParam: Handler;
reviewParam: Handler;
getParam: Handler;
getParamsByPath: Handler;
getParamHistory: Handler;
Expand All @@ -14,6 +15,7 @@ const lazyLoad = (fnname: keyof ParamCommands): Handler =>

const lazy: ParamCommands = {
setParam: lazyLoad('setParam'),
reviewParam: lazyLoad('reviewParam'),
getParam: lazyLoad('getParam'),
getParamsByPath: lazyLoad('getParamsByPath'),
getParamHistory: lazyLoad('getParamHistory'),
Expand All @@ -40,17 +42,31 @@ export function buildParamCommands(args: yargs.Argv, commands = lazy): yargs.Arg
description('set a parameter value'),
(args) =>
args
.option('message', {
type: 'string',
description: 'descriptive message for parameter'
})
.option('overwrite', {
type: 'boolean', default: false,
description: 'overwrite existing parameters'
})
.option('with-approval', {
type: 'boolean', default: false,
description: 'require parameter review to apply change'
})
.option('type', {
type: 'string', default: 'SecureString',
description: 'parameter type',
choices: ['String', 'StringList', 'SecureString']
}),
wrapCommandHandler(commands.setParam))

.command(
'review <path>',
description('review a pending change'),
(args) => args,
wrapCommandHandler(commands.reviewParam))

.command('get <path>',
description('get a parameter value'),
(args) =>
Expand Down
Loading