mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
chore(server): support elasticsearch apiKey (#12405)
This commit is contained in:
@@ -16,6 +16,7 @@ declare global {
|
||||
provider: {
|
||||
type: SearchProviderType;
|
||||
endpoint: string;
|
||||
apiKey: string;
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
@@ -50,6 +51,12 @@ defineModuleConfig('indexer', {
|
||||
return z.string().url().safeParse(val);
|
||||
},
|
||||
},
|
||||
'provider.apiKey': {
|
||||
desc: 'Indexer search service api key. Optional for elasticsearch',
|
||||
link: 'https://www.elastic.co/guide/server/current/api-key.html',
|
||||
default: '',
|
||||
env: ['AFFINE_INDEXER_SEARCH_API_KEY', 'string'],
|
||||
},
|
||||
'provider.username': {
|
||||
desc: 'Indexer search service auth username, if not set, basic auth will be disabled. Optional for elasticsearch',
|
||||
link: 'https://www.elastic.co/guide/en/elasticsearch/reference/current/http-clients.html',
|
||||
|
||||
@@ -248,7 +248,9 @@ export class ElasticsearchProvider extends SearchProvider {
|
||||
const headers = {
|
||||
'Content-Type': contentType,
|
||||
} as Record<string, string>;
|
||||
if (this.config.provider.password) {
|
||||
if (this.config.provider.apiKey) {
|
||||
headers.Authorization = `ApiKey ${this.config.provider.apiKey}`;
|
||||
} else if (this.config.provider.password) {
|
||||
headers.Authorization = `Basic ${Buffer.from(`${this.config.provider.username}:${this.config.provider.password}`).toString('base64')}`;
|
||||
}
|
||||
const response = await fetch(url, {
|
||||
|
||||
Reference in New Issue
Block a user