Skip to content

Commit

Permalink
fix(graphql-auth-transformer): add a time delay when creating apiKey (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
SwaySway authored and sebastiancrossa committed Aug 24, 2020
1 parent 6c7e48e commit 121f1b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,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 @@ -833,7 +835,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 @@ -70,7 +70,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

0 comments on commit 121f1b5

Please sign in to comment.