Skip to content

Commit e6c72d7

Browse files
authored
Merge pull request #965 from constructive-io/devin/1775276749-defensive-resolver-check
fix: add defensive checks in storage resolvers instead of non-null assertions
2 parents 2572aaf + 80a88bf commit e6c72d7

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

graphile/graphile-settings/src/bucket-provisioner-resolver.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,22 @@ export function getBucketProvisionerConnection(): StorageConnectionConfig {
2929

3030
const { cdn } = getEnvOptions();
3131

32-
// cdn is guaranteed populated — pgpmDefaults provides all CDN fields
33-
const { provider, awsRegion, awsAccessKey, awsSecretKey, endpoint } = cdn!;
32+
if (!cdn) {
33+
throw new Error(
34+
'[bucket-provisioner-resolver] CDN config not found. ' +
35+
'Ensure CDN environment variables (AWS_ACCESS_KEY, AWS_SECRET_KEY, etc.) ' +
36+
'are set or that pgpmDefaults provides CDN fields.',
37+
);
38+
}
39+
40+
const { provider, awsRegion, awsAccessKey, awsSecretKey, endpoint } = cdn;
41+
42+
if (!awsAccessKey || !awsSecretKey) {
43+
throw new Error(
44+
'[bucket-provisioner-resolver] Missing S3 credentials. ' +
45+
'Set AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables.',
46+
);
47+
}
3448

3549
log.info(
3650
`[bucket-provisioner-resolver] Initializing: provider=${provider} endpoint=${endpoint}`,
@@ -39,8 +53,8 @@ export function getBucketProvisionerConnection(): StorageConnectionConfig {
3953
connectionConfig = {
4054
provider: (provider as StorageConnectionConfig['provider']) || 'minio',
4155
region: awsRegion || 'us-east-1',
42-
accessKeyId: awsAccessKey!,
43-
secretAccessKey: awsSecretKey!,
56+
accessKeyId: awsAccessKey,
57+
secretAccessKey: awsSecretKey,
4458
...(endpoint ? { endpoint, forcePathStyle: true } : {}),
4559
};
4660

graphile/graphile-settings/src/presigned-url-resolver.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,43 @@ export function getPresignedUrlS3Config(): S3Config {
3838

3939
const { cdn } = getEnvOptions();
4040

41-
// cdn is guaranteed populated — pgpmDefaults provides all CDN fields
42-
const { bucketName, awsRegion, awsAccessKey, awsSecretKey, endpoint, publicUrlPrefix } = cdn!;
41+
if (!cdn) {
42+
throw new Error(
43+
'[presigned-url-resolver] CDN config not found. ' +
44+
'Ensure CDN environment variables (AWS_ACCESS_KEY, AWS_SECRET_KEY, etc.) ' +
45+
'are set or that pgpmDefaults provides CDN fields.',
46+
);
47+
}
48+
49+
const { bucketName, awsRegion, awsAccessKey, awsSecretKey, endpoint, publicUrlPrefix } = cdn;
50+
51+
if (!awsAccessKey || !awsSecretKey) {
52+
throw new Error(
53+
'[presigned-url-resolver] Missing S3 credentials. ' +
54+
'Set AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables.',
55+
);
56+
}
57+
58+
if (!bucketName) {
59+
throw new Error(
60+
'[presigned-url-resolver] Missing CDN bucket name. ' +
61+
'Set CDN_BUCKET_NAME environment variable.',
62+
);
63+
}
4364

4465
log.info(
4566
`[presigned-url-resolver] Initializing: bucket=${bucketName} endpoint=${endpoint}`,
4667
);
4768

4869
const client = new S3Client({
4970
region: awsRegion,
50-
credentials: { accessKeyId: awsAccessKey!, secretAccessKey: awsSecretKey! },
71+
credentials: { accessKeyId: awsAccessKey, secretAccessKey: awsSecretKey },
5172
...(endpoint ? { endpoint, forcePathStyle: true } : {}),
5273
});
5374

5475
s3Config = {
5576
client,
56-
bucket: bucketName!,
77+
bucket: bucketName,
5778
region: awsRegion,
5879
publicUrlPrefix,
5980
...(endpoint ? { endpoint, forcePathStyle: true } : {}),

0 commit comments

Comments
 (0)