mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
chore(server): support elasticsearch apiKey (#12405)
This commit is contained in:
@@ -825,6 +825,11 @@
|
|||||||
"description": "Indexer search service endpoint\n@default \"http://localhost:9308\"\n@environment `AFFINE_INDEXER_SEARCH_ENDPOINT`",
|
"description": "Indexer search service endpoint\n@default \"http://localhost:9308\"\n@environment `AFFINE_INDEXER_SEARCH_ENDPOINT`",
|
||||||
"default": "http://localhost:9308"
|
"default": "http://localhost:9308"
|
||||||
},
|
},
|
||||||
|
"provider.apiKey": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Indexer search service api key. Optional for elasticsearch\n@default \"\"\n@environment `AFFINE_INDEXER_SEARCH_API_KEY`\n@link https://www.elastic.co/guide/server/current/api-key.html",
|
||||||
|
"default": ""
|
||||||
|
},
|
||||||
"provider.username": {
|
"provider.username": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Indexer search service auth username, if not set, basic auth will be disabled. Optional for elasticsearch\n@default \"\"\n@environment `AFFINE_INDEXER_SEARCH_USERNAME`\n@link https://www.elastic.co/guide/en/elasticsearch/reference/current/http-clients.html",
|
"description": "Indexer search service auth username, if not set, basic auth will be disabled. Optional for elasticsearch\n@default \"\"\n@environment `AFFINE_INDEXER_SEARCH_USERNAME`\n@link https://www.elastic.co/guide/en/elasticsearch/reference/current/http-clients.html",
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ const {
|
|||||||
STATIC_IP_NAME,
|
STATIC_IP_NAME,
|
||||||
AFFINE_INDEXER_SEARCH_PROVIDER,
|
AFFINE_INDEXER_SEARCH_PROVIDER,
|
||||||
AFFINE_INDEXER_SEARCH_ENDPOINT,
|
AFFINE_INDEXER_SEARCH_ENDPOINT,
|
||||||
AFFINE_INDEXER_SEARCH_USERNAME,
|
AFFINE_INDEXER_SEARCH_API_KEY,
|
||||||
AFFINE_INDEXER_SEARCH_PASSWORD,
|
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const buildType = BUILD_TYPE || 'canary';
|
const buildType = BUILD_TYPE || 'canary';
|
||||||
@@ -88,8 +87,7 @@ const createHelmCommand = ({ isDryRun }) => {
|
|||||||
const indexerOptions = [
|
const indexerOptions = [
|
||||||
`--set-string global.indexer.provider="${AFFINE_INDEXER_SEARCH_PROVIDER}"`,
|
`--set-string global.indexer.provider="${AFFINE_INDEXER_SEARCH_PROVIDER}"`,
|
||||||
`--set-string global.indexer.endpoint="${AFFINE_INDEXER_SEARCH_ENDPOINT}"`,
|
`--set-string global.indexer.endpoint="${AFFINE_INDEXER_SEARCH_ENDPOINT}"`,
|
||||||
`--set-string global.indexer.username="${AFFINE_INDEXER_SEARCH_USERNAME}"`,
|
`--set-string global.indexer.apiKey="${AFFINE_INDEXER_SEARCH_API_KEY}"`,
|
||||||
`--set-string global.indexer.password="${AFFINE_INDEXER_SEARCH_PASSWORD}"`,
|
|
||||||
];
|
];
|
||||||
const serviceAnnotations = [
|
const serviceAnnotations = [
|
||||||
`--set-json web.serviceAccount.annotations="{ \\"iam.gke.io/gcp-service-account\\": \\"${APP_IAM_ACCOUNT}\\" }"`,
|
`--set-json web.serviceAccount.annotations="{ \\"iam.gke.io/gcp-service-account\\": \\"${APP_IAM_ACCOUNT}\\" }"`,
|
||||||
|
|||||||
@@ -73,13 +73,11 @@ spec:
|
|||||||
value: "{{ .Values.global.indexer.provider }}"
|
value: "{{ .Values.global.indexer.provider }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
value: "{{ .Values.global.indexer.endpoint }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_USERNAME
|
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
||||||
value: "{{ .Values.global.indexer.username }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_PASSWORD
|
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: indexer
|
name: indexer
|
||||||
key: indexer-password
|
key: indexer-apiKey
|
||||||
- name: AFFINE_SERVER_PORT
|
- name: AFFINE_SERVER_PORT
|
||||||
value: "{{ .Values.global.docService.port }}"
|
value: "{{ .Values.global.docService.port }}"
|
||||||
- name: AFFINE_SERVER_SUB_PATH
|
- name: AFFINE_SERVER_SUB_PATH
|
||||||
|
|||||||
@@ -71,13 +71,11 @@ spec:
|
|||||||
value: "{{ .Values.global.indexer.provider }}"
|
value: "{{ .Values.global.indexer.provider }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
value: "{{ .Values.global.indexer.endpoint }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_USERNAME
|
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
||||||
value: "{{ .Values.global.indexer.username }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_PASSWORD
|
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: indexer
|
name: indexer
|
||||||
key: indexer-password
|
key: indexer-apiKey
|
||||||
- name: AFFINE_SERVER_PORT
|
- name: AFFINE_SERVER_PORT
|
||||||
value: "{{ .Values.service.port }}"
|
value: "{{ .Values.service.port }}"
|
||||||
- name: AFFINE_SERVER_SUB_PATH
|
- name: AFFINE_SERVER_SUB_PATH
|
||||||
|
|||||||
@@ -48,13 +48,11 @@ spec:
|
|||||||
value: "{{ .Values.global.indexer.provider }}"
|
value: "{{ .Values.global.indexer.provider }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
value: "{{ .Values.global.indexer.endpoint }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_USERNAME
|
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
||||||
value: "{{ .Values.global.indexer.username }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_PASSWORD
|
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: indexer
|
name: indexer
|
||||||
key: indexer-password
|
key: indexer-apiKey
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
cpu: '100m'
|
cpu: '100m'
|
||||||
|
|||||||
@@ -73,13 +73,11 @@ spec:
|
|||||||
value: "{{ .Values.global.indexer.provider }}"
|
value: "{{ .Values.global.indexer.provider }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
value: "{{ .Values.global.indexer.endpoint }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_USERNAME
|
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
||||||
value: "{{ .Values.global.indexer.username }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_PASSWORD
|
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: indexer
|
name: indexer
|
||||||
key: indexer-password
|
key: indexer-apiKey
|
||||||
- name: AFFINE_SERVER_PORT
|
- name: AFFINE_SERVER_PORT
|
||||||
value: "{{ .Values.service.port }}"
|
value: "{{ .Values.service.port }}"
|
||||||
- name: AFFINE_SERVER_SUB_PATH
|
- name: AFFINE_SERVER_SUB_PATH
|
||||||
|
|||||||
@@ -73,13 +73,11 @@ spec:
|
|||||||
value: "{{ .Values.global.indexer.provider }}"
|
value: "{{ .Values.global.indexer.provider }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
value: "{{ .Values.global.indexer.endpoint }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_USERNAME
|
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
||||||
value: "{{ .Values.global.indexer.username }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_PASSWORD
|
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: indexer
|
name: indexer
|
||||||
key: indexer-password
|
key: indexer-apiKey
|
||||||
- name: AFFINE_SERVER_PORT
|
- name: AFFINE_SERVER_PORT
|
||||||
value: "{{ .Values.service.port }}"
|
value: "{{ .Values.service.port }}"
|
||||||
- name: AFFINE_SERVER_HOST
|
- name: AFFINE_SERVER_HOST
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{{- if .Values.global.indexer.password -}}
|
{{- if .Values.global.indexer.apiKey -}}
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Secret
|
kind: Secret
|
||||||
metadata:
|
metadata:
|
||||||
@@ -9,5 +9,5 @@ metadata:
|
|||||||
"helm.sh/hook-delete-policy": before-hook-creation
|
"helm.sh/hook-delete-policy": before-hook-creation
|
||||||
type: Opaque
|
type: Opaque
|
||||||
data:
|
data:
|
||||||
indexer-password: {{ .Values.global.indexer.password | b64enc }}
|
indexer-apiKey: {{ .Values.global.indexer.apiKey | b64enc }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|||||||
@@ -105,8 +105,7 @@ jobs:
|
|||||||
STATIC_IP_NAME: ${{ secrets.STATIC_IP_NAME }}
|
STATIC_IP_NAME: ${{ secrets.STATIC_IP_NAME }}
|
||||||
AFFINE_INDEXER_SEARCH_PROVIDER: ${{ secrets.AFFINE_INDEXER_SEARCH_PROVIDER }}
|
AFFINE_INDEXER_SEARCH_PROVIDER: ${{ secrets.AFFINE_INDEXER_SEARCH_PROVIDER }}
|
||||||
AFFINE_INDEXER_SEARCH_ENDPOINT: ${{ secrets.AFFINE_INDEXER_SEARCH_ENDPOINT }}
|
AFFINE_INDEXER_SEARCH_ENDPOINT: ${{ secrets.AFFINE_INDEXER_SEARCH_ENDPOINT }}
|
||||||
AFFINE_INDEXER_SEARCH_USERNAME: ${{ secrets.AFFINE_INDEXER_SEARCH_USERNAME }}
|
AFFINE_INDEXER_SEARCH_API_KEY: ${{ secrets.AFFINE_INDEXER_SEARCH_API_KEY }}
|
||||||
AFFINE_INDEXER_SEARCH_PASSWORD: ${{ secrets.AFFINE_INDEXER_SEARCH_PASSWORD }}
|
|
||||||
|
|
||||||
deploy-done:
|
deploy-done:
|
||||||
needs:
|
needs:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ declare global {
|
|||||||
provider: {
|
provider: {
|
||||||
type: SearchProviderType;
|
type: SearchProviderType;
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
|
apiKey: string;
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
@@ -50,6 +51,12 @@ defineModuleConfig('indexer', {
|
|||||||
return z.string().url().safeParse(val);
|
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': {
|
'provider.username': {
|
||||||
desc: 'Indexer search service auth username, if not set, basic auth will be disabled. Optional for elasticsearch',
|
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',
|
link: 'https://www.elastic.co/guide/en/elasticsearch/reference/current/http-clients.html',
|
||||||
|
|||||||
@@ -248,7 +248,9 @@ export class ElasticsearchProvider extends SearchProvider {
|
|||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': contentType,
|
'Content-Type': contentType,
|
||||||
} as Record<string, string>;
|
} 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')}`;
|
headers.Authorization = `Basic ${Buffer.from(`${this.config.provider.username}:${this.config.provider.password}`).toString('base64')}`;
|
||||||
}
|
}
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
|
|||||||
@@ -279,6 +279,12 @@
|
|||||||
"desc": "Indexer search service endpoint",
|
"desc": "Indexer search service endpoint",
|
||||||
"env": "AFFINE_INDEXER_SEARCH_ENDPOINT"
|
"env": "AFFINE_INDEXER_SEARCH_ENDPOINT"
|
||||||
},
|
},
|
||||||
|
"provider.apiKey": {
|
||||||
|
"type": "String",
|
||||||
|
"desc": "Indexer search service api key. Optional for elasticsearch",
|
||||||
|
"link": "https://www.elastic.co/guide/server/current/api-key.html",
|
||||||
|
"env": "AFFINE_INDEXER_SEARCH_API_KEY"
|
||||||
|
},
|
||||||
"provider.username": {
|
"provider.username": {
|
||||||
"type": "String",
|
"type": "String",
|
||||||
"desc": "Indexer search service auth username, if not set, basic auth will be disabled. Optional for elasticsearch",
|
"desc": "Indexer search service auth username, if not set, basic auth will be disabled. Optional for elasticsearch",
|
||||||
|
|||||||
Reference in New Issue
Block a user