Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public makeAppSyncApiKey(apiKeyConfig: Transformer.ApiKeyConfig) {
let expirationDays = 7;
if (apiKeyConfig && apiKeyConfig.apiKeyExpirationDays) {
expirationDays = apiKeyConfig.apiKeyExpirationDays;
}
const expirationDateInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * expirationDays; /* d */
const nowEpochTime = Math.floor(Date.now() / 1000);
return new AppSync.ApiKey({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
Description: apiKeyConfig && apiKeyConfig.description ? apiKeyConfig.description : undefined,
Expires: Fn.If(
ResourceConstants.CONDITIONS.APIKeyExpirationEpochIsPositive,
Fn.Ref(ResourceConstants.PARAMETERS.APIKeyExpirationEpoch),
nowEpochTime + expirationDateInSeconds
),
}).condition(ResourceConstants.CONDITIONS.ShouldCreateAPIKey);
}
public makeAppSyncApiKey() {
const oneWeekFromNowInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * 7 /* d */
const nowEpochTime = Math.floor(Date.now() / 1000)
return new AppSync.ApiKey({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
Expires: Fn.If(
ResourceConstants.CONDITIONS.APIKeyExpirationEpochIsPositive,
Fn.Ref(ResourceConstants.PARAMETERS.APIKeyExpirationEpoch),
nowEpochTime + oneWeekFromNowInSeconds
),
}).condition(ResourceConstants.CONDITIONS.ShouldCreateAPIKey)
}