2019-11-07 09:32:38 +00:00
|
|
|
import API from "./Api";
|
|
|
|
|
import { GenericApiResponse } from "./ApiResponses";
|
|
|
|
|
import { AxiosPromise } from "axios";
|
2020-05-07 08:07:29 +00:00
|
|
|
import { DEFAULT_TEST_DATA_SOURCE_TIMEOUT_MS } from "constants/ApiConstants";
|
2019-11-07 09:32:38 +00:00
|
|
|
|
|
|
|
|
interface DatasourceAuthentication {
|
2020-04-28 06:52:53 +00:00
|
|
|
authType?: string;
|
|
|
|
|
username?: string;
|
|
|
|
|
password?: string;
|
2019-11-07 09:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface Datasource {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
pluginId: string;
|
|
|
|
|
organizationId?: string;
|
|
|
|
|
datasourceConfiguration: {
|
|
|
|
|
url: string;
|
|
|
|
|
authentication?: DatasourceAuthentication;
|
|
|
|
|
properties?: Record<string, string>;
|
|
|
|
|
headers?: Record<string, string>;
|
|
|
|
|
databaseName?: string;
|
|
|
|
|
};
|
2020-07-01 10:01:07 +00:00
|
|
|
invalids?: string[];
|
|
|
|
|
isValid?: boolean;
|
2019-11-07 09:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateDatasourceConfig {
|
|
|
|
|
name: string;
|
|
|
|
|
pluginId: string;
|
|
|
|
|
datasourceConfiguration: {
|
|
|
|
|
url: string;
|
2020-04-28 06:52:53 +00:00
|
|
|
databaseName?: string;
|
|
|
|
|
authentication?: DatasourceAuthentication;
|
2019-11-07 09:32:38 +00:00
|
|
|
};
|
2020-03-06 04:59:24 +00:00
|
|
|
//Passed for logging purposes.
|
2020-04-28 06:52:53 +00:00
|
|
|
appName?: string;
|
2019-11-07 09:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DatasourcesApi extends API {
|
|
|
|
|
static url = "v1/datasources";
|
|
|
|
|
|
2020-06-17 10:19:56 +00:00
|
|
|
static fetchDatasources(
|
|
|
|
|
orgId: string,
|
|
|
|
|
): AxiosPromise<GenericApiResponse<Datasource[]>> {
|
|
|
|
|
return API.get(DatasourcesApi.url + `?organizationId=${orgId}`);
|
2019-11-07 09:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static createDatasource(datasourceConfig: Partial<Datasource>): Promise<{}> {
|
|
|
|
|
return API.post(DatasourcesApi.url, datasourceConfig);
|
|
|
|
|
}
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
static testDatasource(datasourceConfig: Partial<Datasource>): Promise<{}> {
|
2020-05-05 12:16:16 +00:00
|
|
|
return API.post(`${DatasourcesApi.url}/test`, datasourceConfig, undefined, {
|
2020-05-07 08:07:29 +00:00
|
|
|
timeout: DEFAULT_TEST_DATA_SOURCE_TIMEOUT_MS,
|
2020-05-05 12:16:16 +00:00
|
|
|
});
|
2020-04-28 06:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static updateDatasource(
|
|
|
|
|
datasourceConfig: Partial<Datasource>,
|
|
|
|
|
id: string,
|
|
|
|
|
): Promise<{}> {
|
|
|
|
|
return API.put(DatasourcesApi.url + `/${id}`, datasourceConfig);
|
|
|
|
|
}
|
2020-04-29 10:03:56 +00:00
|
|
|
|
|
|
|
|
static deleteDatasource(id: string): Promise<{}> {
|
|
|
|
|
return API.delete(DatasourcesApi.url + `/${id}`);
|
|
|
|
|
}
|
2019-11-07 09:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DatasourcesApi;
|