Merge pull request #6733 from kuangp/fix/elasticSearchEngine
fix(elasticSearchEngine): optionally read auth config
This commit is contained in:
+27
-22
@@ -75,30 +75,35 @@ export interface Config {
|
||||
* Authentication credentials for ElasticSearch
|
||||
* If both ApiKey/Bearer token and username+password is provided, tokens take precedence
|
||||
*/
|
||||
auth?: {
|
||||
username?: string;
|
||||
auth?:
|
||||
| {
|
||||
username: string;
|
||||
|
||||
/**
|
||||
* @visibility secret
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* @visibility secret
|
||||
*/
|
||||
password: string;
|
||||
}
|
||||
| {
|
||||
/**
|
||||
* Base64 Encoded API key to be used to connect to the cluster.
|
||||
* See: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html
|
||||
*
|
||||
* @visibility secret
|
||||
*/
|
||||
apiKey: string;
|
||||
};
|
||||
/* TODO(kuangp): unsupported until @elastic/elasticsearch@7.14 is released
|
||||
| {
|
||||
|
||||
/**
|
||||
* Base64 Encoded API key to be used to connect to the cluster.
|
||||
* See: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html
|
||||
*
|
||||
* @visibility secret
|
||||
*/
|
||||
apiKey?: string;
|
||||
|
||||
/**
|
||||
* Bearer authentication token to connect to the cluster.
|
||||
* See: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-service-token.html
|
||||
*
|
||||
* @visibility secret
|
||||
*/
|
||||
bearer?: string;
|
||||
};
|
||||
/**
|
||||
* Bearer authentication token to connect to the cluster.
|
||||
* See: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-service-token.html
|
||||
*
|
||||
* @visibility secret
|
||||
*
|
||||
bearer: string;
|
||||
};*/
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
+17
-9
@@ -35,13 +35,6 @@ export type ConcreteElasticSearchQuery = {
|
||||
elasticSearchQuery: Object;
|
||||
};
|
||||
|
||||
type ElasticConfigAuth = {
|
||||
username: string;
|
||||
password: string;
|
||||
apiKey: string;
|
||||
bearer: string;
|
||||
};
|
||||
|
||||
type ElasticSearchQueryTranslator = (
|
||||
query: SearchQuery,
|
||||
) => ConcreteElasticSearchQuery;
|
||||
@@ -105,11 +98,15 @@ export class ElasticSearchSearchEngine implements SearchEngine {
|
||||
|
||||
if (config.getOptionalString('provider') === 'elastic') {
|
||||
logger.info('Initializing Elastic.co ElasticSearch search engine.');
|
||||
const authConfig = config.getConfig('auth');
|
||||
return new Client({
|
||||
cloud: {
|
||||
id: config.getString('cloudId'),
|
||||
},
|
||||
auth: config.get<ElasticConfigAuth>('auth'),
|
||||
auth: {
|
||||
username: authConfig.getString('username'),
|
||||
password: authConfig.getString('password'),
|
||||
},
|
||||
});
|
||||
}
|
||||
if (config.getOptionalString('provider') === 'aws') {
|
||||
@@ -122,9 +119,20 @@ export class ElasticSearchSearchEngine implements SearchEngine {
|
||||
});
|
||||
}
|
||||
logger.info('Initializing ElasticSearch search engine.');
|
||||
const authConfig = config.getOptionalConfig('auth');
|
||||
const auth =
|
||||
authConfig &&
|
||||
(authConfig.has('apiKey')
|
||||
? {
|
||||
apiKey: authConfig.getString('apiKey'),
|
||||
}
|
||||
: {
|
||||
username: authConfig.getString('username'),
|
||||
password: authConfig.getString('password'),
|
||||
});
|
||||
return new Client({
|
||||
node: config.getString('node'),
|
||||
auth: config.get<ElasticConfigAuth>('auth'),
|
||||
auth,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user