import { Controller, Get, Post, Delete, Body, Param, UseGuards, } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; import { ClusterToolsService } from './cluster-tools.service'; import { InstallToolDto } from './dto/install-tool.dto'; import { RolesGuard } from '../common/guards/roles.guard'; import { Roles } from '../common/decorators/roles.decorator'; import { UserRole } from '../common/enums'; import { ClusterToolId } from './cluster-tools.types'; @ApiTags('Clusters - Tools') @ApiBearerAuth() @Controller('clusters/:id/tools') @UseGuards(AuthGuard('jwt'), RolesGuard) @Roles(UserRole.ADMIN) export class ClusterToolsController { constructor(private readonly toolsService: ClusterToolsService) {} @Get() @ApiOperation({ summary: 'List installable tools and their status on a cluster (Admin)' }) async list(@Param('id') id: string) { return this.toolsService.getToolsForCluster(id); } @Post(':toolId/install') @ApiOperation({ summary: 'Install an infrastructure tool on a cluster (Admin)' }) async install( @Param('id') id: string, @Param('toolId') toolId: ClusterToolId, @Body() dto: InstallToolDto, ) { return this.toolsService.install(id, toolId, { ...dto } as Record); } @Delete(':toolId') @ApiOperation({ summary: 'Uninstall an infrastructure tool from a cluster (Admin)' }) async uninstall( @Param('id') id: string, @Param('toolId') toolId: ClusterToolId, ) { return this.toolsService.uninstall(id, toolId); } }