Browse Source

use apyKey as param on addTask

pull/11/head
vargburz 1 year ago
parent
commit
a9aae8d135
  1. 8
      src/routes/tasks.ts
  2. 5
      src/services/exporter.ts

8
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`);
}

5
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)) {

Loading…
Cancel
Save