Abort when MinIO bucket does not have versioning enabled #545 (#546)

Co-authored-by: Florent FAYOLLE <florent.fayolle@beta.gouv.fr>
This commit is contained in:
Florent
2023-07-10 12:24:55 +02:00
committed by GitHub
parent a56b0448ff
commit b6b2d05be0
7 changed files with 69 additions and 39 deletions

View File

@@ -1124,7 +1124,6 @@ export class FlexServer implements GristServer {
await this.loadConfig();
this.addComm();
await this.create.configure?.();
if (!isSingleUserMode()) {
const externalStorage = appSettings.section('externalStorage');
const haveExternalStorage = Object.values(externalStorage.nested)
@@ -1135,6 +1134,7 @@ export class FlexServer implements GristServer {
this._disableExternalStorage = true;
externalStorage.flag('active').set(false);
}
await this.create.configure?.();
const workers = this._docWorkerMap;
const docWorkerId = await this._addSelfAsWorker(workers);

View File

@@ -50,6 +50,7 @@ export interface ICreateActiveDocOptions {
export interface ICreateStorageOptions {
name: string;
check(): boolean;
checkBackend?(): Promise<void>;
create(purpose: 'doc'|'meta', extraPrefix: string): ExternalStorage|undefined;
}
@@ -119,7 +120,10 @@ export function makeSimpleCreator(opts: {
},
async configure() {
for (const s of storage || []) {
if (s.check()) { break; }
if (s.check()) {
await s.checkBackend?.();
break;
}
}
},
...(opts.shell && {

View File

@@ -107,6 +107,11 @@ export class MinIOExternalStorage implements ExternalStorage {
}
}
public async hasVersioning(): Promise<Boolean> {
const versioning = await this._s3.getBucketVersioning(this.bucket);
return versioning && versioning.Status === 'Enabled';
}
public async versions(key: string, options?: { includeDeleteMarkers?: boolean }) {
const results: minio.BucketItem[] = [];
await new Promise((resolve, reject) => {

View File

@@ -60,3 +60,16 @@ export function checkMinIOExternalStorage() {
region
};
}
export async function checkMinIOBucket() {
const options = checkMinIOExternalStorage();
if (!options) {
throw new Error('Configuration check failed for MinIO backend storage.');
}
const externalStorage = new MinIOExternalStorage(options.bucket, options);
if (!await externalStorage.hasVersioning()) {
await externalStorage.close();
throw new Error(`FATAL: the MinIO bucket "${options.bucket}" does not have versioning enabled`);
}
}