feat: es auth (#156)

This commit is contained in:
Montassar Ghanmy
2023-07-12 14:59:14 +01:00
committed by GitHub
parent 7538322720
commit a11e7bc315
3 changed files with 19 additions and 3 deletions
@@ -58,7 +58,11 @@
"type": "SEARCH_DRIVER",
"elasticsearch": {
"endpoint": "SEARCH_ES_ENDPOINT",
"flushInterval": "SEARCH_ES_FLUSHINTERVAL"
"flushInterval": "SEARCH_ES_FLUSHINTERVAL",
"useAuth": "SEARCH_ES_USE_AUTH",
"username": "SEARCH_ES_USERNAME",
"password": "SEARCH_ES_PASSWORD"
}
},
"storage": {
@@ -40,12 +40,21 @@ export default class ElasticSearch extends SearchAdapter implements SearchAdapte
public async connect() {
try {
this.client = new Client({
const clientOptions: any = {
node: this.configuration.endpoint,
ssl: {
rejectUnauthorized: false,
},
});
};
if (this.configuration.useAuth) {
clientOptions.auth = {
username: this.configuration.username,
password: this.configuration.password,
};
}
this.client = new Client(clientOptions);
} catch (e) {
logger.error(`Unable to connect to ElasticSearch at ${this.configuration.endpoint}`);
}
@@ -67,6 +67,9 @@ export interface SearchServiceAPI extends TdriveServiceProvider {
export type SearchConfiguration = {
type?: false | "elasticsearch" | "mongodb";
elasticsearch?: {
useAuth: boolean;
username?: string;
password?: string;
endpoint: string;
flushInterval: number; //In milliseconds
};