Skip to content

Commit

Permalink
ensure all code in actions uses the constant api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Mar 17, 2020
1 parent ae7787b commit 4ad4cce
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { kfetch } from 'ui/kfetch';
import { omit, pick } from 'lodash';
import { i18n } from '@kbn/i18n';
import { ActionResult } from '../../../../../../../plugins/actions/common';
import { ActionResult, BASE_ACTION_API_PATH } from '../../../../../../../plugins/actions/common';
import { ManageEmailAction, EmailActionData } from '../manage_email_action';
import { ALERT_ACTION_TYPE_EMAIL } from '../../../../common/constants';
import { NEW_ACTION_ID } from './configuration';
Expand All @@ -44,7 +44,7 @@ export const Step1: React.FC<GetStep1Props> = (props: GetStep1Props) => {
if (props.editAction) {
await kfetch({
method: 'PUT',
pathname: `/api/action/${props.editAction.id}`,
pathname: `${BASE_ACTION_API_PATH}/${props.editAction.id}`,
body: JSON.stringify({
name: props.editAction.name,
config: omit(data, ['user', 'password']),
Expand All @@ -55,7 +55,7 @@ export const Step1: React.FC<GetStep1Props> = (props: GetStep1Props) => {
} else {
await kfetch({
method: 'POST',
pathname: '/api/action',
pathname: BASE_ACTION_API_PATH,
body: JSON.stringify({
name: i18n.translate('xpack.monitoring.alerts.configuration.emailAction.name', {
defaultMessage: 'Email action for Stack Monitoring alerts',
Expand All @@ -75,7 +75,7 @@ export const Step1: React.FC<GetStep1Props> = (props: GetStep1Props) => {

await kfetch({
method: 'DELETE',
pathname: `/api/action/${id}`,
pathname: `${BASE_ACTION_API_PATH}/${id}`,
});

if (props.editAction && props.editAction.id === id) {
Expand All @@ -101,7 +101,7 @@ export const Step1: React.FC<GetStep1Props> = (props: GetStep1Props) => {

const result = await kfetch({
method: 'POST',
pathname: `/api/action/${props.selectedEmailActionId}/_execute`,
pathname: `${BASE_ACTION_API_PATH}/${props.selectedEmailActionId}/_execute`,
body: JSON.stringify({ params }),
});
if (result.status === 'ok') {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { ActionResult } from '../types';
import { LicenseState } from '../lib/license_state';
import { verifyApiAccess } from '../lib/license_api_access';
import { BASE_ACTION_API_PATH } from '../../common';

export const bodySchema = schema.object({
name: schema.string(),
Expand All @@ -26,7 +27,7 @@ export const bodySchema = schema.object({
export const createActionRoute = (router: IRouter, licenseState: LicenseState) => {
router.post(
{
path: `/api/action`,
path: BASE_ACTION_API_PATH,
validate: {
body: bodySchema,
},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/routes/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from 'kibana/server';
import { LicenseState } from '../lib/license_state';
import { verifyApiAccess } from '../lib/license_api_access';
import { BASE_ACTION_API_PATH } from '../../common';

const paramSchema = schema.object({
id: schema.string(),
Expand All @@ -27,7 +28,7 @@ const paramSchema = schema.object({
export const deleteActionRoute = (router: IRouter, licenseState: LicenseState) => {
router.delete(
{
path: `/api/action/{id}`,
path: `${BASE_ACTION_API_PATH}/{id}`,
validate: {
params: paramSchema,
},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/routes/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { verifyApiAccess } from '../lib/license_api_access';

import { ActionExecutorContract } from '../lib';
import { ActionTypeExecutorResult } from '../types';
import { BASE_ACTION_API_PATH } from '../../common';

const paramSchema = schema.object({
id: schema.string(),
Expand All @@ -32,7 +33,7 @@ export const executeActionRoute = (
) => {
router.post(
{
path: '/api/action/{id}/_execute',
path: `${BASE_ACTION_API_PATH}/{id}/_execute`,
validate: {
body: bodySchema,
params: paramSchema,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { FindOptions } from '../../../alerting/server';
import { LicenseState } from '../lib/license_state';
import { verifyApiAccess } from '../lib/license_api_access';
import { BASE_ACTION_API_PATH } from '../../common';

// config definition
const querySchema = schema.object({
Expand Down Expand Up @@ -43,7 +44,7 @@ const querySchema = schema.object({
export const findActionRoute = (router: IRouter, licenseState: LicenseState) => {
router.get(
{
path: `/api/action/_find`,
path: `${BASE_ACTION_API_PATH}/_find`,
validate: {
query: querySchema,
},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/routes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from 'kibana/server';
import { LicenseState } from '../lib/license_state';
import { verifyApiAccess } from '../lib/license_api_access';
import { BASE_ACTION_API_PATH } from '../../common';

const paramSchema = schema.object({
id: schema.string(),
Expand All @@ -22,7 +23,7 @@ const paramSchema = schema.object({
export const getActionRoute = (router: IRouter, licenseState: LicenseState) => {
router.get(
{
path: `/api/action/{id}`,
path: `${BASE_ACTION_API_PATH}/{id}`,
validate: {
params: paramSchema,
},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/routes/list_action_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import {
} from 'kibana/server';
import { LicenseState } from '../lib/license_state';
import { verifyApiAccess } from '../lib/license_api_access';
import { BASE_ACTION_API_PATH } from '../../common';

export const listActionTypesRoute = (router: IRouter, licenseState: LicenseState) => {
router.get(
{
path: `/api/action/types`,
path: `${BASE_ACTION_API_PATH}/types`,
validate: {},
options: {
tags: ['access:actions-read'],
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/routes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from 'kibana/server';
import { LicenseState } from '../lib/license_state';
import { verifyApiAccess } from '../lib/license_api_access';
import { BASE_ACTION_API_PATH } from '../../common';

const paramSchema = schema.object({
id: schema.string(),
Expand All @@ -28,7 +29,7 @@ const bodySchema = schema.object({
export const updateActionRoute = (router: IRouter, licenseState: LicenseState) => {
router.put(
{
path: `/api/action/{id}`,
path: `${BASE_ACTION_API_PATH}/{id}`,
validate: {
body: bodySchema,
params: paramSchema,
Expand Down

0 comments on commit 4ad4cce

Please sign in to comment.