From b74971e29da5cf1d0277c4b22bcf5ee71fc64833 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Wed, 15 Nov 2023 14:05:05 +0700 Subject: [PATCH] UBERF-4289: Allow to configure user agent (#3995) Signed-off-by: Andrey Sobolev --- pods/account/src/index.ts | 1 + pods/backup/src/platform.ts | 3 +++ server/tool/src/connect.ts | 12 ++++++++++-- server/tool/src/plugin.ts | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pods/account/src/index.ts b/pods/account/src/index.ts index 7e5e732a01..ea6b4c304f 100644 --- a/pods/account/src/index.ts +++ b/pods/account/src/index.ts @@ -64,6 +64,7 @@ export function serveAccount (methods: Record, productId } setMetadata(toolPlugin.metadata.Endpoint, endpointUri) setMetadata(toolPlugin.metadata.Transactor, transactorUri) + setMetadata(toolPlugin.metadata.UserAgent, 'AccountService') let client: MongoClient diff --git a/pods/backup/src/platform.ts b/pods/backup/src/platform.ts index 1b87b82abd..1ae679be5f 100644 --- a/pods/backup/src/platform.ts +++ b/pods/backup/src/platform.ts @@ -21,6 +21,7 @@ import serverToken from '@hcengineering/server-token' import got from 'got' import { ObjectId } from 'mongodb' import config from './config' +import toolPlugin from '@hcengineering/server-tool' /** * @public @@ -72,6 +73,8 @@ export class PlatformWorker { secretKey: config.MinioSecretKey }) + setMetadata(toolPlugin.metadata.UserAgent, config.ServiceID) + await this.backup().then(() => { void this.schedule() }) diff --git a/server/tool/src/connect.ts b/server/tool/src/connect.ts index a7ab5b3b81..70c5fbfbc3 100644 --- a/server/tool/src/connect.ts +++ b/server/tool/src/connect.ts @@ -16,8 +16,9 @@ import client, { clientId } from '@hcengineering/client' import { Client, systemAccountEmail, WorkspaceId } from '@hcengineering/core' -import { addLocation, getResource, setMetadata } from '@hcengineering/platform' +import { addLocation, getMetadata, getResource, setMetadata } from '@hcengineering/platform' import { generateToken } from '@hcengineering/server-token' +import plugin from './plugin' /** * @public @@ -37,7 +38,14 @@ export async function connect ( setMetadata(client.metadata.UseBinaryProtocol, true) setMetadata(client.metadata.UseProtocolCompression, true) - setMetadata(client.metadata.ClientSocketFactory, (url) => new WebSocket(url)) + setMetadata(client.metadata.ClientSocketFactory, (url) => { + const socket = new WebSocket(url, { + headers: { + 'User-Agent': getMetadata(plugin.metadata.UserAgent) ?? 'Anticrm Tool Client' + } + }) + return socket + }) addLocation(clientId, () => import('@hcengineering/client-resources')) return await ( diff --git a/server/tool/src/plugin.ts b/server/tool/src/plugin.ts index 14ee3fc055..6a498faf57 100644 --- a/server/tool/src/plugin.ts +++ b/server/tool/src/plugin.ts @@ -12,7 +12,8 @@ const toolPlugin = plugin(toolId, { metadata: { Endpoint: '' as Metadata, Transactor: '' as Metadata, - InitWorkspace: '' as Metadata + InitWorkspace: '' as Metadata, + UserAgent: '' as Metadata } })