Skip to content

Commit

Permalink
Merge pull request #190 from Sanketika-Obsrv/config-change
Browse files Browse the repository at this point in the history
Sanketika-obsrv/Issue-tracker #OBS-139: added cretentials for aws
  • Loading branch information
HarishGangula authored Jun 18, 2024
2 parents 3dd90c3 + 5438f4b commit 5fd761f
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions api-service/src/v2/services/CloudServices/AWSStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ import { config as globalConfig } from "../../configs/Config";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
import { getFileKey } from "../../utils/common"
import { FilterDataByDateRange, ICloudService } from "./types";
import { logger } from "@azure/storage-blob";
import { URLAccess } from "../../types/SampleURLModel";
import logger from "../../logger";

export class AWSStorageService implements ICloudService {
client: any;
constructor(config: any) {
if (_.get(config, "identity") && _.get(config, "credential") && _.get(config, "region")) {
const region = _.get(config, "region").toString();
this.client = new S3Client({ region });
} else {
const region = globalConfig.cloud_config.cloud_storage_region || "us-east-2";
const s3Client = new S3Client({
region,
});
this.client = s3Client;
const region = _.get(config, "region")
const accessKeyId = _.get(config, "identity")
const secretAccessKey = _.get(config, "credential")
const configuration = { region, credentials: { accessKeyId, secretAccessKey } }
try {
this.client = new S3Client(configuration);
}
catch (err) {
logger.error(err)
}
}
}

Expand All @@ -39,12 +41,18 @@ export class AWSStorageService implements ICloudService {
const AWSCommand = access === URLAccess.Read ? this.getAWSCommand : this.putAWSCommand
const containerURLExpiry = urlExpiry ? urlExpiry : globalConfig.cloud_config.storage_url_expiry
const signedURLs = filesList.map((fileNameWithPrefix: any) => {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
const generateSignedUrl = async () => {
const command = AWSCommand(container, fileNameWithPrefix);
const fileName = fileNameWithPrefix.split("/").pop();
const presignedURL = await getSignedUrl(this.client, command, { expiresIn: containerURLExpiry });
resolve({ [fileName]: presignedURL });
try {
const command = AWSCommand(container, fileNameWithPrefix);
const fileName = fileNameWithPrefix.split("/").pop();
const presignedURL = await getSignedUrl(this.client, command, { expiresIn: containerURLExpiry });
resolve({ [fileName]: presignedURL });
}
catch (err: any) {
logger.error({ error: err?.message })
reject({ error: err?.message });
}
}
generateSignedUrl();
});
Expand Down

0 comments on commit 5fd761f

Please sign in to comment.