|
|
@ -33,13 +33,14 @@ export class Exporter { |
|
|
|
this._task.id = uuidv4(); |
|
|
|
this._task.id = uuidv4(); |
|
|
|
this._task.progress = _.cloneDeep(DEFAULT_PROGRESS); |
|
|
|
this._task.progress = _.cloneDeep(DEFAULT_PROGRESS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._validateQueries(task.queries); |
|
|
|
|
|
|
|
this._validateDatasourceUrl(datasourceUrl); |
|
|
|
|
|
|
|
|
|
|
|
const targets = task.queries.map((query: DashboardQuery) => new Target( |
|
|
|
const targets = task.queries.map((query: DashboardQuery) => new Target( |
|
|
|
query.panel, |
|
|
|
query.panel, |
|
|
|
query.datasource, |
|
|
|
query.datasource, |
|
|
|
)); |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
this._validateTargets(datasourceUrl, targets); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this._updateProgress(); |
|
|
|
await this._updateProgress(); |
|
|
|
|
|
|
|
|
|
|
|
const queryConfigs = targets.map( |
|
|
|
const queryConfigs = targets.map( |
|
|
@ -127,15 +128,22 @@ export class Exporter { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _validateTargets(datasourceUrl: string, targets: Target[]) { |
|
|
|
private _validateQueries(queries: DashboardQuery[]) { |
|
|
|
if(!targets || !Array.isArray(targets)) { |
|
|
|
if(!queries || !Array.isArray(queries)) { |
|
|
|
throw new Error('Incorrect targets format'); |
|
|
|
throw new Error('`queries` field is required and should be an array'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(targets.length > 1) { |
|
|
|
for(const query of queries) { |
|
|
|
throw new Error(`Multiple queries are not supported yet`); |
|
|
|
if(!_.isEmpty(query.datasource)) { |
|
|
|
|
|
|
|
throw new Error('all queries should have a `datasource` field'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(!_.isEmpty(query.panel.targets)) { |
|
|
|
|
|
|
|
throw new Error('all queries should have a `panel` field with non-empty `targets` field'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private _validateDatasourceUrl(datasourceUrl: string) { |
|
|
|
const host = new URL(datasourceUrl).origin; |
|
|
|
const host = new URL(datasourceUrl).origin; |
|
|
|
const apiKey = apiKeys[host]; |
|
|
|
const apiKey = apiKeys[host]; |
|
|
|
|
|
|
|
|
|
|
|