mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
feat(server): api/admin/storage/test — per-target ephemeral probes, mirror targets probed individually
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Get, HttpException, Put, Req, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Get, HttpCode, HttpException, Post, Put, Req, UseGuards } from '@nestjs/common';
|
||||
import type { Request } from 'express';
|
||||
import { redactStorageSecrets } from './storage-secrets';
|
||||
import type { User } from '../../types';
|
||||
@@ -9,7 +9,7 @@ import { AuditService } from '../audit/audit.service';
|
||||
import { getClientIp } from '../audit/client-ip';
|
||||
import { ManagedForbidden } from '../common/managed';
|
||||
import { StorageAdminService } from './storage-admin.service';
|
||||
import { StorageConfigDto } from './storage-admin.dto';
|
||||
import { StorageConfigDto, StorageTestRequestDto } from './storage-admin.dto';
|
||||
|
||||
/**
|
||||
* /api/admin/storage — the admin surface over the storage registry (spec:
|
||||
@@ -48,4 +48,28 @@ export class StorageAdminController {
|
||||
// The defaults-tab contract: never echo the request — answer the fresh effective world.
|
||||
return this.service.state();
|
||||
}
|
||||
|
||||
@Post('test')
|
||||
@HttpCode(200) // a probe answers 200 with per-target results, not a 201 resource
|
||||
async test(@CurrentUser() user: User, @Body() body: StorageTestRequestDto, @Req() req: Request) {
|
||||
let result;
|
||||
try {
|
||||
result = await this.service.testBackend(body.backend);
|
||||
} catch (err) {
|
||||
throw new HttpException({ error: err instanceof Error ? err.message : String(err) }, 400);
|
||||
}
|
||||
// Audited because the probe writes and deletes an object; names only, never options.
|
||||
this.audit.writeAudit({
|
||||
userId: user.id,
|
||||
action: 'admin.storage_test',
|
||||
ip: getClientIp(req),
|
||||
details: {
|
||||
backend: body.backend.name,
|
||||
type: body.backend.type,
|
||||
ok: result.ok,
|
||||
targets: result.targets.map(({ name, ok }) => ({ name, ok })),
|
||||
},
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user