Skip to content

Commit 408d3d2

Browse files
committed
fix
1 parent 980ea79 commit 408d3d2

File tree

8 files changed

+20
-5
lines changed

8 files changed

+20
-5
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,7 @@ dist
132132
# AWS SAM
133133
.aws-sam/
134134
build/
135-
dist/
135+
dist/
136+
137+
*.pyc
138+
__pycache__

src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AppRoles, RunEnvironment } from "./roles.js";
33
type GroupRoleMapping = Record<string, AppRoles[]>;
44
type AzureRoleMapping = Record<string, AppRoles[]>;
55

6-
type ConfigType = {
6+
export type ConfigType = {
77
GroupRoleMapping: GroupRoleMapping;
88
AzureRoleMapping: AzureRoleMapping;
99
ValidCorsOrigins: (string | RegExp)[];
@@ -14,6 +14,7 @@ type GenericConfigType = {
1414
DynamoTableName: string;
1515
ConfigSecretName: string;
1616
UpcomingEventThresholdSeconds: number;
17+
AwsRegion: string;
1718
};
1819

1920
type EnvironmentConfigType = {
@@ -24,6 +25,7 @@ const genericConfig: GenericConfigType = {
2425
DynamoTableName: "infra-events-api-records",
2526
ConfigSecretName: "infra-events-api-config",
2627
UpcomingEventThresholdSeconds: 1800, // 30 mins
28+
AwsRegion: process.env.AWS_REGION || "us-east-1",
2729
} as const;
2830

2931
const environmentConfig: EnvironmentConfigType = {

src/plugins/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export type AadToken = {
5252
roles?: string[];
5353
};
5454
const smClient = new SecretsManagerClient({
55-
region: process.env.AWS_REGION || "us-east-1",
55+
region: genericConfig.AwsRegion,
5656
});
5757

5858
const getSecretValue = async (
@@ -123,7 +123,7 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
123123
}
124124
verifyOptions = { algorithms: ["HS256" as Algorithm] };
125125
} else {
126-
const AadClientId = process.env.AadValidClientId;
126+
const AadClientId = fastify.environmentConfig.AadValidClientId;
127127
if (!AadClientId) {
128128
request.log.error(
129129
"Server is misconfigured, could not find `AadValidClientId`!",

src/routes/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const getResponseJsonSchema = zodToJsonSchema(getResponseBodySchema);
5353
type EventsGetQueryParams = { upcomingOnly?: boolean };
5454

5555
const dynamoClient = new DynamoDBClient({
56-
region: process.env.AWS_REGION || "us-east-1",
56+
region: genericConfig.AwsRegion,
5757
});
5858

5959
const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {

src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FastifyRequest, FastifyInstance, FastifyReply } from "fastify";
22
import { AppRoles, RunEnvironment } from "./roles.ts";
33
import { AadToken } from "./plugins/auth.ts";
4+
import { ConfigType } from "./config.ts";
45
declare module "fastify" {
56
interface FastifyInstance {
67
authenticate: (
Binary file not shown.
Binary file not shown.

tests/live_integration/test_events.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def test_get_events(api_client):
2+
response = api_client.get("/api/v1/events")
3+
assert response.status_code == 200
4+
assert response.json() != []
5+
6+
def test_post_events_unauthenticated(api_client):
7+
response = api_client.post("/api/v1/events")
8+
assert response.status_code == 403
9+
assert response.json()

0 commit comments

Comments
 (0)