hedgedoc/src/api/public/monitoring/monitoring.controller.ts
Philip Molares 216baa42a1
refactor: move TokenAuthGuard in the same file as TokenStrategy
This should help to make clear why code is executed when the TokenAuthGuard is encountered by a request. Currently, one has to connect both files via the string 'token', which is a bit cryptic

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-09-04 18:03:41 +02:00

54 lines
1.5 KiB
TypeScript

/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Controller, Get, UseGuards } from '@nestjs/common';
import {
ApiForbiddenResponse,
ApiOkResponse,
ApiProduces,
ApiSecurity,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { TokenAuthGuard } from '../../../auth/token.strategy';
import { MonitoringService } from '../../../monitoring/monitoring.service';
import { ServerStatusDto } from '../../../monitoring/server-status.dto';
import {
forbiddenDescription,
unauthorizedDescription,
} from '../../utils/descriptions';
@ApiTags('monitoring')
@ApiSecurity('token')
@Controller('monitoring')
export class MonitoringController {
constructor(private monitoringService: MonitoringService) {}
@UseGuards(TokenAuthGuard)
@Get()
@ApiOkResponse({
description: 'The server info',
type: ServerStatusDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
getStatus(): Promise<ServerStatusDto> {
// TODO: toServerStatusDto.
return this.monitoringService.getServerStatus();
}
@UseGuards(TokenAuthGuard)
@Get('prometheus')
@ApiOkResponse({
description: 'Prometheus compatible monitoring data',
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiProduces('text/plain')
getPrometheusStatus(): string {
return '';
}
}