Skip to content

Commit

Permalink
Fix update data source & block update endpint
Browse files Browse the repository at this point in the history
Signed-off-by: Kristen Tian <[email protected]>
  • Loading branch information
kristenTian committed Sep 15, 2022
1 parent 48ea2fe commit 94e38f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,19 @@ export class DataSourceSavedObjectsClientWrapper {
}

private async validateAndUpdatePartialAttributes<T = unknown>(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:
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi

onClickUpdateDataSource = () => {
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 */
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data_source_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 94e38f2

Please sign in to comment.