diff --git a/public/JobHandler/index.ts b/public/JobHandler/index.ts index 1798e4625..f07bd9c29 100644 --- a/public/JobHandler/index.ts +++ b/public/JobHandler/index.ts @@ -17,7 +17,7 @@ export { listenEvent, destroyListener, EVENT_MAP } from "./utils"; export async function JobHandlerRegister(core: CoreSetup) { const commonService = new CommonService(core.http); - const accountResult = await commonService.apiCaller<{ + const accountResult = await commonService.accountInfo<{ user_name: string; }>({ endpoint: "transport.request", diff --git a/public/services/CommonService.ts b/public/services/CommonService.ts index a0247d355..b04770497 100644 --- a/public/services/CommonService.ts +++ b/public/services/CommonService.ts @@ -23,4 +23,18 @@ export default class CommonService extends MDSEnabledClientService { payload.query = queryObject; return (await this.httpClient.fetch(url, payload)) as ServerResponse; }; + + accountInfo = async (params: IAPICaller): Promise> => { + let url = `${NODE_API.ACCOUNT_INFO}`; + const payload: HttpFetchOptions = {}; + payload.method = "POST"; + payload.body = JSON.stringify({ + data: params.data, + endpoint: params.endpoint, + hideLog: params.hideLog, + }); + // we are not sending dataSourceId in query object, as for securityInfo, + // it will always contact local cluster + return (await this.httpClient.fetch(url, payload)) as ServerResponse; + }; } diff --git a/server/routes/common.ts b/server/routes/common.ts index c01c31be1..9e4348d60 100644 --- a/server/routes/common.ts +++ b/server/routes/common.ts @@ -17,20 +17,32 @@ export default function (services: NodeServices, router: IRouter, dataSourceEnab dataSourceId: schema.string(), }); } + let bodySchema = schema.nullable( + schema.object({ + endpoint: schema.string(), + data: schema.nullable(schema.any()), + hideLog: schema.nullable(schema.boolean()), + }) + ); const payload = { path: NODE_API.API_CALLER, validate: { - body: schema.nullable( - schema.object({ - endpoint: schema.string(), - data: schema.nullable(schema.any()), - hideLog: schema.nullable(schema.boolean()), - }) - ), + body: bodySchema, query: query, }, }; router.post(payload, commonService.apiCaller); + + // this api is called on the very first page load + router.post( + { + path: NODE_API.ACCOUNT_INFO, + validate: { + body: bodySchema, + }, + }, + commonService.apiCaller + ); } diff --git a/utils/constants.ts b/utils/constants.ts index 0dda4d67a..25a5a6728 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -27,6 +27,7 @@ export const NODE_API = Object.freeze({ _REPOSITORIES: `${BASE_API_PATH}/_repositores`, PUT_INDEX: `${BASE_API_PATH}/putIndex`, API_CALLER: `${BASE_API_PATH}/apiCaller`, + ACCOUNT_INFO: `${BASE_API_PATH}/accountInfo`, }); export const REQUEST = Object.freeze({