2022-12-21 15:11:25 +00:00
|
|
|
import {wrapWithKeyMappedStorage} from 'app/server/lib/ExternalStorage';
|
|
|
|
import {appSettings} from 'app/server/lib/AppSettings';
|
|
|
|
import {MinIOExternalStorage} from 'app/server/lib/MinIOExternalStorage';
|
|
|
|
|
|
|
|
export function configureMinIOExternalStorage(purpose: 'doc'|'meta', extraPrefix: string) {
|
|
|
|
const options = checkMinIOExternalStorage();
|
|
|
|
if (!options?.bucket) { return undefined; }
|
|
|
|
return wrapWithKeyMappedStorage(new MinIOExternalStorage(options.bucket, options), {
|
|
|
|
basePrefix: options.prefix,
|
|
|
|
extraPrefix,
|
|
|
|
purpose,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function checkMinIOExternalStorage() {
|
|
|
|
const settings = appSettings.section('externalStorage').section('minio');
|
|
|
|
const bucket = settings.flag('bucket').readString({
|
|
|
|
envVar: ['GRIST_DOCS_MINIO_BUCKET', 'TEST_MINIO_BUCKET'],
|
|
|
|
preferredEnvVar: 'GRIST_DOCS_MINIO_BUCKET',
|
|
|
|
});
|
|
|
|
if (!bucket) { return undefined; }
|
|
|
|
const prefix = settings.flag('prefix').requireString({
|
|
|
|
envVar: ['GRIST_DOCS_MINIO_PREFIX'],
|
|
|
|
preferredEnvVar: 'GRIST_DOCS_MINIO_PREFIX',
|
|
|
|
defaultValue: 'docs/',
|
|
|
|
});
|
|
|
|
const endPoint = settings.flag('endpoint').requireString({
|
|
|
|
envVar: ['GRIST_DOCS_MINIO_ENDPOINT'],
|
|
|
|
preferredEnvVar: 'GRIST_DOCS_MINIO_ENDPOINT',
|
|
|
|
});
|
|
|
|
const port = settings.flag('port').read({
|
|
|
|
envVar: ['GRIST_DOCS_MINIO_PORT'],
|
|
|
|
preferredEnvVar: 'GRIST_DOCS_MINIO_PORT',
|
|
|
|
}).getAsInt();
|
|
|
|
const useSSL = settings.flag('useSsl').read({
|
|
|
|
envVar: ['GRIST_DOCS_MINIO_USE_SSL'],
|
|
|
|
}).getAsBool();
|
|
|
|
const accessKey = settings.flag('accessKey').requireString({
|
|
|
|
envVar: ['GRIST_DOCS_MINIO_ACCESS_KEY'],
|
2022-12-22 17:58:39 +00:00
|
|
|
censor: true,
|
2022-12-21 15:11:25 +00:00
|
|
|
});
|
|
|
|
const secretKey = settings.flag('secretKey').requireString({
|
|
|
|
envVar: ['GRIST_DOCS_MINIO_SECRET_KEY'],
|
2022-12-22 17:58:39 +00:00
|
|
|
censor: true,
|
2022-12-21 15:11:25 +00:00
|
|
|
});
|
|
|
|
settings.flag('url').set(`minio://${bucket}/${prefix}`);
|
|
|
|
settings.flag('active').set(true);
|
|
|
|
return {
|
|
|
|
endPoint,
|
|
|
|
port,
|
|
|
|
bucket, prefix,
|
|
|
|
useSSL,
|
|
|
|
accessKey,
|
|
|
|
secretKey,
|
|
|
|
};
|
|
|
|
}
|