Skip to content

Commit

Permalink
Adding new api to fetch security info
Browse files Browse the repository at this point in the history
  • Loading branch information
RamakrishnaChilaka committed Apr 1, 2024
1 parent f171c65 commit f60f576
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion public/JobHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions public/services/CommonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,18 @@ export default class CommonService extends MDSEnabledClientService {
payload.query = queryObject;
return (await this.httpClient.fetch(url, payload)) as ServerResponse<T>;
};

accountInfo = async <T>(params: IAPICaller): Promise<ServerResponse<T>> => {
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<T>;
};
}
26 changes: 19 additions & 7 deletions server/routes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
1 change: 1 addition & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit f60f576

Please sign in to comment.