Skip to content
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
152 changes: 0 additions & 152 deletions src/api/functions/cloudfrontKvStore.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"prettier:write": "prettier --write *.ts **/*.ts"
},
"dependencies": {
"@aws-sdk/client-cloudfront-keyvaluestore": "^3.895.0",
"@aws-sdk/client-dynamodb": "^3.895.0",
"@aws-sdk/client-lambda": "^3.895.0",
"@aws-sdk/client-secrets-manager": "^3.895.0",
Expand Down
57 changes: 1 addition & 56 deletions src/api/routes/linkry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@ import {
UnauthorizedError,
ValidationError,
} from "../../common/errors/index.js";
import { NoDataRequest } from "../types.js";
import {
QueryCommand,
TransactWriteItemsCommand,
TransactWriteItem,
TransactionCanceledException,
} from "@aws-sdk/client-dynamodb";
import { CloudFrontKeyValueStoreClient } from "@aws-sdk/client-cloudfront-keyvaluestore";
import { genericConfig } from "../../common/config.js";
import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
import rateLimiter from "api/plugins/rateLimiter.js";
import {
deleteKey,
getLinkryKvArn,
setKey,
} from "api/functions/cloudfrontKvStore.js";
import { createRequest, linkrySlug } from "common/types/linkry.js";
import {
extractUniqueSlugs,
Expand Down Expand Up @@ -191,12 +184,6 @@ const linkryRoutes: FastifyPluginAsync = async (fastify, _options) => {
message: `Slug ${request.body.slug} is reserved by the system.`,
});
}

if (!fastify.cloudfrontKvClient) {
fastify.cloudfrontKvClient = new CloudFrontKeyValueStoreClient({
region: genericConfig.AwsRegion,
});
}
},
onRequest: fastify.authorizeFromSchema,
},
Expand Down Expand Up @@ -423,24 +410,6 @@ const linkryRoutes: FastifyPluginAsync = async (fastify, _options) => {
message: "Failed to save data to DynamoDB.",
});
}
// Add to cloudfront key value store so that redirects happen at the edge
const kvArn = await getLinkryKvArn(fastify.runEnvironment);
try {
await setKey({
key: request.body.slug,
value: request.body.redirect,
kvsClient: fastify.cloudfrontKvClient,
arn: kvArn,
});
} catch (e) {
fastify.log.error(e);
if (e instanceof BaseError) {
throw e;
}
throw new DatabaseInsertError({
message: "Failed to save redirect to Cloudfront KV store.",
});
}
await createAuditLogEntry({
dynamoClient: fastify.dynamoClient,
entry: {
Expand Down Expand Up @@ -517,15 +486,7 @@ const linkryRoutes: FastifyPluginAsync = async (fastify, _options) => {
}),
}),
),
onRequest: async (request, reply) => {
await fastify.authorizeFromSchema(request, reply);

if (!fastify.cloudfrontKvClient) {
fastify.cloudfrontKvClient = new CloudFrontKeyValueStoreClient({
region: genericConfig.AwsRegion,
});
}
},
onRequest: fastify.authorizeFromSchema,
},
async (request, reply) => {
const { slug } = request.params;
Expand Down Expand Up @@ -614,22 +575,6 @@ const linkryRoutes: FastifyPluginAsync = async (fastify, _options) => {
message: "Failed to delete data from DynamoDB.",
});
}
const kvArn = await getLinkryKvArn(fastify.runEnvironment);
try {
await deleteKey({
key: slug,
kvsClient: fastify.cloudfrontKvClient,
arn: kvArn,
});
} catch (e) {
fastify.log.error(e);
if (e instanceof BaseError) {
throw e;
}
throw new DatabaseDeleteError({
message: "Failed to delete redirect at Cloudfront KV store.",
});
}
await createAuditLogEntry({
dynamoClient: fastify.dynamoClient,
entry: {
Expand Down
2 changes: 0 additions & 2 deletions src/api/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import NodeCache from "node-cache";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
import { SQSClient } from "@aws-sdk/client-sqs";
import { CloudFrontKeyValueStoreClient } from "@aws-sdk/client-cloudfront-keyvaluestore";
import { AvailableAuthorizationPolicy } from "common/policies/definition.js";
import type RedisModule from "ioredis";
export type Redis = RedisModule.default;
Expand Down Expand Up @@ -45,7 +44,6 @@ declare module "fastify" {
sqsClient?: SQSClient;
redisClient: Redis;
secretsManagerClient: SecretsManagerClient;
cloudfrontKvClient: CloudFrontKeyValueStoreClient;
secretConfig: SecretConfig | (SecretConfig & SecretTesting);
refreshSecretConfig: CallableFunction;
}
Expand Down
2 changes: 0 additions & 2 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type ConfigType = {
PaidMemberGroupId: string;
PaidMemberPriceId: string;
AadValidReadOnlyClientId: string;
LinkryCloudfrontKvArn?: string;
ConfigurationSecretIds: string[];
DiscordGuildId: string;
GroupSuffix: string;
Expand Down Expand Up @@ -136,7 +135,6 @@ const environmentConfig: EnvironmentConfigType = {
PaidMemberGroupId: "9222451f-b354-4e64-ba28-c0f367a277c2",
PaidMemberPriceId: "price_1S5eAqDGHrJxx3mKZYGoulj3",
AadValidReadOnlyClientId: "2c6a0057-5acc-496c-a4e5-4adbf88387ba",
LinkryCloudfrontKvArn: "arn:aws:cloudfront::427040638965:key-value-store/0c2c02fd-7c47-4029-975d-bc5d0376bba1",
DiscordGuildId: "1278798685706391664",
EntraServicePrincipalId: "8c26ff11-fb86-42f2-858b-9011c9f0708d",
GroupSuffix: "[NonProd]",
Expand Down
Loading
Loading