Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanketika-obsrv/Issue-tracker #OBS-139: added cretentials for aws #190

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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