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

feat(secretsmanager): validate maximum value of automaticallyAfter in RotationSchedule #27592

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -37,6 +37,8 @@ export interface RotationScheduleOptions {
* Specifies the number of days after the previous rotation before
* Secrets Manager triggers the next automatic rotation.
*
* The maximum value is 1000 days.
*
* A value of zero will disable automatic rotation - `Duration.days(0)`.
*
* @default Duration.days(30)
Expand Down Expand Up @@ -125,6 +127,9 @@ export class RotationSchedule extends Resource {
}

let automaticallyAfterDays: number | undefined = undefined;
if (props.automaticallyAfter && props.automaticallyAfter.toDays() > 1000) {
throw new Error(`automaticallyAfter must not be greater than 1000 days, got ${props.automaticallyAfter.toDays()} days`);
}
if (props.automaticallyAfter?.toMilliseconds() !== 0) {
automaticallyAfterDays = props.automaticallyAfter?.toDays() || 30;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,3 +651,21 @@ test('rotation schedule should have a dependency on lambda permissions', () => {
],
});
});

test('automaticallyAfter must not be greater than 1000 days', () => {
// GIVEN
const secret = new secretsmanager.Secret(stack, 'Secret');
const rotationLambda = new lambda.Function(stack, 'Lambda', {
runtime: lambda.Runtime.NODEJS_LATEST,
code: lambda.Code.fromInline('export.handler = event => event;'),
handler: 'index.handler',
});

// WHEN
// THEN
expect(() => new secretsmanager.RotationSchedule(stack, 'RotationSchedule', {
secret,
rotationLambda,
automaticallyAfter: Duration.days(1001),
})).toThrow(/automaticallyAfter must not be greater than 1000 days, got 1001 days/);
});