Skip to content

Commit

Permalink
Allow S3 empty config values to allow IAM Roles
Browse files Browse the repository at this point in the history
  • Loading branch information
cruizba committed Nov 4, 2024
1 parent e15c973 commit 0e0a017
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
8 changes: 4 additions & 4 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET || 'secret';

// S3 configuration
export const CALL_S3_BUCKET = process.env.CALL_S3_BUCKET || 'openvidu';
export const CALL_S3_SERVICE_ENDPOINT = process.env.CALL_S3_SERVICE_ENDPOINT || 'http://localhost:9000';
export const CALL_S3_ACCESS_KEY = process.env.CALL_S3_ACCESS_KEY || 'minioadmin';
export const CALL_S3_SECRET_KEY = process.env.CALL_S3_SECRET_KEY || 'minioadmin';
export const CALL_AWS_REGION = process.env.CALL_AWS_REGION || 'us-east-1';
export const CALL_S3_SERVICE_ENDPOINT = process.env.CALL_S3_SERVICE_ENDPOINT || undefined;
export const CALL_S3_ACCESS_KEY = process.env.CALL_S3_ACCESS_KEY || undefined;
export const CALL_S3_SECRET_KEY = process.env.CALL_S3_SECRET_KEY || undefined;
export const CALL_AWS_REGION = process.env.CALL_AWS_REGION || undefined;
export const CALL_S3_WITH_PATH_STYLE_ACCESS = process.env.CALL_S3_WITH_PATH_STYLE_ACCESS || 'true';
22 changes: 18 additions & 4 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,24 @@ const logEnvVars = () => {
console.log('S3 Configuration');
console.log('---------------------------------------------------------');
console.log('CALL S3 BUCKET:', text(CALL_S3_BUCKET));
console.log('CALL S3 SERVICE ENDPOINT:', text(CALL_S3_SERVICE_ENDPOINT));
console.log('CALL S3 ACCESS KEY:', credential('****' + CALL_S3_ACCESS_KEY.slice(-3)));
console.log('CALL S3 SECRET KEY:', credential('****' + CALL_S3_SECRET_KEY.slice(-3)));
console.log('CALL AWS REGION:', text(CALL_AWS_REGION));

// S3 configuration
if (CALL_S3_SERVICE_ENDPOINT) {
console.log('CALL S3 SERVICE ENDPOINT:', text(CALL_S3_SERVICE_ENDPOINT));
}

if (CALL_S3_ACCESS_KEY) {
console.log('CALL S3 ACCESS KEY:', credential('****' + CALL_S3_ACCESS_KEY.slice(-3)));
}

if (CALL_S3_SECRET_KEY) {
console.log('CALL S3 SECRET KEY:', credential('****' + CALL_S3_SECRET_KEY.slice(-3)));
}

if (CALL_AWS_REGION) {
console.log('CALL AWS REGION:', text(CALL_AWS_REGION));
}

console.log('---------------------------------------------------------');
};

Expand Down
23 changes: 16 additions & 7 deletions backend/src/services/s3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,24 @@ export class S3Service {
protected static instance: S3Service;

constructor() {
const config: S3ClientConfig = {
region: CALL_AWS_REGION,
credentials: {
const config: S3ClientConfig = {};

if (CALL_AWS_REGION) {
config.endpoint = CALL_S3_SERVICE_ENDPOINT;
}

if (CALL_S3_ACCESS_KEY && CALL_S3_SECRET_KEY) {
config.credentials = {
accessKeyId: CALL_S3_ACCESS_KEY,
secretAccessKey: CALL_S3_SECRET_KEY
},
endpoint: CALL_S3_SERVICE_ENDPOINT,
forcePathStyle: CALL_S3_WITH_PATH_STYLE_ACCESS === 'true'
};
};
}

if (CALL_S3_SERVICE_ENDPOINT) {
config.endpoint = CALL_S3_SERVICE_ENDPOINT;
}

config.forcePathStyle = CALL_S3_WITH_PATH_STYLE_ACCESS === 'true';

this.s3 = new S3Client(config);
}
Expand Down

0 comments on commit 0e0a017

Please sign in to comment.