From efb7c2789716ab30827e4ecbe03214b98fc7e523 Mon Sep 17 00:00:00 2001 From: Kristen Tian <105667444+kristenTian@users.noreply.github.com> Date: Thu, 15 Sep 2022 11:05:33 -0700 Subject: [PATCH] Fix update data source & block update endpint (#2364) Signed-off-by: Kristen Tian Signed-off-by: Kristen Tian --- .../data_source_saved_objects_client_wrapper.ts | 15 +++++++++------ .../edit_form/edit_data_source_form.tsx | 2 +- .../data_source_management/public/types.ts | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.ts b/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.ts index ee7aba23b824..29ffc8f4123e 100644 --- a/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.ts +++ b/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.ts @@ -160,16 +160,19 @@ export class DataSourceSavedObjectsClientWrapper { } private async validateAndUpdatePartialAttributes(attributes: T) { - const { auth } = attributes; + const { auth, endpoint } = attributes; + + if (endpoint) { + throw SavedObjectsErrorHelpers.createBadRequestError( + `Update data source endpoint is not supported` + ); + } if (auth === undefined) { return attributes; } - const { - type, - credentials: { password }, - } = auth; + const { type, credentials } = auth; switch (type) { case AuthType.NoAuth: @@ -179,7 +182,7 @@ export class DataSourceSavedObjectsClientWrapper { credentials: undefined, }; case AuthType.UsernamePasswordType: - if (password) { + if (credentials && credentials.password) { return { ...attributes, auth: await this.encryptCredentials(auth), diff --git a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx index cd402573587d..bf59853d5427 100644 --- a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx @@ -206,10 +206,10 @@ export class EditDataSourceForm extends React.Component { if (this.isFormValid()) { + // update data source endpoint is currently not supported/allowed const formValues: DataSourceAttributes = { title: this.state.title, description: this.state.description, - endpoint: this.props.existingDataSource.endpoint, auth: this.state.auth, }; /* Remove credentials object for NoAuth */ diff --git a/src/plugins/data_source_management/public/types.ts b/src/plugins/data_source_management/public/types.ts index 7ba6fb444acc..c0aa502b5830 100644 --- a/src/plugins/data_source_management/public/types.ts +++ b/src/plugins/data_source_management/public/types.ts @@ -70,7 +70,7 @@ export const credentialSourceOptions = [ export interface DataSourceAttributes extends SavedObjectAttributes { title: string; description?: string; - endpoint: string; + endpoint?: string; auth: { type: AuthType; credentials: UsernamePasswordTypedContent | undefined;