Skip to content

Commit

Permalink
UBERF-4289: Allow to configure user agent
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Nov 15, 2023
1 parent 5d8c1a6 commit 48f1cab
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions pods/account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function serveAccount (methods: Record<string, AccountMethod>, productId
}
setMetadata(toolPlugin.metadata.Endpoint, endpointUri)
setMetadata(toolPlugin.metadata.Transactor, transactorUri)
setMetadata(toolPlugin.metadata.UserAgent, 'AccountService')

let client: MongoClient

Expand Down
3 changes: 3 additions & 0 deletions pods/backup/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,6 +73,8 @@ export class PlatformWorker {
secretKey: config.MinioSecretKey
})

setMetadata(toolPlugin.metadata.UserAgent, config.ServiceID)

await this.backup().then(() => {
void this.schedule()
})
Expand Down
12 changes: 10 additions & 2 deletions server/tool/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion server/tool/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const toolPlugin = plugin(toolId, {
metadata: {
Endpoint: '' as Metadata<string>,
Transactor: '' as Metadata<string>,
InitWorkspace: '' as Metadata<string>
InitWorkspace: '' as Metadata<string>,
UserAgent: '' as Metadata<string>
}
})

Expand Down

0 comments on commit 48f1cab

Please sign in to comment.