Skip to content

Commit

Permalink
Merge credential object into data source
Browse files Browse the repository at this point in the history
  • Loading branch information
noCharger committed Sep 1, 2022
1 parent c553fe4 commit f3e8ba2
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/plugins/data_source/server/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import {
SavedObjectsClientContract,
SavedObjectsErrorHelpers,
} from '../../../../../src/core/server';
import { DATA_SOURCE_SAVED_OBJECT_TYPE, CREDENTIAL_SAVED_OBJECT_TYPE } from '../../common';
import {
CredentialSavedObjectAttributes,
UsernamePasswordTypedContent,
} from '../../common/credentials/types';
import { DataSourceAttributes } from '../../common/data_sources';
import { DATA_SOURCE_SAVED_OBJECT_TYPE } from '../../common';

import { DataSourceAttributes, UsernamePasswordTypedContent } from '../../common/data_sources';
import { DataSourcePluginConfigType } from '../../config';
import { CryptographyClient } from '../cryptography';
import { parseClientOptions } from './client_config';
Expand Down Expand Up @@ -52,19 +49,12 @@ export const getDataSource = async (
};

export const getCredential = async (
credentialId: string,
savedObjects: SavedObjectsClientContract,
dataSource: SavedObject<DataSourceAttributes>,
cryptographyClient: CryptographyClient
): Promise<UsernamePasswordTypedContent> => {
try {
const credentialSavedObject = await savedObjects.get<CredentialSavedObjectAttributes>(
CREDENTIAL_SAVED_OBJECT_TYPE,
credentialId
);
const {
username,
password,
} = credentialSavedObject.attributes.credentialMaterials.credentialMaterialsContent;

const { username, password } = dataSource.attributes.credentials!.credentialsContent;
const decodedPassword = await cryptographyClient.decodeAndDecrypt(password);
const credential = {
username,
Expand All @@ -89,17 +79,16 @@ export const getCredential = async (
const getQueryClient = async (
rootClient: Client,
dataSource: SavedObject<DataSourceAttributes>,
savedObjects: SavedObjectsClientContract,
cryptographyClient: CryptographyClient
): Promise<Client> => {
if (dataSource.attributes.noAuth) {
return rootClient.child();
} else {
const credential = await getCredential(
dataSource.references[0].id,
savedObjects,
dataSource,
cryptographyClient
);

return getBasicAuthClient(rootClient, credential);
}
};
Expand Down

0 comments on commit f3e8ba2

Please sign in to comment.