diff --git a/src/routes/tasks.ts b/src/routes/tasks.ts index 1d417ef..de068b7 100644 --- a/src/routes/tasks.ts +++ b/src/routes/tasks.ts @@ -17,6 +17,7 @@ type TRequest = { task: ExportTask, url: string, timeZoneName: string, + apiKey: string, }, }; @@ -66,6 +67,11 @@ async function addTask(req: TRequest, res) { res.status(400).send('"task" field is required'); return; } + const apiKey = body.apiKey; + if (_.isEmpty(apiKey)) { + res.status(400).send('"apiKey" field is required'); + return; + } try { validateGrafanaUrl(clientUrl); @@ -87,7 +93,7 @@ async function addTask(req: TRequest, res) { } const exporter = exporterFactory.getExporter(); - exporter.export(task, datasourceUrl, body.timeZoneName); + exporter.export(task, datasourceUrl, body.timeZoneName, apiKey); res.status(200).send(`Export process started`); } diff --git a/src/services/exporter.ts b/src/services/exporter.ts index 0b18413..7c4c2e3 100644 --- a/src/services/exporter.ts +++ b/src/services/exporter.ts @@ -29,7 +29,7 @@ const DEFAULT_PROGRESS = { export class Exporter { private _task: ExportTask; - public async export(task: ExportTask, datasourceUrl: string, timeZoneName: string) { + public async export(task: ExportTask, datasourceUrl: string, timeZoneName: string, apiKey: string) { try { this._task = _.cloneDeep(task); this._task.id = uuidv4(); @@ -72,9 +72,6 @@ export class Exporter { let values = []; for(const queryConfig of queryConfigs) { - const host = new URL(datasourceUrl).origin; - const apiKey = getApiKey(host); - const datasourceMetrics = await queryByConfig(queryConfig, datasourceUrl, from, to, apiKey); if(_.isEmpty(columns)) {