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(graphql-auth-transformer): add a time delay when creating apiKey #4493

Merged
merged 3 commits into from
Jul 14, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ async function askApiKeyQuestions() {
message: 'After how many days from now the API key should expire (1-365):',
default: 7,
validate: validateDays,
// adding filter to ensure parsing input as int -> https://github.com/SBoudrias/Inquirer.js/issues/866
filter: value => (isNaN(parseInt(value, 10)) ? value : parseInt(value, 10)),
},
];

Expand Down Expand Up @@ -832,7 +834,6 @@ async function askOpenIDConnectQuestions() {
function validateDays(input) {
const isValid = /^\d+$/.test(input);
const days = isValid ? parseInt(input, 10) : 0;

if (!isValid || days < 1 || days > 365) {
return 'Number of days must be between 1 and 365.';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/categories/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function addApiWithSchema(cwd: string, schemaFile: string) {
.wait(/.*Enter a description for the API key.*/)
.sendCarriageReturn()
.wait(/.*After how many days from now the API key should expire.*/)
.sendCarriageReturn()
.sendLine('1')
.wait(/.*Do you want to configure advanced settings for the GraphQL API.*/)
.sendCarriageReturn()
.wait('Do you have an annotated GraphQL schema?')
Expand Down
5 changes: 4 additions & 1 deletion packages/graphql-auth-transformer/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export class ResourceFactory {
if (apiKeyConfig && apiKeyConfig.apiKeyExpirationDays) {
expirationDays = apiKeyConfig.apiKeyExpirationDays;
}
const expirationDateInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * expirationDays; /* d */
// add delay expiration time is valid upon resource creation
let expirationDateInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * expirationDays /* d */;
// Add a 2 minute time delay if set to 1 day: https://github.com/aws-amplify/amplify-cli/issues/4460
if (expirationDays === 1) expirationDateInSeconds += 60 * 2;
const nowEpochTime = Math.floor(Date.now() / 1000);
return new AppSync.ApiKey({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
Expand Down