-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a86383
commit 8bb6fa9
Showing
4 changed files
with
96 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 61 additions & 61 deletions
122
Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/ApiGatewayEmulatorProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,78 @@ | ||
using Amazon.Lambda.TestTool.Commands.Settings; | ||
using Amazon.Lambda.TestTool.Extensions; | ||
using Amazon.Lambda.TestTool.Models; | ||
using Amazon.Lambda.TestTool.Services; | ||
|
||
namespace Amazon.Lambda.TestTool.Processes; | ||
|
||
/// <summary> | ||
/// A process that runs the API Gatewat emulator. | ||
/// </summary> | ||
public class ApiGatewayEmulatorProcess | ||
{ | ||
/// <summary> | ||
/// The service provider that will contain all the registered services. | ||
/// </summary> | ||
using Amazon.Lambda.TestTool.Commands.Settings; | ||
using Amazon.Lambda.TestTool.Extensions; | ||
using Amazon.Lambda.TestTool.Models; | ||
using Amazon.Lambda.TestTool.Services; | ||
|
||
namespace Amazon.Lambda.TestTool.Processes; | ||
|
||
/// <summary> | ||
/// A process that runs the API Gatewat emulator. | ||
/// </summary> | ||
public class ApiGatewayEmulatorProcess | ||
{ | ||
/// <summary> | ||
/// The service provider that will contain all the registered services. | ||
/// </summary> | ||
public required IServiceProvider Services { get; init; } | ||
|
||
/// <summary> | ||
/// The API Gatewat emulator task that was started. | ||
/// </summary> | ||
/// <summary> | ||
/// The API Gatewat emulator task that was started. | ||
/// </summary> | ||
public required Task RunningTask { get; init; } | ||
|
||
/// <summary> | ||
/// The endpoint of the API Gatewat emulator. | ||
/// </summary> | ||
/// </summary> | ||
public required string ServiceUrl { get; init; } | ||
|
||
/// <summary> | ||
/// Creates the Web API and runs it in the background. | ||
/// </summary> | ||
public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, CancellationToken cancellationToken = default) | ||
{ | ||
var builder = WebApplication.CreateBuilder(); | ||
|
||
builder.Services.AddApiGatewayEmulatorServices(); | ||
|
||
var serviceUrl = $"http://{settings.Host}:{settings.ApiGatewayEmulatorPort}"; | ||
builder.WebHost.UseUrls(serviceUrl); | ||
/// </summary> | ||
public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, CancellationToken cancellationToken = default) | ||
{ | ||
var builder = WebApplication.CreateBuilder(); | ||
|
||
builder.Services.AddApiGatewayEmulatorServices(); | ||
|
||
var serviceUrl = $"http://{settings.Host}:{settings.ApiGatewayEmulatorPort}"; | ||
builder.WebHost.UseUrls(serviceUrl); | ||
builder.WebHost.SuppressStatusMessages(true); | ||
|
||
builder.Services.AddHealthChecks(); | ||
|
||
var app = builder.Build(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.MapHealthChecks("/health"); | ||
|
||
app.Map("/{**catchAll}", (HttpContext context, IApiGatewayRouteConfigService routeConfigService) => | ||
{ | ||
var routeConfig = routeConfigService.GetRouteConfig(context.Request.Method, context.Request.Path); | ||
if (routeConfig == null) | ||
{ | ||
return Results.NotFound("Route not found"); | ||
} | ||
|
||
if (settings.ApiGatewayEmulatorMode.Equals(ApiGatewayEmulatorMode.HttpV2)) | ||
{ | ||
// TODO: Translate to APIGatewayHttpApiV2ProxyRequest | ||
} | ||
else | ||
{ | ||
// TODO: Translate to APIGatewayProxyRequest | ||
} | ||
|
||
return Results.Ok(); | ||
}); | ||
|
||
var runTask = app.RunAsync(cancellationToken); | ||
|
||
return new ApiGatewayEmulatorProcess | ||
{ | ||
Services = app.Services, | ||
RunningTask = runTask, | ||
ServiceUrl = serviceUrl | ||
}; | ||
} | ||
app.MapHealthChecks("/health"); | ||
|
||
app.Map("/{**catchAll}", (HttpContext context, IApiGatewayRouteConfigService routeConfigService) => | ||
{ | ||
var routeConfig = routeConfigService.GetRouteConfig(context.Request.Method, context.Request.Path); | ||
if (routeConfig == null) | ||
{ | ||
return Results.NotFound("Route not found"); | ||
} | ||
|
||
if (settings.ApiGatewayEmulatorMode.Equals(ApiGatewayEmulatorMode.HttpV2)) | ||
{ | ||
// TODO: Translate to APIGatewayHttpApiV2ProxyRequest | ||
} | ||
else | ||
{ | ||
// TODO: Translate to APIGatewayProxyRequest | ||
} | ||
|
||
return Results.Ok(); | ||
}); | ||
|
||
var runTask = app.RunAsync(cancellationToken); | ||
|
||
return new ApiGatewayEmulatorProcess | ||
{ | ||
Services = app.Services, | ||
RunningTask = runTask, | ||
ServiceUrl = serviceUrl | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters