diff --git a/forge/ee/routes/teamBroker/index.js b/forge/ee/routes/teamBroker/index.js index 651ed494ef..699f37c6c1 100644 --- a/forge/ee/routes/teamBroker/index.js +++ b/forge/ee/routes/teamBroker/index.js @@ -1,3 +1,5 @@ +const schemaApi = require('./schema') + module.exports = async function (app) { app.addHook('preHandler', app.verifySession) @@ -35,6 +37,8 @@ module.exports = async function (app) { } }) + await schemaApi(app) + /** * Get the Teams MQTT Clients * @name /api/v1/teams/:teamId/broker/clients diff --git a/forge/ee/routes/teamBroker/schema.js b/forge/ee/routes/teamBroker/schema.js new file mode 100644 index 0000000000..d2bd59f21e --- /dev/null +++ b/forge/ee/routes/teamBroker/schema.js @@ -0,0 +1,42 @@ +const YAML = require('yaml') +module.exports = async function (app) { + app.get('/team-broker/schema.yml', async (request, reply) => { + const list = await app.teamBroker.getUsedTopics(request.team.hashid) + const schema = { + asyncapi: '3.0.0', + info: { + version: '1.0.0', + title: `${request.team.name} Team Broker`, + description: 'An auto-generated schema of the topics being used on the team broker' + } + } + // Add the team-broker details + + // Figure out the hostname for the team broker + let teamBrokerHost = app.config.broker?.teamBroker?.host + if (!teamBrokerHost) { + // No explict value set, default to broker.${domain} + if (app.config.domain) { + teamBrokerHost = `broker.${app.config.domain}` + } + } + if (teamBrokerHost) { + schema.servers = { + 'team-broker': { + host: teamBrokerHost, + protocol: 'mqtt' + } + } + } + + if (list.length > 0) { + schema.channels = {} + list.forEach(topic => { + schema.channels[topic] = { + address: topic + } + }) + } + reply.send(YAML.stringify(schema)) + }) +} diff --git a/forge/routes/api/settings.js b/forge/routes/api/settings.js index ff5fab41e1..42a703aaca 100644 --- a/forge/routes/api/settings.js +++ b/forge/routes/api/settings.js @@ -47,6 +47,11 @@ module.exports = async function (app) { if (app.config.features.enabled('customHostnames')) { response.cnameTarget = app.config.driver.options?.customHostname?.cnameTarget } + if (app.config.features.enabled('teamBroker')) { + // use IP address if on localfs and no domain configured + const defaultHost = app.config.domain ? `broker.${app.config.domain}` : app.config.host + response['team:broker:host'] = app.config.broker?.teamBroker?.host || defaultHost + } if (request.session.User.admin) { response['platform:licensed'] = isLicensed