-
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.
feat: add api gateway emulator skeleton
- Loading branch information
Showing
31 changed files
with
795 additions
and
130 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/CancellableAsyncCommand.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Spectre.Console.Cli; | ||
|
||
public abstract class CancellableAsyncCommand<TSettings> : AsyncCommand<TSettings> where TSettings : CommandSettings | ||
{ | ||
public abstract Task<int> ExecuteAsync(CommandContext context, TSettings settings, CancellationTokenSource cancellationTokenSource); | ||
|
||
public sealed override async Task<int> ExecuteAsync(CommandContext context, TSettings settings) | ||
{ | ||
using var cancellationSource = new CancellationTokenSource(); | ||
|
||
using var sigInt = PosixSignalRegistration.Create(PosixSignal.SIGINT, onSignal); | ||
using var sigQuit = PosixSignalRegistration.Create(PosixSignal.SIGQUIT, onSignal); | ||
using var sigTerm = PosixSignalRegistration.Create(PosixSignal.SIGTERM, onSignal); | ||
|
||
var cancellable = ExecuteAsync(context, settings, cancellationSource); | ||
return await cancellable; | ||
|
||
void onSignal(PosixSignalContext context) | ||
{ | ||
context.Cancel = true; | ||
cancellationSource.Cancel(); | ||
} | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Amazon.Lambda.TestTool.Models; | ||
using Spectre.Console.Cli; | ||
using System.ComponentModel; | ||
|
||
namespace Amazon.Lambda.TestTool.Commands.Settings; | ||
|
||
/// <summary> | ||
/// Represents the settings for configuring the <see cref="RunCommand"/>, which is the default command. | ||
/// </summary> | ||
public sealed class RunCommandSettings : CommandSettings | ||
{ | ||
/// <summary> | ||
/// The hostname or IP address used for the test tool's web interface. | ||
/// Any host other than an explicit IP address or localhost (e.g. '*', '+' or 'example.com') binds to all public IPv4 and IPv6 addresses. | ||
/// </summary> | ||
[CommandOption("--host <HOST>")] | ||
[Description( | ||
"The hostname or IP address used for the test tool's web interface. Any host other than an explicit IP address or localhost (e.g. '*', '+' or 'example.com') binds to all public IPv4 and IPv6 addresses.")] | ||
[DefaultValue(Constants.DefaultHost)] | ||
public string Host { get; set; } = Constants.DefaultHost; | ||
|
||
/// <summary> | ||
/// The port number used for the test tool's web interface. | ||
/// </summary> | ||
[CommandOption("-p|--port <PORT>")] | ||
[Description("The port number used for the test tool's web interface.")] | ||
[DefaultValue(Constants.DefaultPort)] | ||
public int Port { get; set; } = Constants.DefaultPort; | ||
|
||
/// <summary> | ||
/// Disable auto launching the test tool's web interface in a browser. | ||
/// </summary> | ||
[CommandOption("--no-launch-window")] | ||
[Description("Disable auto launching the test tool's web interface in a browser.")] | ||
public bool NoLaunchWindow { get; set; } | ||
|
||
/// <summary> | ||
/// If set to true the test tool will pause waiting for a key input before exiting. | ||
/// The is useful when executing from an IDE so you can avoid having the output window immediately disappear after executing the Lambda code. | ||
/// The default value is true. | ||
/// </summary> | ||
[CommandOption("--pause-exit")] | ||
[Description("If set to true the test tool will pause waiting for a key input before exiting. The is useful when executing from an IDE so you can avoid having the output window immediately disappear after executing the Lambda code. The default value is true.")] | ||
public bool PauseExit { get; set; } | ||
|
||
/// <summary> | ||
/// Disables logging in the application | ||
/// </summary> | ||
[CommandOption("--disable-logs")] | ||
[Description("Disables logging in the application")] | ||
public bool DisableLogs { get; set; } | ||
|
||
/// <summary> | ||
/// The API Gateway Emulator Mode specifies the format of the event that API Gateway sends to a Lambda integration, | ||
/// and how API Gateway interprets the response from Lambda. | ||
/// The available modes are: Rest, HttpV1, HttpV2. | ||
/// </summary> | ||
[CommandOption("--api-gateway-emulator <MODE>")] | ||
[Description( | ||
"The API Gateway Emulator Mode specifies the format of the event that API Gateway sends to a Lambda integration, and how API Gateway interprets the response from Lambda. " + | ||
"The available modes are: Rest, HttpV1, HttpV2.")] | ||
public ApiGatewayEmulatorMode? ApiGatewayEmulatorMode { get; set; } | ||
|
||
/// <summary> | ||
/// The port number used for the test tool's API Gateway emulator. | ||
/// </summary> | ||
[CommandOption("--api-gateway-emulator-port <PORT>")] | ||
[Description("The port number used for the test tool's API Gateway emulator.")] | ||
[DefaultValue(Constants.DefaultApiGatewayEmulatorPort)] | ||
public int? ApiGatewayEmulatorPort { get; set; } = Constants.DefaultApiGatewayEmulatorPort; | ||
} |
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
1 change: 1 addition & 0 deletions
1
Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Components/Pages/SaveRequestDialog.razor
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
75 changes: 73 additions & 2 deletions
75
Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Constants.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,23 +1,94 @@ | ||
using Amazon.Lambda.TestTool.Models; | ||
|
||
namespace Amazon.Lambda.TestTool; | ||
|
||
/// <summary> | ||
/// Provides constant values used across the application. | ||
/// </summary> | ||
public abstract class Constants | ||
{ | ||
/// <summary> | ||
/// The name of the dotnet CLI tool | ||
/// </summary> | ||
public const string ToolName = "lambda-test-tool"; | ||
|
||
/// <summary> | ||
/// The default port used by the Lambda Test Tool for the Lambda Runtime API and the Web Interface. | ||
/// </summary> | ||
public const int DefaultPort = 5050; | ||
|
||
/// <summary> | ||
/// The default port used by the API Gateway Emulator. | ||
/// </summary> | ||
public const int DefaultApiGatewayEmulatorPort = 5051; | ||
|
||
/// <summary> | ||
/// The default hostname used for the Lambda Test Tool. | ||
/// </summary> | ||
public const string DefaultHost = "localhost"; | ||
|
||
/// <summary> | ||
/// The default mode for the API Gateway Emulator. | ||
/// </summary> | ||
public const ApiGatewayEmulatorMode DefaultApiGatewayEmulatorMode = ApiGatewayEmulatorMode.HttpV2; | ||
|
||
/// <summary> | ||
/// The prefix for environment variables used to configure the Lambda functions. | ||
/// </summary> | ||
public const string LambdaConfigEnvironmentVariablePrefix = "APIGATEWAY_EMULATOR_ROUTE_CONFIG"; | ||
|
||
/// <summary> | ||
/// The product name displayed for the Lambda Test Tool. | ||
/// </summary> | ||
public const string ProductName = "AWS .NET Mock Lambda Test Tool"; | ||
|
||
/// <summary> | ||
/// The CSS style used for successful responses in the tool's UI. | ||
/// </summary> | ||
public const string ResponseSuccessStyle = "white-space: pre-wrap; height: min-content; font-size: 75%; color: black"; | ||
|
||
/// <summary> | ||
/// The CSS style used for error responses in the tool's UI. | ||
/// </summary> | ||
public const string ResponseErrorStyle = "white-space: pre-wrap; height: min-content; font-size: 75%; color: red"; | ||
|
||
/// <summary> | ||
/// The CSS style used for successful responses in the tool's UI when a size constraint is applied. | ||
/// </summary> | ||
public const string ResponseSuccessStyleSizeConstraint = "white-space: pre-wrap; height: 300px; font-size: 75%; color: black"; | ||
|
||
/// <summary> | ||
/// The CSS style used for error responses in the tool's UI when a size constraint is applied. | ||
/// </summary> | ||
public const string ResponseErrorStyleSizeConstraint = "white-space: pre-wrap; height: 300px; font-size: 75%; color: red"; | ||
|
||
/// <summary> | ||
/// The GitHub repository link for the AWS Lambda .NET repository. | ||
/// </summary> | ||
public const string LinkGithubRepo = "https://github.com/aws/aws-lambda-dotnet"; | ||
public const string LinkGithubTestTool = "https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool"; | ||
|
||
/// <summary> | ||
/// The GitHub link for the Lambda Test Tool. | ||
/// </summary> | ||
public const string LinkGithubTestTool = "https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool-v2"; | ||
|
||
/// <summary> | ||
/// The GitHub link for the Lambda Test Tool's installation and running instructions. | ||
/// </summary> | ||
public const string LinkGithubTestToolInstallAndRun = "https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool#installing-and-running"; | ||
|
||
/// <summary> | ||
/// The AWS Developer Guide link for Dead Letter Queues in AWS Lambda. | ||
/// </summary> | ||
public const string LinkDlqDeveloperGuide = "https://docs.aws.amazon.com/lambda/latest/dg/dlq.html"; | ||
|
||
/// <summary> | ||
/// The Microsoft documentation link for the <see cref="System.Runtime.Loader.AssemblyLoadContext"/> class. | ||
/// </summary> | ||
public const string LinkMsdnAssemblyLoadContext = "https://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext"; | ||
public const string LinkVsToolkitMarketplace = "https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.AWSToolkitforVisualStudio2017"; | ||
|
||
/// <summary> | ||
/// The Visual Studio Marketplace link for the AWS Toolkit for Visual Studio. | ||
/// </summary> | ||
public const string LinkVsToolkitMarketplace = "https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.AWSToolkitforVisualStudio2022"; | ||
} |
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
17 changes: 17 additions & 0 deletions
17
Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Extensions/ServiceCollectionExtensions.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,14 +1,31 @@ | ||
using Amazon.Lambda.TestTool.Services; | ||
using Amazon.Lambda.TestTool.Services.IO; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace Amazon.Lambda.TestTool.Extensions; | ||
|
||
/// <summary> | ||
/// A class that contains extension methods for the <see cref="IServiceCollection"/> interface. | ||
/// </summary> | ||
public static class ServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Adds a set of services for the .NET CLI portion of this application. | ||
/// </summary> | ||
public static void AddCustomServices(this IServiceCollection serviceCollection, | ||
ServiceLifetime lifetime = ServiceLifetime.Singleton) | ||
{ | ||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(IToolInteractiveService), typeof(ConsoleInteractiveService), lifetime)); | ||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(IDirectoryManager), typeof(DirectoryManager), lifetime)); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a set of services for the API Gateway emulator portion of this application. | ||
/// </summary> | ||
public static void AddApiGatewayEmulatorServices(this IServiceCollection serviceCollection, | ||
ServiceLifetime lifetime = ServiceLifetime.Singleton) | ||
{ | ||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(IApiGatewayRouteConfigService), typeof(ApiGatewayRouteConfigService), lifetime)); | ||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(IEnvironmentManager), typeof(EnvironmentManager), lifetime)); | ||
} | ||
} |
Oops, something went wrong.