Skip to content

Commit d14a20b

Browse files
authored
Merge pull request #367 from Sanketika-Obsrv/api-svc-fixes
#OI-I3: Fix: Mandatory header required during azure blob upload
2 parents 8d5a757 + 0f6f9a4 commit d14a20b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

api-service/src/configs/Config.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getCloudConfigs = () => {
1414
return parsedCloudConfig;
1515
}
1616
return {};
17-
}
17+
}
1818

1919

2020
export const config = {
@@ -30,8 +30,8 @@ export const config = {
3030
"native_query_path": "/druid/v2",
3131
"list_datasources_path": "/druid/v2/datasources",
3232
"submit_ingestion": "druid/indexer/v1/supervisor",
33-
"username": process.env.druid_username || "admin",
34-
"password": process.env.druid_password || "admin123"
33+
"username": process.env.druid_username || "admin",
34+
"password": process.env.druid_password || "admin123"
3535
},
3636
"prometheus": {
3737
"url": process.env.prometheus_url || "http://localhost:9090"
@@ -102,6 +102,7 @@ export const config = {
102102
"maxQueryDateRange": process.env.exhaust_query_range ? parseInt(process.env.exhaust_query_range) : 31, // in days. Defines the maximum no. of days the files can be fetched
103103
"exclude_exhaust_types": process.env.exclude_exhaust_types ? process.env.exclude_exhaust_types.split(",") : ["system-stats", "masterdata-system-stats", "system-events",], // list of folder type names to skip exhaust service
104104
"telemetry_data_path": process.env.telemetry_data_path || "telemetry-data",
105+
"azure_blob_type": process.env.azure_blob_type || "BlockBlob"
105106
},
106107
"template_config": {
107108
"template_required_variables": process.env.template_required_vars ? process.env.template_required_vars.split(",") : ["DATASET", "STARTDATE", "ENDDATE"],
@@ -149,5 +150,5 @@ export const config = {
149150
},
150151
"dataset_filter_config": {
151152
"status_filter_limit": process.env.status_filter_limit ? parseInt(process.env.status_filter_limit) : 10 // Maximum number of filters allowed in a dataset
152-
}
153+
}
153154
}

api-service/src/controllers/ConnectorRegister/ConnectorRegisterController.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { PassThrough } from "stream";
99
import { registerConnector } from "../../connections/commandServiceConnection";
1010
import { generatePreSignedUrl } from "../GenerateSignedURL/helper";
1111
import { obsrvError } from "../../types/ObsrvError";
12+
import { config } from "../../configs/Config";
1213

1314
export const apiId = "api.connector.register";
1415
export const code = "FAILED_TO_REGISTER_CONNECTOR";
@@ -25,11 +26,11 @@ const connectorRegisterController = async (req: Request, res: Response) => {
2526
logger.info({ apiId, resmsgid, message: `File uploaded to cloud provider successfully` })
2627
const downloadUrls = await generatePreSignedUrl("read", [payload.relative_path], "connector")
2728
const urlPayload = {
28-
download_url : _.get(downloadUrls, [0, "preSignedUrl"]),
29+
download_url: _.get(downloadUrls, [0, "preSignedUrl"]),
2930
file_name: _.get(downloadUrls, [0, "fileName"])
3031
}
31-
if(!urlPayload.download_url){
32-
throw obsrvError("", "SIGNED_URL_NOT_FOUND",`Failed to generate signed url for path ${payload.relative_path}`, "BAD_REQUEST", 400)
32+
if (!urlPayload.download_url) {
33+
throw obsrvError("", "SIGNED_URL_NOT_FOUND", `Failed to generate signed url for path ${payload.relative_path}`, "BAD_REQUEST", 400)
3334
}
3435
const userToken = req.get('authorization') as string;
3536
const registryResponse = await registerConnector(urlPayload, userToken);
@@ -76,11 +77,18 @@ const uploadStream = async (req: Request) => {
7677
const pass = new PassThrough();
7778
file.pipe(pass);
7879
const fileBuffer = await streamToBuffer(pass);
80+
81+
const uploadHeaders: any = {
82+
"Content-Type": info.mimeType,
83+
"Content-Length": fileBuffer.length,
84+
};
85+
86+
if (config.cloud_config.cloud_storage_provider === "azure") {
87+
uploadHeaders["x-ms-blob-type"] = config.cloud_config.azure_blob_type;
88+
}
89+
7990
await axios.put(preSignedUrl[0]?.preSignedUrl, fileBuffer, {
80-
headers: {
81-
"Content-Type": info.mimeType,
82-
"Content-Length": fileBuffer.length,
83-
}
91+
headers: uploadHeaders
8492
});
8593
}
8694
catch (err) {

0 commit comments

Comments
 (0)