in src/backend/deny-list/client.lambda-shared.ts [37:76]
private async init() {
if (this._map) {
throw new Error('init() cannot be called twice');
}
this._map = {};
try {
const params = {
Bucket: this.bucketName,
Key: this.objectKey,
};
const { Body: body } = await this.s3.getObject(params).promise();
if (!body) {
console.log(`WARNING: deny list body is empty at ${this.bucketName}/${this.objectKey}`);
return;
}
const contents = body.toString('utf-8');
// an empty string is a valid (empty) deny list
if (contents.length === 0) {
return;
}
const data = JSON.parse(contents) as DenyListMap;
if (typeof(data) != 'object') {
throw new Error(`Invalid format in deny list file at ${this.bucketName}/${this.objectKey}. Expecting a map`);
}
this._map = data;
} catch (e) {
if (e.code === 'NoSuchKey' || e.code === 'NoSuchBucket') {
return;
}
throw new Error(`Unable to parse deny list file ${this.bucketName}/${this.objectKey}: ${e}`);
}
}