Diagnostic tool: testing API communication from Prosody to Peertube.

This commit is contained in:
John Livingston
2021-06-22 12:57:24 +02:00
parent 7279761c66
commit a526feac19
6 changed files with 83 additions and 7 deletions

View File

@ -113,6 +113,27 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
return result
}
try {
const apiUrl = `http://localhost:${prosodyPort}/peertubelivechat_test/test-prosody-peertube`
const testResult = await got(apiUrl, {
method: 'GET',
headers: {
authorization: 'Bearer ' + await getAPIKey(options)
},
responseType: 'json',
resolveBodyOnly: true
})
if (testResult.ok === true) {
result.messages.push('API Prosody -> Peertube is OK')
} else {
result.messages.push('API Prosody -> Peertube is KO. Response was: ' + JSON.stringify(testResult))
return result
}
} catch (error) {
result.messages.push('Error when calling Prosody test api (test-prosody-peertube): ' + (error as string))
return result
}
result.ok = true
return result
}

View File

@ -85,6 +85,7 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
'api/'
const authApiUrl = baseApiUrl + 'user' // FIXME: should be protected by apikey, but mod_auth_http cant handle params
const roomApiUrl = baseApiUrl + 'room?apikey=' + apikey + '&jid={room.jid|jid_node}'
const testApiUrl = baseApiUrl + 'test?apikey=' + apikey
const config = new ProsodyConfigContent(paths, prosodyDomain)
config.useHttpAuthentication(authApiUrl)
@ -96,7 +97,7 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
// TODO: add a settings to choose?
config.useDefaultPersistent()
config.useTestModule(apikey)
config.useTestModule(apikey, testApiUrl)
let logLevel: ProsodyLogLevel | undefined
if (logger.level && (typeof logger.level === 'string')) {

View File

@ -236,9 +236,10 @@ class ProsodyConfigContent {
this.muc.set('muc_room_default_persistent', true)
}
useTestModule (apikey: string): void {
useTestModule (prosodyApikey: string, apiurl: string): void {
this.global.add('modules_enabled', 'http_peertubelivechat_test')
this.global.set('peertubelivechat_test_apikey', apikey)
this.global.set('peertubelivechat_test_apikey', prosodyApikey)
this.global.set('peertubelivechat_test_peertube_api_url', apiurl)
}
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {

View File

@ -34,6 +34,14 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
const router = getRouter()
const logger = peertubeHelpers.logger
router.get('/test', asyncMiddleware([
getCheckAPIKeyMiddleware(options),
async (req: Request, res: Response, _next: NextFunction) => {
logger.info('Test api call')
res.json({ ok: true })
}
]))
router.get('/room', asyncMiddleware([
getCheckAPIKeyMiddleware(options),
async (req: Request, res: Response, _next: NextFunction) => {