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

Commit

Permalink
APIs endpoints for data reports. (#50)
Browse files Browse the repository at this point in the history
Adding API endpoints for data reports
  • Loading branch information
fabioued authored Aug 21, 2020
1 parent 0603e98 commit 9c9df14
Show file tree
Hide file tree
Showing 9 changed files with 1,383 additions and 83 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"eslint-plugin-react": "^7.12.4",
"jest": "^26.0.1",
"prettier": "2.0.5",
"react-test-renderer": "^16.13.1"
"react-test-renderer": "^16.13.1",
"elastic-builder": "^2.7.1",
"json-2-csv": "^3.7.6"
}
}
160 changes: 80 additions & 80 deletions server/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,104 +15,104 @@

import { schema } from '@kbn/config-schema';

// TODO: needs update when we integrate csv feature
const dataReportSchema = schema.object({
saved_search_id: schema.string(),
time_range: schema.string(),
report_format: schema.oneOf([schema.literal('csv'), schema.literal('xlsx')]),
export const dataReportSchema = schema.object({
saved_search_id: schema.string(),
start: schema.string(),
end: schema.string(),
report_format: schema.oneOf([schema.literal('csv'), schema.literal('xlsx')]),
});

const visualReportSchema = schema.object({
url: schema.uri(),
window_width: schema.number({ defaultValue: 1200 }),
window_height: schema.number({ defaultValue: 800 }),
report_format: schema.oneOf([schema.literal('pdf'), schema.literal('png')]),
url: schema.uri(),
window_width: schema.number({ defaultValue: 1200 }),
window_height: schema.number({ defaultValue: 800 }),
report_format: schema.oneOf([schema.literal('pdf'), schema.literal('png')]),
});

export const scheduleSchema = schema.object({
schedule_type: schema.oneOf([
schema.literal('Now'),
schema.literal('Future Date'),
schema.literal('Recurring'),
schema.literal('Cron Based'),
]),
schedule: schema.any(),
schedule_type: schema.oneOf([
schema.literal('Now'),
schema.literal('Future Date'),
schema.literal('Recurring'),
schema.literal('Cron Based'),
]),
schedule: schema.any(),
});

export const intervalSchema = schema.object({
interval: schema.object({
period: schema.number(),
// Refer to job scheduler SPI https://github.com/opendistro-for-elasticsearch/job-scheduler/blob/b333469c183a15ddbf496a690300cc9e34d937fb/spi/src/main/java/com/amazon/opendistroforelasticsearch/jobscheduler/spi/schedule/IntervalSchedule.java
unit: schema.oneOf([
schema.literal('MINUTES'),
schema.literal('HOURS'),
schema.literal('DAYS'),
]),
// timeStamp
start_time: schema.number(),
}),
interval: schema.object({
period: schema.number(),
// Refer to job scheduler SPI https://github.com/opendistro-for-elasticsearch/job-scheduler/blob/b333469c183a15ddbf496a690300cc9e34d937fb/spi/src/main/java/com/amazon/opendistroforelasticsearch/jobscheduler/spi/schedule/IntervalSchedule.java
unit: schema.oneOf([
schema.literal('MINUTES'),
schema.literal('HOURS'),
schema.literal('DAYS'),
]),
// timeStamp
start_time: schema.number(),
}),
});

export const cronSchema = schema.object({
corn: schema.object({
expression: schema.string(),
time_zone: schema.string(),
}),
corn: schema.object({
expression: schema.string(),
time_zone: schema.string(),
}),
});

export const emailSchema = schema.object({
subject: schema.string(),
body: schema.string(),
has_attachment: schema.boolean({ defaultValue: true }),
recipients: schema.arrayOf(schema.string(), { minSize: 1 }),
subject: schema.string(),
body: schema.string(),
has_attachment: schema.boolean({ defaultValue: true }),
recipients: schema.arrayOf(schema.string(), { minSize: 1 }),
});

export const reportSchema = schema.object({
report_name: schema.string(),
report_source: schema.oneOf([
schema.literal('Dashboard'),
schema.literal('Visualization'),
schema.literal('Saved search'),
]),
report_type: schema.oneOf([
schema.literal('Download'),
schema.literal('Alert'),
schema.literal('Schedule'),
]),
description: schema.string(),
report_params: schema.conditional(
schema.siblingRef('report_source'),
'Saved search',
dataReportSchema,
visualReportSchema
),
report_name: schema.string(),
report_source: schema.oneOf([
schema.literal('Dashboard'),
schema.literal('Visualization'),
schema.literal('Saved search'),
]),
report_type: schema.oneOf([
schema.literal('Download'),
schema.literal('Alert'),
schema.literal('Schedule'),
]),
description: schema.string(),
report_params: schema.conditional(
schema.siblingRef('report_source'),
'Saved search',
dataReportSchema,
visualReportSchema
),

delivery: schema.maybe(
schema.object({
channel: schema.oneOf([
schema.literal('Email'),
schema.literal('Slack'),
schema.literal('Chime'),
schema.literal('Kibana User'),
]),
//TODO: no validation on delivery settings for now, because @kbn/config-schema has no support for more than 2 conditions
delivery_params: schema.any(),
})
),
delivery: schema.maybe(
schema.object({
channel: schema.oneOf([
schema.literal('Email'),
schema.literal('Slack'),
schema.literal('Chime'),
schema.literal('Kibana User'),
]),
//TODO: no validation on delivery settings for now, because @kbn/config-schema has no support for more than 2 conditions
delivery_params: schema.any(),
})
),

trigger: schema.maybe(
schema.object({
trigger_type: schema.oneOf([
schema.literal('Alert'),
schema.literal('Schedule'),
]),
trigger_params: schema.conditional(
schema.siblingRef('trigger_type'),
'Alert',
// TODO: add alerting schema here once we finished the design for alerting integration
schema.any(),
scheduleSchema
),
})
),
trigger: schema.maybe(
schema.object({
trigger_type: schema.oneOf([
schema.literal('Alert'),
schema.literal('Schedule'),
]),
trigger_params: schema.conditional(
schema.siblingRef('trigger_type'),
'Alert',
// TODO: add alerting schema here once we finished the design for alerting integration
schema.any(),
scheduleSchema
),
})
),
});
Loading

0 comments on commit 9c9df14

Please sign in to comment.