podman-client-dotnet/src/PodmanClient/PodmanClient.Exec.cs
copilot-swe-agent[bot] bbba014602
feat: add System.Text.Json source generation for AOT/trim compatibility
- Add PodmanJsonContext (JsonSerializerContext) covering all ~70 DTOs and
  request models used by the library with PropertyNameCaseInsensitive=true
- Replace MaksIT.Core ToJson()/ToObject<T>() with explicit JsonTypeInfo<T>
  parameters threaded through all internal HTTP helper methods
- Update all call sites in PodmanClient partial classes
- Update PodmanProgressSession<T> constructor to accept JsonTypeInfo<T>
- Remove MaksIT.Core package reference (no longer needed)
- Enable IsAotCompatible=true in project file to activate trim/AOT analyzers
- All 13 unit tests pass, 0 build warnings
2026-06-30 17:15:10 +00:00

93 lines
2.6 KiB
C#

using MaksIT.PodmanClientDotNet;
using System.Text.Json;
using Microsoft.Extensions.Logging;
using MaksIT.PodmanClientDotNet.Internal;
using MaksIT.PodmanClientDotNet.Models;
using MaksIT.PodmanClientDotNet.Dtos.Exec;
using MaksIT.PodmanClientDotNet.Models.Exec;
using MaksIT.Results;
public partial class PodmanClient {
public async Task<Result<CreateExecResponseDto?>> CreateExecAsync(
string containerName,
string[] cmd,
bool attachStderr = true,
bool attachStdin = false,
bool attachStdout = true,
string? detachKeys = null,
string[]? env = null,
bool privileged = false,
bool tty = false,
string? user = null,
string? workingDir = null
) {
var execRequest = new CreateExecRequest {
AttachStderr = attachStderr,
AttachStdin = attachStdin,
AttachStdout = attachStdout,
Cmd = cmd,
DetachKeys = detachKeys,
Env = env,
Privileged = privileged,
Tty = tty,
User = user,
WorkingDir = workingDir,
};
return await PostJsonAsync<CreateExecRequest, CreateExecResponseDto>(
$"/libpod/containers/{Uri.EscapeDataString(containerName)}/exec",
"Create exec",
execRequest,
PodmanJsonContext.Default.CreateExecRequest,
PodmanJsonContext.Default.CreateExecResponseDto
).ConfigureAwait(false);
}
public async Task<Result> StartExecAsync(
string execId,
bool detach = false,
bool tty = false,
int? height = null,
int? width = null
) {
var startExecRequest = new StartExecRequest {
Detach = detach,
Tty = tty,
Height = height,
Width = width,
};
var result = await PostJsonWithoutBodyAsync<StartExecRequest>(
$"/libpod/exec/{Uri.EscapeDataString(execId)}/start",
"Start exec",
startExecRequest,
PodmanJsonContext.Default.StartExecRequest
).ConfigureAwait(false);
if (result.IsSuccess)
_logger.LogInformation("Exec started successfully.");
return result;
}
public Task<Result<InspectExecResponseDto?>> InspectExecAsync(string execId) =>
GetJsonAsync<InspectExecResponseDto>(
$"/libpod/exec/{Uri.EscapeDataString(execId)}/json",
"Inspect exec",
PodmanJsonContext.Default.InspectExecResponseDto
);
public Task<Result> ResizeExecAsync(string execId, int height, int width, CancellationToken cancellationToken = default) =>
PostWithoutBodyAsync(
$"/libpod/exec/{Uri.EscapeDataString(execId)}/resize",
"Resize exec",
query: [
("h", height.ToString()),
("w", width.ToString()),
],
cancellationToken: cancellationToken
);
}