Allow s3 credentials via env (#6066)

closes #5072
This commit is contained in:
brendanlaschke 2024-06-30 21:47:51 +02:00 committed by GitHub
parent cce9bf5730
commit afb3f4b7b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 3 deletions

View File

@ -220,6 +220,16 @@ export class EnvironmentVariables {
@IsOptional()
STORAGE_S3_ENDPOINT: string;
@ValidateIf((env) => env.STORAGE_TYPE === StorageDriverType.S3)
@IsString()
@IsOptional()
STORAGE_S3_ACCESS_KEY_ID: string;
@ValidateIf((env) => env.STORAGE_TYPE === StorageDriverType.S3)
@IsString()
@IsOptional()
STORAGE_S3_SECRET_ACCESS_KEY: string;
@IsString()
@ValidateIf((env) => env.STORAGE_TYPE === StorageDriverType.Local)
STORAGE_LOCAL_PATH = '.local-storage';

View File

@ -32,15 +32,24 @@ export const fileStorageModuleFactory = async (
const bucketName = environmentService.get('STORAGE_S3_NAME');
const endpoint = environmentService.get('STORAGE_S3_ENDPOINT');
const region = environmentService.get('STORAGE_S3_REGION');
const accessKeyId = environmentService.get('STORAGE_S3_ACCESS_KEY_ID');
const secretAccessKey = environmentService.get(
'STORAGE_S3_SECRET_ACCESS_KEY',
);
return {
type: StorageDriverType.S3,
options: {
bucketName: bucketName ?? '',
endpoint: endpoint,
credentials: fromNodeProviderChain({
clientConfig: { region },
}),
credentials: accessKeyId
? {
accessKeyId,
secretAccessKey,
}
: fromNodeProviderChain({
clientConfig: { region },
}),
forcePathStyle: true,
region: region ?? '',
},

View File

@ -142,6 +142,8 @@ yarn command:prod cron:calendar:google-calendar-sync
['STORAGE_S3_REGION', '', 'Storage Region'],
['STORAGE_S3_NAME', '', 'Bucket Name'],
['STORAGE_S3_ENDPOINT', '', 'Use if a different Endpoint is needed (for example Google)'],
['STORAGE_S3_ACCESS_KEY_ID', '', 'Optional depending on the authentication method'],
['STORAGE_S3_SECRET_ACCESS_KEY', '', 'Optional depending on the authentication method'],
['STORAGE_LOCAL_PATH', '.local-storage', 'data path (local storage)'],
]}></ArticleTable>