Skip to content

Commit

Permalink
Merge pull request #38 from bcgov/grant-bucket-permissions
Browse files Browse the repository at this point in the history
Grant bucket access
  • Loading branch information
mgtennant authored Oct 9, 2024
2 parents 8af7251 + 593b0cf commit c891bc6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions backend/src/file_submissions/file_submissions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,41 @@ export class FileSubmissionsService {
}
}

/**
* Grants the current IDIR user the ability to upload files to the S3 bucket
* @param token
*/
async function grantBucketAccess(token: string) {
const axios = require("axios");

let config = {
method: "put",
url: `${process.env.COMS_URI}/v1/bucket`,
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
data: {
accessKeyId: process.env.OBJECTSTORE_ACCESS_KEY,
bucket: process.env.OBJECTSTORE_BUCKET,
bucketName: process.env.OBJECTSTORE_BUCKET_NAME,
endpoint: process.env.OBJECTSTORE_URL,
secretAccessKey: process.env.OBJECTSTORE_SECRET_KEY,
active: true,
key: "/",
permCodes: ["CREATE"],
},
};

await axios
.request(config)
.then((res) => console.log(res))
.catch((err) => {
console.log("create bucket failed");
console.log(err);
});
}

async function saveToS3(token: any, file: Express.Multer.File) {
const path = require("path");
let fileGUID = null;
Expand All @@ -225,6 +260,8 @@ async function saveToS3(token: any, file: Express.Multer.File) {

const axios = require("axios");

await grantBucketAccess(token);

let config = {
method: "put",
maxBodyLength: Infinity,
Expand Down

0 comments on commit c891bc6

Please sign in to comment.