Skip to content

Commit

Permalink
Support new session api
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelldi committed Mar 23, 2024
1 parent 8b0ff1c commit de6639c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
30 changes: 27 additions & 3 deletions src/dotnet/aspire-session-host/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@ namespace AspireSessionHost;

[UsedImplicitly]
internal sealed record Session(
string ProjectPath,
bool Debug,
LaunchConfiguration[] LaunchConfigurations,
EnvironmentVariable[]? Env,
string[]? Args
);

[UsedImplicitly]
internal sealed record EnvironmentVariable(string Name, string? Value);
internal sealed record LaunchConfiguration(
string Type,
string ProjectPath,
Mode? Mode,
string[]? LaunchProfile,
bool? DisableLaunchProfile
);

internal enum Mode
{
Debug,
NoDebug
}

[UsedImplicitly]
internal sealed record EnvironmentVariable(string Name, string? Value);

[UsedImplicitly]
internal sealed record ErrorResponse(ErrorDetail Error);

[UsedImplicitly]
internal sealed record ErrorDetail(
string Code,
string Message,
ErrorDetail[]? Details = null
);
12 changes: 10 additions & 2 deletions src/dotnet/aspire-session-host/Sessions/SessionEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ internal static void MapSessionEndpoints(this IEndpointRouteBuilder routes)

group.MapPut(
"/",
async Task<Results<Created<Session>, BadRequest<string>>> (Session session, SessionService service) =>
async Task<Results<Created<Session>, BadRequest<ErrorResponse>>> (Session session,
SessionService service) =>
{
var id = await service.Create(session);
return id.HasValue
? TypedResults.Created($"/run_session/{id.Value}", session)
: TypedResults.BadRequest("Unable to create a session");
: TypedResults.BadRequest(
new ErrorResponse(
new ErrorDetail(
"UnexpectedError",
"Unable to create a session"
)
)
);
});

group.MapDelete(
Expand Down
8 changes: 6 additions & 2 deletions src/dotnet/aspire-session-host/Sessions/SessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ internal sealed class SessionService(Connection connection, ILogger<SessionServi
{
internal async Task<Guid?> Create(Session session)
{
var launchConfiguration = session.LaunchConfigurations
.FirstOrDefault(it => string.Equals(it.Type, "project", StringComparison.InvariantCultureIgnoreCase));
if (launchConfiguration is null) return null;

var id = Guid.NewGuid();
var stringId = id.ToString();
var envs = session.Env
Expand All @@ -16,8 +20,8 @@ internal sealed class SessionService(Connection connection, ILogger<SessionServi
?.ToArray();
var sessionModel = new SessionModel(
stringId,
session.ProjectPath,
session.Debug,
launchConfiguration.ProjectPath,
launchConfiguration.Mode == Mode.Debug,
session.Args,
envs
);
Expand Down

0 comments on commit de6639c

Please sign in to comment.