diff --git a/tdrive/backend/node/config/custom-environment-variables.json b/tdrive/backend/node/config/custom-environment-variables.json index 81339917..7e4f7abe 100644 --- a/tdrive/backend/node/config/custom-environment-variables.json +++ b/tdrive/backend/node/config/custom-environment-variables.json @@ -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": { diff --git a/tdrive/backend/node/src/core/platform/services/search/adapters/elasticsearch/index.ts b/tdrive/backend/node/src/core/platform/services/search/adapters/elasticsearch/index.ts index 01835399..5f594ca4 100644 --- a/tdrive/backend/node/src/core/platform/services/search/adapters/elasticsearch/index.ts +++ b/tdrive/backend/node/src/core/platform/services/search/adapters/elasticsearch/index.ts @@ -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}`); } diff --git a/tdrive/backend/node/src/core/platform/services/search/api.ts b/tdrive/backend/node/src/core/platform/services/search/api.ts index 12ef3cdd..164a3e3c 100644 --- a/tdrive/backend/node/src/core/platform/services/search/api.ts +++ b/tdrive/backend/node/src/core/platform/services/search/api.ts @@ -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 };