Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Disable api calls that uses Kibana default internal user #212

Merged
merged 2 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kibana-reports/public/components/main/main_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const generateReportById = async (
handlePermissionsMissingToast
) => {
await httpClient
.post(`../api/reporting/generateReport/${reportId}`)
.get(`../api/reporting/generateReport/${reportId}`)
.then(async (response) => {
//TODO: duplicate code, extract to be a function that can reuse. e.g. handleResponse(response)
const fileFormat = extractFileFormat(response['filename']);
Expand Down
14 changes: 14 additions & 0 deletions kibana-reports/server/backend/opendistro-es-reports-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export default function (Client: any, config: any, components: any) {
needBody: true,
});

esReports.createReportFromDefinition = clientAction({
url: {
fmt: `${ES_REPORTS_API.ON_DEMAND_REPORT}/<%=reportDefinitionId%>`,
req: {
reportDefinitionId: {
type: 'string',
required: true,
},
},
},
method: 'POST',
needBody: true,
});

esReports.updateReportInstanceStatus = clientAction({
url: {
fmt: `${ES_REPORTS_API.REPORT_INSTANCE}/<%=reportInstanceId%>`,
Expand Down
18 changes: 9 additions & 9 deletions kibana-reports/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ export class OpendistroKibanaReportsPlugin
Polling at at a 5 min fixed interval

TODO: need further optimization polling with a mix approach of
random delay and dynamic delay based on the amount of jobs
random delay and dynamic delay based on the amount of jobs.
*/
setIntervalAsync(
pollAndExecuteJob,
POLL_INTERVAL,
esReportsClient,
notificationClient,
esClient,
this.logger
);
// setIntervalAsync(
// pollAndExecuteJob,
// POLL_INTERVAL,
// esReportsClient,
// notificationClient,
// esClient,
// this.logger
// );
return {};
}

Expand Down
16 changes: 9 additions & 7 deletions kibana-reports/server/routes/lib/createReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ export const createReport = async (
);
}
// update report state to "created"
if (!savedReportId) {
await updateReportState(reportId, esReportsClient, REPORT_STATE.created);
}
// TODO: temporarily remove the following
// if (!savedReportId) {
// await updateReportState(reportId, esReportsClient, REPORT_STATE.created);
// }

// deliver report
if (!savedReportId && deliveryType == DELIVERY_TYPE.channel) {
Expand All @@ -125,10 +126,11 @@ export const createReport = async (
}
} catch (error) {
// update report instance with "error" state
//TODO: save error detail and display on UI
if (!savedReportId) {
await updateReportState(reportId, esReportsClient, REPORT_STATE.error);
}
// TODO: save error detail and display on UI
// TODO: temporarily disable the following, will add back
// if (!savedReportId) {
// await updateReportState(reportId, esReportsClient, REPORT_STATE.error);
// }
throw error;
}

Expand Down
3 changes: 2 additions & 1 deletion kibana-reports/server/routes/lib/deliverReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ export const deliverReport = async (
}

// update report state
await updateReportState(reportId, esReportsClient, REPORT_STATE.shared);
// TODO: temporarily disable the following, will add back
// await updateReportState(reportId, esReportsClient, REPORT_STATE.shared);
};
4 changes: 3 additions & 1 deletion kibana-reports/server/routes/lib/saveReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const saveReport = async (
},
},
},
status: BACKEND_REPORT_STATE.executing, // download from in-context menu should always pass executing state to backend
// download from in-context menu should always pass executing state to backend
// TODO: set to success, since update report status API in temporarily unavailable, need change back to pending later
status: BACKEND_REPORT_STATE.success,
inContextDownloadUrlPath: queryUrl,
};

Expand Down
66 changes: 63 additions & 3 deletions kibana-reports/server/routes/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from './utils/converters/backendToUi';

export default function (router: IRouter) {
// generate report
// generate report (with provided metadata)
router.post(
{
path: `${API_PREFIX}/generateReport`,
Expand Down Expand Up @@ -85,8 +85,8 @@ export default function (router: IRouter) {
}
);

// generate report from id
router.post(
// generate report from report id
router.get(
{
path: `${API_PREFIX}/generateReport/{reportId}`,
validate: {
Expand Down Expand Up @@ -140,6 +140,66 @@ export default function (router: IRouter) {
}
);

// create report from existing report definition
router.post(
{
path: `${API_PREFIX}/generateReport/{reportDefinitionId}`,
validate: {
params: schema.object({
reportDefinitionId: schema.string(),
}),
},
},
async (
context,
request,
response
): Promise<IKibanaResponse<any | ResponseError>> => {
//@ts-ignore
const logger: Logger = context.reporting_plugin.logger;
const reportDefinitionId = request.params.reportDefinitionId;
try {
// @ts-ignore
const esReportsClient: ILegacyScopedClusterClient = context.reporting_plugin.esReportsClient.asScoped(
request
);
// call ES API to create report from definition
const esResp = await esReportsClient.callAsCurrentUser(
'es_reports.createReportFromDefinition',
{
reportDefinitionId: reportDefinitionId,
body: {
reportDefinitionId: reportDefinitionId,
},
}
);
const reportId = esResp.reportInstance.id;
// convert report to use UI model
const report = backendToUiReport(esResp.reportInstance);
// generate report
const reportData = await createReport(
request,
context,
report,
reportId
);

return response.ok({
body: {
data: reportData.dataUrl,
filename: reportData.fileName,
},
});
} catch (error) {
logger.error(
`Failed to generate report from reportDefinition id ${reportDefinitionId} : ${error}`
);
logger.error(error);
return errorResponse(response, error);
}
}
);

// get all reports details
router.get(
{
Expand Down