Skip to content

Commit 8f5794c

Browse files
Merge branch 'main' into fix-apigateway-tracing
2 parents d469586 + 6a57111 commit 8f5794c

27 files changed

+12192
-0
lines changed

.github/workflows/preview.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
run: dotnet pack src/Voxel.MiddyNet.Tracing.SQSMiddleware/Voxel.MiddyNet.Tracing.SQSMiddleware.csproj -c $BUILD_CONFIG --version-suffix $VERSION_SUFFIX --no-build --include-source --include-symbols -o ./artifacts/Voxel.MiddyNet.Tracing.SQSMiddleware
4848
- name: dotnet pack [MiddyNet ProblemDetails]
4949
run: dotnet pack src/Voxel.MiddyNet.ProblemDetailsMiddleware/Voxel.MiddyNet.ProblemDetailsMiddleware.csproj -c $BUILD_CONFIG --version-suffix $VERSION_SUFFIX --no-build --include-source --include-symbols -o ./artifacts/Voxel.MiddyNet.ProblemDetailsMiddleware
50+
- name: dotnet pack [MiddyNet HttpJsonBodyParser]
51+
run: dotnet pack src/Voxel.MiddyNet.HttpJsonBodyParserMiddleware/Voxel.MiddyNet.HttpJsonBodyParserMiddleware.csproj -c $BUILD_CONFIG --version-suffix $VERSION_SUFFIX --no-build --include-source --include-symbols -o ./artifacts/Voxel.MiddyNet.HttpJsonBodyParserMiddleware
5052
- name: setup nuget
5153
uses: NuGet/[email protected]
5254
with:
@@ -67,4 +69,6 @@ jobs:
6769
run: dotnet nuget push ./artifacts/Voxel.MiddyNet.Tracing.SQSMiddleware/*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
6870
- name: Publish Voxel.MiddyNet.ProblemDetailsMiddleware nuget
6971
run: dotnet nuget push ./artifacts/Voxel.MiddyNet.ProblemDetailsMiddleware/*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
72+
- name: Publish Voxel.MiddyNet.HttpJsonBodyParserMiddleware nuget
73+
run: dotnet nuget push ./artifacts/Voxel.MiddyNet.HttpJsonBodyParserMiddleware/*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
7074

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
run: dotnet pack src/Voxel.MiddyNet.Tracing.SQSMiddleware/Voxel.MiddyNet.Tracing.SQSMiddleware.csproj -c $BUILD_CONFIG --no-build --include-source --include-symbols -o ./artifacts/Voxel.MiddyNet.Tracing.SQSMiddleware
5353
- name: dotnet pack [MiddyNet ProblemDetails]
5454
run: dotnet pack src/Voxel.MiddyNet.ProblemDetailsMiddleware/Voxel.MiddyNet.ProblemDetailsMiddleware.csproj -c $BUILD_CONFIG --no-build --include-source --include-symbols -o ./artifacts/Voxel.MiddyNet.ProblemDetailsMiddleware
55+
- name: dotnet pack [MiddyNet HttpJsonBodyParser]
56+
run: dotnet pack src/Voxel.MiddyNet.HttpJsonBodyParserMiddleware/Voxel.MiddyNet.HttpJsonBodyParserMiddleware.csproj -c $BUILD_CONFIG --no-build --include-source --include-symbols -o ./artifacts/Voxel.MiddyNet.HttpJsonBodyParserMiddleware
5557
- name: setup nuget
5658
uses: NuGet/[email protected]
5759
with:
@@ -72,4 +74,6 @@ jobs:
7274
run: dotnet nuget push ./artifacts/Voxel.MiddyNet.Tracing.SQSMiddleware/*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
7375
- name: Publish Voxel.MiddyNet.ProblemDetailsMiddleware nuget
7476
run: dotnet nuget push ./artifacts/Voxel.MiddyNet.ProblemDetailsMiddleware/*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
77+
- name: Publish Voxel.MiddyNet.HttpJsonBodyParserMiddleware nuget
78+
run: dotnet nuget push ./artifacts/Voxel.MiddyNet.HttpJsonBodyParserMiddleware/*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
7579

Voxel.MiddyNet.sln

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiGatewayProblemDetails",
7777
EndProject
7878
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Voxel.MiddyNet.ApiGatewayProblemDetails", "samples\ApiGatewayProblemDetails\Voxel.MiddyNet.ApiGatewayProblemDetails\Voxel.MiddyNet.ApiGatewayProblemDetails.csproj", "{615A99CC-A3ED-4E42-9A9A-AC29B13B095C}"
7979
EndProject
80+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Voxel.MiddyNet.HttpJsonMiddleware.Tests", "test\Voxel.MiddyNet.HttpJsonMiddleware.Tests\Voxel.MiddyNet.HttpJsonMiddleware.Tests.csproj", "{AD9A0773-EF96-4F4A-890C-337277EDCC2F}"
81+
EndProject
82+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Voxel.MiddyNet.HttpJsonMiddleware", "src\Voxel.MiddyNet.HttpJsonMiddleware\Voxel.MiddyNet.HttpJsonMiddleware.csproj", "{111CB170-E682-498D-9E84-42FFFB66CE36}"
83+
EndProject
84+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpJsonBodyParser", "HttpJsonBodyParser", "{2B9304CC-B4DD-4DD5-9428-F7D8A0BC39BC}"
85+
EndProject
86+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Voxel.MiddyNet.HttpJsonBodyParserSample", "samples\HttpJsonBodyParser\Voxel.MiddyNet.HttpJsonBodyParserSample\Voxel.MiddyNet.HttpJsonBodyParserSample.csproj", "{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}"
87+
EndProject
88+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpV2JsonBodyParser", "HttpV2JsonBodyParser", "{308136A6-9610-482A-98E9-D007B6A75437}"
89+
EndProject
90+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Voxel.MiddyNet.HttpV2JsonBodyParserSample", "samples\HttpV2JsonBodyParser\Voxel.MiddyNet.HttpV2JsonBodyParserSample\Voxel.MiddyNet.HttpV2JsonBodyParserSample.csproj", "{ADC380CE-B0FA-4E6A-B12C-F7EB2E4D2DE9}"
91+
EndProject
8092
Global
8193
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8294
Debug|Any CPU = Debug|Any CPU
@@ -191,6 +203,22 @@ Global
191203
{615A99CC-A3ED-4E42-9A9A-AC29B13B095C}.Debug|Any CPU.Build.0 = Debug|Any CPU
192204
{615A99CC-A3ED-4E42-9A9A-AC29B13B095C}.Release|Any CPU.ActiveCfg = Release|Any CPU
193205
{615A99CC-A3ED-4E42-9A9A-AC29B13B095C}.Release|Any CPU.Build.0 = Release|Any CPU
206+
{AD9A0773-EF96-4F4A-890C-337277EDCC2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
207+
{AD9A0773-EF96-4F4A-890C-337277EDCC2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
208+
{AD9A0773-EF96-4F4A-890C-337277EDCC2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
209+
{AD9A0773-EF96-4F4A-890C-337277EDCC2F}.Release|Any CPU.Build.0 = Release|Any CPU
210+
{111CB170-E682-498D-9E84-42FFFB66CE36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
211+
{111CB170-E682-498D-9E84-42FFFB66CE36}.Debug|Any CPU.Build.0 = Debug|Any CPU
212+
{111CB170-E682-498D-9E84-42FFFB66CE36}.Release|Any CPU.ActiveCfg = Release|Any CPU
213+
{111CB170-E682-498D-9E84-42FFFB66CE36}.Release|Any CPU.Build.0 = Release|Any CPU
214+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
215+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
216+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
217+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}.Release|Any CPU.Build.0 = Release|Any CPU
218+
{ADC380CE-B0FA-4E6A-B12C-F7EB2E4D2DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
219+
{ADC380CE-B0FA-4E6A-B12C-F7EB2E4D2DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
220+
{ADC380CE-B0FA-4E6A-B12C-F7EB2E4D2DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
221+
{ADC380CE-B0FA-4E6A-B12C-F7EB2E4D2DE9}.Release|Any CPU.Build.0 = Release|Any CPU
194222
EndGlobalSection
195223
GlobalSection(SolutionProperties) = preSolution
196224
HideSolutionNode = FALSE
@@ -228,6 +256,12 @@ Global
228256
{981ECA54-36BC-4B48-AFE6-AD212E6C9DD8} = {202D1DF0-62D6-4006-99DC-BBFBE59428B1}
229257
{1F42DBC9-C1FC-4FC7-A5A0-97B47C410C26} = {B07FEFF7-B407-4792-8C6B-B6D0CC8626D4}
230258
{615A99CC-A3ED-4E42-9A9A-AC29B13B095C} = {1F42DBC9-C1FC-4FC7-A5A0-97B47C410C26}
259+
{AD9A0773-EF96-4F4A-890C-337277EDCC2F} = {202D1DF0-62D6-4006-99DC-BBFBE59428B1}
260+
{111CB170-E682-498D-9E84-42FFFB66CE36} = {202D1DF0-62D6-4006-99DC-BBFBE59428B1}
261+
{2B9304CC-B4DD-4DD5-9428-F7D8A0BC39BC} = {B07FEFF7-B407-4792-8C6B-B6D0CC8626D4}
262+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9} = {2B9304CC-B4DD-4DD5-9428-F7D8A0BC39BC}
263+
{308136A6-9610-482A-98E9-D007B6A75437} = {B07FEFF7-B407-4792-8C6B-B6D0CC8626D4}
264+
{ADC380CE-B0FA-4E6A-B12C-F7EB2E4D2DE9} = {308136A6-9610-482A-98E9-D007B6A75437}
231265
EndGlobalSection
232266
GlobalSection(ExtensibilityGlobals) = postSolution
233267
SolutionGuid = {EFA347F5-761B-44CF-B6DB-8981387C72B3}

docs/source/nuget/packages.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,69 @@ And like this for Http API::
264264
}
265265
}
266266

267+
Voxel.MiddyNet.HttpJsonBodyParser
268+
---------------------------------
269+
This package contains a middleware that parses a JSON to an object of an explicit type. There are two versions avalaible:
270+
271+
* One for REST APIs (APIGatewayProxyRequest and APIGatewayProxyResponse).
272+
* One for HTTP APIs (APIGatewayHttpApiV2ProxyRequest and APIGatewayHttpApiV2ProxyResponse).
273+
274+
Configuration
275+
^^^^^^^^^^^^^
276+
When you use the middleware, You need to specify the type you want to convert the JSON object into. The middleware will put the object in the AdditionalContext[Constants.BodyContextKey] property. To access the object, you will need to perform an explicit cast of that property.
277+
278+
Sample code
279+
^^^^^^^^^^^
280+
A typical use of the middelware will look like this for Rest API::
281+
282+
public class MySample : MiddyNet<APIGatewayProxyRequest, APIGatewayProxyResponse>
283+
{
284+
public MySample()
285+
{
286+
Use(new HttpJsonBodyParserMiddleware<Foo>());
287+
}
288+
289+
protected override async Task<APIGatewayProxyResponse> Handle(APIGatewayProxyRequest apiEvent, MiddyNetContext context)
290+
{
291+
var foo = ((Foo)context.AdditionalContext[Constants.BodyContextKey]);
292+
293+
// Do stuff with foo
294+
295+
var result = new APIGatewayProxyResponse
296+
{
297+
StatusCode = 200,
298+
Body = "hello from test"
299+
};
300+
301+
return Task.FromResult(result);
302+
}
303+
}
304+
305+
And like this for Http API::
306+
307+
public class MySample : MiddyNet<APIGatewayHttpApiV2ProxyRequest, APIGatewayHttpApiV2ProxyResponse>
308+
{
309+
public MySample()
310+
{
311+
Use(new HttpV2JsonBodyParserMiddleware<Foo>());
312+
}
313+
314+
protected override async Task<APIGatewayHttpApiV2ProxyResponse> Handle(APIGatewayHttpApiV2ProxyResponse apiEvent, MiddyNetContext context)
315+
{
316+
var foo = ((Foo)context.AdditionalContext[Constants.BodyContextKey]);
317+
318+
// Do stuff with typed foo
319+
320+
var result = new APIGatewayHttpApiV2ProxyResponse
321+
{
322+
StatusCode = 200,
323+
Body = "hello from test"
324+
};
325+
326+
return Task.FromResult(result);
327+
}
328+
}
329+
267330
Voxel.MiddyNet.ProblemDetailsMiddleware
268331
---------------------------------------
269332
The middleware contained in this package formats Api exceptions as ProblemDetails following [RFC7807](https://tools.ietf.org/html/rfc7807).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Threading.Tasks;
2+
using Amazon.Lambda.Core;
3+
using Amazon.Lambda.APIGatewayEvents;
4+
using Voxel.MiddyNet.HttpJsonMiddleware;
5+
6+
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
7+
namespace Voxel.MiddyNet.HttpJsonBodyParserSample
8+
{
9+
public class HttpJsonBodyParser : MiddyNet<APIGatewayProxyRequest, APIGatewayProxyResponse>
10+
{
11+
public HttpJsonBodyParser()
12+
{
13+
Use(new HttpJsonBodyParserMiddleware<Person>());
14+
}
15+
16+
protected override Task<APIGatewayProxyResponse> Handle(APIGatewayProxyRequest lambdaEvent, MiddyNetContext context)
17+
{
18+
var person = ((Person) context.AdditionalContext[HttpJsonBodyParserMiddleware.BodyContextKey]);
19+
context.Logger.Log(LogLevel.Info, "Function called", new LogProperty(HttpJsonBodyParserMiddleware.BodyContextKey, person));
20+
var result = new APIGatewayProxyResponse
21+
{
22+
StatusCode = 200,
23+
Body = $"Person name is {person.Name} {person.Surname} and it is {person.Age} years old."
24+
};
25+
26+
return Task.FromResult(result);
27+
}
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Voxel.MiddyNet.HttpJsonBodyParserSample
4+
{
5+
public class Person
6+
{
7+
[JsonPropertyName("name")]
8+
public string Name { get; set; }
9+
[JsonPropertyName("surname")]
10+
public string Surname { get; set; }
11+
[JsonPropertyName("age")]
12+
public int Age { get; set; }
13+
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
6+
<AssemblyName>Voxel.MiddyNet.HttpJsonBodyParserSample</AssemblyName>
7+
<PackageId>Voxel.MiddyNet.HttpJsonBodyParserSample</PackageId>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Amazon.Lambda.Core" Version="1.2.0" />
12+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.1.0" />
13+
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.4.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\..\src\Voxel.MiddyNet.HttpJsonMiddleware\Voxel.MiddyNet.HttpJsonMiddleware.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dotnet restore
2+
dotnet tool install -g Amazon.Lambda.Tools --framework netcoreapp3.1
3+
dotnet build --configuration Release
4+
dotnet lambda package --configuration Release --framework netcoreapp3.1 --output-package bin/Release/netcoreapp3.1/Voxel.MiddyNet.HttpJsonBodyParserSample.zip
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
#install zip on debian OS, since microsoft/dotnet container doesn't have zip by default
4+
if [ -f /etc/debian_version ]
5+
then
6+
apt -qq update
7+
apt -qq -y install zip
8+
fi
9+
10+
dotnet restore
11+
dotnet tool install -g Amazon.Lambda.Tools --framework netcoreapp3.1
12+
dotnet build --configuration Release
13+
dotnet lambda package --configuration Release --framework netcoreapp3.1 --output-package bin/Release/netcoreapp3.1/Voxel.MiddyNet.HttpJsonBodyParserSample.zip
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
service: voxel-middynet-httpJsonBodyParserSample
2+
3+
provider:
4+
name: aws
5+
runtime: dotnetcore3.1
6+
region: ${opt:region, self:custom.defaultRegion}
7+
stage: ${opt:stage, self:custom.defaultStage}
8+
9+
custom:
10+
defaultRegion: eu-west-1
11+
defaultStage: dev${env:SLSUSER, ""}
12+
sqsTracingSampleQueueName: ${self:service}-${self:provider.stage}-httpJsonBodyParserSample
13+
package:
14+
individually: true
15+
16+
functions:
17+
httpJsonParserSample:
18+
handler: Voxel.MiddyNet.HttpJsonBodyParserSample::Voxel.MiddyNet.HttpJsonBodyParserSample.HttpJsonBodyParser::Handler
19+
package:
20+
artifact: bin/Release/netcoreapp3.1/Voxel.MiddyNet.HttpJsonBodyParserSample.zip
21+
events:
22+
- http: POST testParser

0 commit comments

Comments
 (0)