Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
Fixing time values and TTL
  • Loading branch information
Igrom committed Apr 23, 2018
1 parent 9dd37b1 commit 7bcfe86
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatefold",
"version": "1.0.2",
"version": "1.0.3",
"description": "The compact URL shortener. Developed at Cimpress.",
"main": "index.js",
"scripts": {
Expand Down
16 changes: 11 additions & 5 deletions src/gatefold.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
"GatefoldDDBTable": {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [ {
"AttributeName": "ShortUrl",
"AttributeType": "S"
} ],
"AttributeDefinitions" : [
{
"AttributeName": "ShortUrl",
"AttributeType": "S"
}
],
"KeySchema" : [ {
"AttributeName": "ShortUrl",
"KeyType": "HASH"
Expand All @@ -32,6 +34,10 @@
"ReadCapacityUnits" : 1,
"WriteCapacityUnits" : 1
},
"TimeToLiveSpecification": {
"AttributeName" : "ExpiresAt",
"Enabled" : true
},
"TableName" : "gatefold-$GATEFOLD_DOMAIN"
}
},
Expand All @@ -56,7 +62,7 @@
"Effect": "Allow",
"Action": [
"dynamodb:GetItem",
"dynamodb:UpdateItem"
"dynamodb:UpdateItem"
],
"Resource": { "Fn::GetAtt": [ "GatefoldDDBTable", "Arn" ] }
} ]
Expand Down
4 changes: 2 additions & 2 deletions src/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"passthroughBehavior": "never",
"httpMethod": "POST",
"requestTemplates": {
"application/json": "#set ($guid = $context.requestId)\n#set ($suffix1 = $guid.substring(0,4))\n#set ($suffix2 = $guid.substring(24,28))\n#set ($short = \"https://$GATEFOLD_DOMAIN/$suffix1$suffix2\")\n#set ($token = $guid.substring(0))\n#set ($ttl = $context.requestTimeEpoch + 86400 * $GATEFOLD_TTL)\n{\n \"TableName\": \"gatefold-$GATEFOLD_DOMAIN\",\n \"Key\": {\n \"ShortUrl\": {\n \"S\": \"$short\"\n }\n },\n \"ExpressionAttributeNames\": {\n \"#Token\": \"Token\"\n },\n \"ExpressionAttributeValues\": {\n \":longUrl\": {\n \"S\": $input.json(\"$.longUrl\")\n },\n \":token\": {\n \"S\": \"$token\"\n },\n \":currentTime\": {\n \"S\": \"$context.requestTimeEpoch\"\n },\n \":expiresAt\": {\n \"S\": \"$ttl\"\n }\n },\n \"UpdateExpression\": \"SET LongUrl = :longUrl, #Token = :token, CreatedAt = :currentTime, ModifiedAt = :currentTime, ExpiresAt = :expiresAt\",\n \"ConditionExpression\": \"attribute_not_exists(ShortUrl)\",\n \"ReturnValues\": \"ALL_NEW\"\n}"
"application/json": "#set ($guid = $context.requestId)\n#set ($suffix1 = $guid.substring(0,4))\n#set ($suffix2 = $guid.substring(24,28))\n#set ($short = \"https://$GATEFOLD_DOMAIN/$suffix1$suffix2\")\n#set ($token = $guid.substring(0))\n#set ($curTime = $context.requestTimeEpoch / 1000)\n#set ($ttl = $curTime + 86400 * $GATEFOLD_TTL)\n{\n \"TableName\": \"gatefold-$GATEFOLD_DOMAIN\",\n \"Key\": {\n \"ShortUrl\": {\n \"S\": \"$short\"\n }\n },\n \"ExpressionAttributeNames\": {\n \"#Token\": \"Token\"\n },\n \"ExpressionAttributeValues\": {\n \":longUrl\": {\n \"S\": $input.json(\"$.longUrl\")\n },\n \":token\": {\n \"S\": \"$token\"\n },\n \":currentTime\": {\n \"N\": \"$curTime\"\n },\n \":expiresAt\": {\n \"N\": \"$ttl\"\n }\n },\n \"UpdateExpression\": \"SET LongUrl = :longUrl, #Token = :token, CreatedAt = :currentTime, ModifiedAt = :currentTime, ExpiresAt = :expiresAt\",\n \"ConditionExpression\": \"attribute_not_exists(ShortUrl)\",\n \"ReturnValues\": \"ALL_NEW\"\n}"
},
"type": "aws"
}
Expand Down Expand Up @@ -431,7 +431,7 @@
"passthroughBehavior": "never",
"httpMethod": "POST",
"requestTemplates": {
"application/json": "#set ($suffix = $input.params(\"id\"))\n#set ($ttl = $context.requestTimeEpoch + 86400 * $GATEFOLD_TTL)\n#set ($token = $input.json(\"$.token\"))\n{\n \"TableName\": \"gatefold-$GATEFOLD_DOMAIN\",\n \"Key\": {\n \"ShortUrl\": {\n \"S\": \"https://$GATEFOLD_DOMAIN/$suffix\"\n }\n },\n \"ExpressionAttributeNames\": {\n \"#Token\": \"Token\"\n },\n \"ExpressionAttributeValues\": {\n \":longUrl\": {\n \"S\": $input.json('$.longUrl')\n },\n \":token\": {\n \"S\": $token\n },\n \":currentTime\": {\n \"S\": \"$context.requestTimeEpoch\"\n },\n \":expiresAt\": {\n \"S\": \"$ttl\"\n }\n },\n \"UpdateExpression\": \"SET LongUrl = :longUrl, #Token = :token, CreatedAt = if_not_exists(CreatedAt, :currentTime), ModifiedAt = :currentTime, ExpiresAt = :expiresAt\",\n \"ConditionExpression\": \"(attribute_not_exists(ShortUrl)) or (#Token = :token)\",\n \"ReturnValues\": \"ALL_NEW\"\n}"
"application/json": "#set ($suffix = $input.params(\"id\"))\n#set ($token = $input.json(\"$.token\"))\n#set ($curTime = $context.requestTimeEpoch / 1000)\n#set ($ttl = $curTime + 86400 * $GATEFOLD_TTL)\n{\n \"TableName\": \"gatefold-$GATEFOLD_DOMAIN\",\n \"Key\": {\n \"ShortUrl\": {\n \"S\": \"https://$GATEFOLD_DOMAIN/$suffix\"\n }\n },\n \"ExpressionAttributeNames\": {\n \"#Token\": \"Token\"\n },\n \"ExpressionAttributeValues\": {\n \":longUrl\": {\n \"S\": $input.json('$.longUrl')\n },\n \":token\": {\n \"S\": $token\n },\n \":currentTime\": {\n \"N\": \"$curTime\"\n },\n \":expiresAt\": {\n \"N\": \"$ttl\"\n }\n },\n \"UpdateExpression\": \"SET LongUrl = :longUrl, #Token = :token, CreatedAt = if_not_exists(CreatedAt, :currentTime), ModifiedAt = :currentTime, ExpiresAt = :expiresAt\",\n \"ConditionExpression\": \"(attribute_not_exists(ShortUrl)) or (#Token = :token)\",\n \"ReturnValues\": \"ALL_NEW\"\n}"
},
"type": "aws"
}
Expand Down

0 comments on commit 7bcfe86

Please sign in to comment.