diff --git a/src/common/config/variables/Variables.ts b/src/common/config/variables/Variables.ts index 49ad7c2f..10df52e7 100644 --- a/src/common/config/variables/Variables.ts +++ b/src/common/config/variables/Variables.ts @@ -130,6 +130,18 @@ export class BackendVariables { @IsNotEmpty() public readonly SMS_FACTOR_TOKEN!: string; + @IsNotEmpty() + public readonly SCW_ACCESS_KEY_ID!: string; + + @IsNotEmpty() + public readonly SCW_ACCESS_KEY_SECRET!: string; + + @IsNotEmpty() + public readonly SCW_BUCKET_ENDPOINT!: string; + + @IsNotEmpty() + public readonly SCW_BUCKET_NAME!: string; + public constructor() { dotenv.config(); this.DATABASE_PORT = process.env["DATABASE_PORT"]!; @@ -174,6 +186,10 @@ export class BackendVariables { this.OVH_CONSUMER_KEY = process.env["OVH_CONSUMER_KEY"]!; this.OVH_SMS_SERVICE_NAME = process.env["OVH_SMS_SERVICE_NAME"]!; this.SMS_FACTOR_TOKEN = process.env["SMS_FACTOR_TOKEN"]!; + this.SCW_ACCESS_KEY_ID = process.env["SCW_ACCESS_KEY_ID"]!; + this.SCW_ACCESS_KEY_SECRET = process.env["SCW_ACCESS_KEY_SECRET"]!; + this.SCW_BUCKET_ENDPOINT = process.env["SCW_BUCKET_ENDPOINT"]!; + this.SCW_BUCKET_NAME = process.env["SCW_BUCKET_NAME"]!; } public async validate(groups?: string[]) { const validationOptions = groups ? { groups } : undefined; diff --git a/src/services/common/IdNotService/IdNotService.ts b/src/services/common/IdNotService/IdNotService.ts index b9157b6d..047868af 100644 --- a/src/services/common/IdNotService/IdNotService.ts +++ b/src/services/common/IdNotService/IdNotService.ts @@ -121,7 +121,6 @@ export default class IdNotService extends BaseService { code: code, grant_type: "authorization_code", }); - console.log(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query.toString()); const token = await fetch(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query, { method: "POST" }); if(token.status !== 200) console.error(await token.text()); diff --git a/src/services/common/OfficeRibService/OfficeRibService.ts b/src/services/common/OfficeRibService/OfficeRibService.ts index 535125bc..5ada46a8 100644 --- a/src/services/common/OfficeRibService/OfficeRibService.ts +++ b/src/services/common/OfficeRibService/OfficeRibService.ts @@ -4,29 +4,29 @@ import * as AWS from "aws-sdk"; import { BackendVariables } from "@Common/config/variables/Variables"; import path from "path"; -// Configure the AWS SDK for Scaleway -const s3 = new AWS.S3({ - accessKeyId: "SCWZ39ZVQWXFC7HA0647", - secretAccessKey: "59bcf27d-bee3-4d14-8b4d-03fd6a8be6cd", - endpoint: "https://lecoffre-bucket.s3.fr-par.scw.cloud", // Use the appropriate Scaleway endpoint - s3ForcePathStyle: true, // Needed for Scaleway's S3-compatible API - signatureVersion: "v4", -}); - @Service() export default class OfficerRibService extends BaseService { + private readonly s3: AWS.S3; constructor(private variables: BackendVariables) { super(); + + // Configure the AWS SDK for Scaleway + this.s3 = new AWS.S3({ + accessKeyId: this.variables.SCW_ACCESS_KEY_ID, + secretAccessKey: this.variables.SCW_ACCESS_KEY_SECRET, + endpoint: this.variables.SCW_BUCKET_ENDPOINT, // Use the appropriate Scaleway endpoint + s3ForcePathStyle: true, // Needed for Scaleway's S3-compatible API + signatureVersion: "v4", + }); } public async getByUid(uid: string, fileName: string) { const key = path.join(this.variables.ENV, uid, fileName); - - + return new Promise(async (resolve, reject) => { - s3.getObject( + this.s3.getObject( { - Bucket: "lecoffre-bucket", + Bucket: this.variables.SCW_BUCKET_NAME, Key: key, }, function (err, data) { @@ -34,21 +34,21 @@ export default class OfficerRibService extends BaseService { resolve(data); }, ); - }); + }); } public async createOrUpdate(officeId: string, file: Express.Multer.File) { const key = path.join(this.variables.ENV, officeId, file.originalname); const uploadParams = { - Bucket: "lecoffre-bucket", + Bucket: this.variables.SCW_BUCKET_NAME, Key: key, // Example: 'example.txt' Body: file.buffer, // Example: fs.createReadStream('/path/to/file') ACL: "public-read", // Optional: Set the ACL if needed }; return new Promise((resolve, reject) => { - s3.putObject(uploadParams, function (err, data) { + this.s3.putObject(uploadParams, function (err, data) { if (err) return reject(err); resolve(`https://lecoffre-bucket.s3.fr-par.scw.cloud/lecoffre-bucket/${key}`); }); @@ -59,9 +59,9 @@ export default class OfficerRibService extends BaseService { const key = path.join(this.variables.ENV, officeId, fileName); return new Promise(async (resolve, reject) => { - s3.getObject( + this.s3.getObject( { - Bucket: "lecoffre-bucket", + Bucket: this.variables.SCW_BUCKET_NAME, Key: key, }, function (err, data) { @@ -69,6 +69,6 @@ export default class OfficerRibService extends BaseService { resolve(data); }, ); - }); + }); } }