43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using w4c_workflows.Filters;
|
||
|
|
using w4c_workflows.Services.Quota;
|
||
|
|
|
||
|
|
namespace w4c_workflows.Controllers;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Per-tenant workflow execution quota. <c>GET</c> returns the current period's
|
||
|
|
/// usage (drives the counter on the Workflows page); <c>POST reset</c> zeroes it
|
||
|
|
/// for the current period (admin / support). Authenticated with the tenant's
|
||
|
|
/// operator key, like every other control-plane endpoint.
|
||
|
|
/// </summary>
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/workflows/quota")]
|
||
|
|
public class WorkflowQuotaController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly WorkflowQuotaService _quota;
|
||
|
|
|
||
|
|
public WorkflowQuotaController(WorkflowQuotaService quota)
|
||
|
|
{
|
||
|
|
_quota = quota;
|
||
|
|
}
|
||
|
|
|
||
|
|
private string TenantId => (string?)HttpContext.Items["TenantId"]
|
||
|
|
?? throw new InvalidOperationException("TenantId not resolved by auth middleware");
|
||
|
|
|
||
|
|
/// <summary>Current execution usage against this tenant's monthly limit.</summary>
|
||
|
|
[HttpGet]
|
||
|
|
[RequireScope("read")]
|
||
|
|
public async Task<IActionResult> Get(CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await _quota.GetAsync(TenantId, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>Resets the current period's execution counter to zero.</summary>
|
||
|
|
[HttpPost("reset")]
|
||
|
|
[RequireScope("manage")]
|
||
|
|
public async Task<IActionResult> Reset(CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await _quota.ResetAsync(TenantId, ct));
|
||
|
|
}
|
||
|
|
}
|