Skip to content

Commit 2336194

Browse files
author
Tarash Agarwal
committed
Merge branch 'main' of github.com:acm-uiuc/core into siglead-management
2 parents 5ab43ab + 8a366c6 commit 2336194

File tree

3 files changed

+92
-16
lines changed

3 files changed

+92
-16
lines changed

cloudformation/main.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ Resources:
678678
Type: AWS::CloudFront::Distribution
679679
Properties:
680680
DistributionConfig:
681+
HttpVersion: 'http2and3'
681682
Origins:
682683
- Id: S3WebsiteOrigin
683684
DomainName: !GetAtt AppFrontendS3Bucket.RegionalDomainName
@@ -699,6 +700,7 @@ Resources:
699700
- UiDomainName
700701

701702
DefaultCacheBehavior:
703+
Compress: true
702704
TargetOriginId: S3WebsiteOrigin
703705
ViewerProtocolPolicy: redirect-to-https
704706
AllowedMethods:
@@ -732,6 +734,7 @@ Resources:
732734
- HEAD
733735
CachePolicyId: !Ref CloudfrontCachePolicy
734736
OriginRequestPolicyId: 216adef6-5c7f-47e4-b989-5492eafa07d3
737+
Compress: true
735738
- PathPattern: "/api/v1/organizations"
736739
TargetOriginId: ApiGatewayOrigin
737740
ViewerProtocolPolicy: redirect-to-https
@@ -748,6 +751,7 @@ Resources:
748751
- HEAD
749752
CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6"
750753
OriginRequestPolicyId: 216adef6-5c7f-47e4-b989-5492eafa07d3
754+
Compress: true
751755
- PathPattern: "/api/documentation*"
752756
TargetOriginId: ApiGatewayOrigin
753757
ViewerProtocolPolicy: redirect-to-https
@@ -764,6 +768,7 @@ Resources:
764768
- HEAD
765769
CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6"
766770
OriginRequestPolicyId: 216adef6-5c7f-47e4-b989-5492eafa07d3
771+
Compress: true
767772
- PathPattern: "/api/*"
768773
TargetOriginId: ApiGatewayOrigin
769774
ViewerProtocolPolicy: redirect-to-https
@@ -778,16 +783,16 @@ Resources:
778783
CachedMethods:
779784
- GET
780785
- HEAD
781-
CachePolicyId: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad # caching disabled
786+
CachePolicyId: !Ref CloudfrontNoCachePolicy # caching disabled
782787
OriginRequestPolicyId: 216adef6-5c7f-47e4-b989-5492eafa07d3
788+
Compress: true
783789
ViewerCertificate:
784790
AcmCertificateArn: !FindInMap
785791
- ApiGwConfig
786792
- !Ref RunEnvironment
787793
- EnvCertificateArn
788794
MinimumProtocolVersion: TLSv1.2_2021
789795
SslSupportMethod: sni-only
790-
HttpVersion: http2
791796
PriceClass: PriceClass_100
792797

793798
AppFrontendS3BucketPolicy:
@@ -803,6 +808,25 @@ Resources:
803808
Action: s3:GetObject
804809
Resource: !Sub "${AppFrontendS3Bucket.Arn}/*"
805810

811+
CloudfrontNoCachePolicy:
812+
Type: AWS::CloudFront::CachePolicy
813+
Properties:
814+
CachePolicyConfig:
815+
Comment: Cache policy with caching disabled and Gzip/Brotli enabled
816+
DefaultTTL: 0
817+
MaxTTL: 1
818+
MinTTL: 0
819+
Name: NoCache-GzipBrotli-Enabled
820+
ParametersInCacheKeyAndForwardedToOrigin:
821+
CookiesConfig:
822+
CookieBehavior: none
823+
EnableAcceptEncodingBrotli: true
824+
EnableAcceptEncodingGzip: true
825+
HeadersConfig:
826+
HeaderBehavior: none
827+
QueryStringsConfig:
828+
QueryStringBehavior: none
829+
806830
CloudfrontCachePolicy:
807831
Type: AWS::CloudFront::CachePolicy
808832
Properties:
@@ -860,6 +884,7 @@ Resources:
860884
Type: AWS::CloudFront::Distribution
861885
Properties:
862886
DistributionConfig:
887+
HttpVersion: 'http2and3'
863888
Origins:
864889
- Id: ApiGatewayOrigin
865890
DomainName: !Sub "${AppApiGateway}.execute-api.${AWS::Region}.amazonaws.com"
@@ -878,6 +903,7 @@ Resources:
878903
- !Ref RunEnvironment
879904
- EnvDomainName
880905
DefaultCacheBehavior:
906+
Compress: true
881907
TargetOriginId: ApiGatewayOrigin
882908
ViewerProtocolPolicy: redirect-to-https
883909
AllowedMethods:
@@ -904,7 +930,6 @@ Resources:
904930
- EnvCertificateArn
905931
MinimumProtocolVersion: TLSv1.2_2021
906932
SslSupportMethod: sni-only
907-
HttpVersion: http2
908933
PriceClass: PriceClass_100
909934

910935
LinkryRecordsCloudfrontStore:
@@ -962,6 +987,7 @@ Resources:
962987
Type: AWS::CloudFront::Distribution
963988
Properties:
964989
DistributionConfig:
990+
HttpVersion: 'http2and3'
965991
Enabled: true
966992
DefaultCacheBehavior:
967993
ViewerProtocolPolicy: redirect-to-https
@@ -993,7 +1019,6 @@ Resources:
9931019
- EnvCertificateArn
9941020
MinimumProtocolVersion: TLSv1.2_2021
9951021
SslSupportMethod: sni-only
996-
HttpVersion: http2
9971022
PriceClass: PriceClass_100
9981023

9991024
LinkryDomainProxy:

src/common/types/apiKey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if (policySchemas.length === 0) {
3636
})
3737
}
3838

39-
const policyUnion = policySchemas.length > 0
39+
export const policyUnion = policySchemas.length > 0
4040
? z.discriminatedUnion("name", policySchemas as [typeof policySchemas[0], ...typeof policySchemas])
4141
: z.never();
4242

src/ui/pages/apiKeys/ManageKeysTable.tsx

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {
2+
Alert,
23
Badge,
34
Button,
45
Center,
56
Checkbox,
67
Code,
78
CopyButton,
89
Group,
10+
JsonInput,
911
List,
1012
Modal,
1113
MultiSelect,
@@ -18,6 +20,7 @@ import { DateTimePicker } from "@mantine/dates";
1820
import {
1921
IconAlertCircle,
2022
IconEye,
23+
IconHandStop,
2124
IconPlus,
2225
IconTrash,
2326
} from "@tabler/icons-react";
@@ -26,13 +29,15 @@ import {
2629
apiKeyAllowedRoles,
2730
ApiKeyMaskedEntry,
2831
ApiKeyPostBody,
32+
policyUnion,
2933
} from "@common/types/apiKey";
3034
import { useAuth } from "@ui/components/AuthContext";
3135
import { notifications } from "@mantine/notifications";
3236
import pluralize from "pluralize";
3337
import dayjs from "dayjs";
3438
import { AppRoles } from "@common/roles";
3539
import { BlurredTextDisplay } from "../../components/BlurredTextDisplay";
40+
import { z } from "zod";
3641

3742
const HumanFriendlyDate = ({ date }: { date: number }) => {
3843
return (
@@ -131,8 +136,8 @@ export const OrgApiKeyTable: React.FC<OrgApiKeyTableProps> = ({
131136
await fetchKeys();
132137
} catch (e) {
133138
notifications.show({
134-
title: "Create failed",
135-
message: "Unable to create API key.",
139+
title: "Unable to create API key.",
140+
message: "Please try again or contact support.",
136141
color: "red",
137142
});
138143
}
@@ -188,6 +193,7 @@ export const OrgApiKeyTable: React.FC<OrgApiKeyTableProps> = ({
188193
const [roles, setRoles] = useState<AppRoles[]>([]);
189194
const [description, setDescription] = useState("");
190195
const [expiresAt, setExpiresAt] = useState<Date | null>(null);
196+
const [policyDocument, setPolicyDocument] = useState("");
191197

192198
return (
193199
<>
@@ -309,17 +315,62 @@ export const OrgApiKeyTable: React.FC<OrgApiKeyTableProps> = ({
309315
clearable
310316
mt="md"
311317
/>
318+
<JsonInput
319+
label="Policy Document (optional)"
320+
description={
321+
<Alert
322+
icon={<IconHandStop />}
323+
title="Advanced Feature"
324+
color="orange"
325+
>
326+
Errors in this field will prevent your API key from working!
327+
Please consult the API documentation for instructions.
328+
</Alert>
329+
}
330+
value={policyDocument}
331+
onChange={setPolicyDocument}
332+
placeholder={`[
333+
{
334+
"name": "EventsHostRestrictionPolicy",
335+
"params": {
336+
"host": [
337+
"ACM"
338+
]
339+
}
340+
}
341+
]`}
342+
validationError="Invalid JSON"
343+
formatOnBlur
344+
autosize
345+
minRows={6}
346+
/>
312347
<Group justify="flex-end" mt="lg">
313348
<Button
314-
onClick={() =>
315-
handleCreate({
316-
roles,
317-
description,
318-
expiresAt: expiresAt
319-
? Math.floor(expiresAt.getTime() / 1000)
320-
: undefined,
321-
})
322-
}
349+
onClick={() => {
350+
let parsedPolicyDocument = undefined;
351+
try {
352+
if (policyDocument && policyDocument.trim() !== "") {
353+
parsedPolicyDocument = z
354+
.array(policyUnion)
355+
.parse(JSON.parse(policyDocument));
356+
}
357+
handleCreate({
358+
roles,
359+
description,
360+
expiresAt: expiresAt
361+
? Math.floor(expiresAt.getTime() / 1000)
362+
: undefined,
363+
restrictions: parsedPolicyDocument,
364+
});
365+
} catch (e) {
366+
console.error(e);
367+
notifications.show({
368+
title: "Invalid policy document!",
369+
message: "Please correct the policy document and try again.",
370+
color: "red",
371+
});
372+
}
373+
}}
323374
disabled={roles.length === 0 || description.trim() === ""}
324375
>
325376
Create

0 commit comments

Comments
 (0)