w4c-workflows-api/Services/ForgejoWorkflowRepoService.AdminApi.cs
Vitali sharp8n 42ffcb9adc workflows
2026-09-13 19:28:47 +03:00

30 lines
1.2 KiB
C#

namespace w4c_workflows.Services;
// Forgejo admin-API half of the workflow repo service: a single authenticated
// JSON call against the Forgejo REST API using the pooled named client.
public sealed partial class ForgejoWorkflowRepoService
{
private async Task<HttpResponseMessage> SendAdminAsync(
HttpMethod method, string path, object? body, CancellationToken ct)
{
using var request = new HttpRequestMessage(method, $"{_forgejoBase}/api/v1{path}");
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
"Bearer", _forgejoAdminToken);
if (body != null)
{
request.Content = new StringContent(
System.Text.Json.JsonSerializer.Serialize(body, new System.Text.Json.JsonSerializerOptions
{
PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.SnakeCaseLower,
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
}),
System.Text.Encoding.UTF8,
"application/json");
}
return await _adminHttp.SendAsync(request, ct);
}
}