Skip to content

Commit 5495eeb

Browse files
Lambda Authorizer Annotations Support (#2284)
1 parent 0838ea4 commit 5495eeb

54 files changed

Lines changed: 5469 additions & 934 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.Annotations",
5+
"Type": "Minor",
6+
"ChangelogMessages": [
7+
"Developers can now define Lambda Authorizers and protect API endpoints entirely through C# attributes, eliminating the need for manual CloudFormation configuration."
8+
]
9+
}
10+
]
11+
}

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Amazon.Lambda.Annotations.SourceGenerator.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
<ItemGroup>
6464
<TargetPathWithTargetPlatformMoniker Include="$(PKGNewtonsoft_Json)\lib\netstandard2.0\Newtonsoft.Json.dll" IncludeRuntimeDependency="false" />
6565
<TargetPathWithTargetPlatformMoniker Include="$(PKGYamlDotNet)\lib\netstandard2.0\YamlDotNet.dll" IncludeRuntimeDependency="false" />
66+
<!-- The source generator loads Amazon.Lambda.Annotations at runtime to inspect attribute types.
67+
Without this, the generator fails with FileNotFoundException in Release builds (CS8785).
68+
Use absolute path via $(MSBuildProjectDirectory) so the path resolves correctly when
69+
propagated to consuming projects through the project reference chain. -->
70+
<TargetPathWithTargetPlatformMoniker Include="$(MSBuildProjectDirectory)\$(OutputPath)Amazon.Lambda.Annotations.dll" IncludeRuntimeDependency="false" />
6671
</ItemGroup>
6772
</Target>
6873

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
; Unshipped analyzer release
22
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
3+
4+
### New Rules
5+
6+
Rule ID | Category | Severity | Notes
7+
--------|----------|----------|-------
8+
AWSLambda0120 | AWSLambdaCSharpGenerator | Error | Authorizer Name Required
9+
AWSLambda0121 | AWSLambdaCSharpGenerator | Error | HTTP API Authorizer Not Found
10+
AWSLambda0122 | AWSLambdaCSharpGenerator | Error | REST API Authorizer Not Found
11+
AWSLambda0123 | AWSLambdaCSharpGenerator | Error | Authorizer Type Mismatch
12+
AWSLambda0124 | AWSLambdaCSharpGenerator | Error | Authorizer Type Mismatch
13+
AWSLambda0125 | AWSLambdaCSharpGenerator | Error | Duplicate Authorizer Name
14+
AWSLambda0127 | AWSLambdaCSharpGenerator | Error | Invalid Result TTL
15+
AWSLambda0128 | AWSLambdaCSharpGenerator | Error | Authorizer Payload Version Mismatch
16+
AWSLambda0129 | AWSLambdaCSharpGenerator | Error | Missing LambdaFunction Attribute

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,78 @@ public static class DiagnosticDescriptors
153153
category: "AWSLambdaCSharpGenerator",
154154
DiagnosticSeverity.Error,
155155
isEnabledByDefault: true);
156+
157+
// Authorizer diagnostics (ALA0019-ALA0027 per design document)
158+
public static readonly DiagnosticDescriptor AuthorizerMissingName = new DiagnosticDescriptor(
159+
id: "AWSLambda0120",
160+
title: "Authorizer Name Required",
161+
messageFormat: "The Name property is required on [{0}] attribute",
162+
category: "AWSLambdaCSharpGenerator",
163+
DiagnosticSeverity.Error,
164+
isEnabledByDefault: true);
165+
166+
public static readonly DiagnosticDescriptor HttpApiAuthorizerNotFound = new DiagnosticDescriptor(
167+
id: "AWSLambda0121",
168+
title: "HTTP API Authorizer Not Found",
169+
messageFormat: "Authorizer '{0}' referenced in [HttpApi] attribute does not exist. Add [HttpApiAuthorizer] to an authorizer Lambda function method named '{0}', or reference it using nameof().",
170+
category: "AWSLambdaCSharpGenerator",
171+
DiagnosticSeverity.Error,
172+
isEnabledByDefault: true);
173+
174+
public static readonly DiagnosticDescriptor RestApiAuthorizerNotFound = new DiagnosticDescriptor(
175+
id: "AWSLambda0122",
176+
title: "REST API Authorizer Not Found",
177+
messageFormat: "Authorizer '{0}' referenced in [RestApi] attribute does not exist. Add [RestApiAuthorizer] to an authorizer Lambda function method named '{0}', or reference it using nameof().",
178+
category: "AWSLambdaCSharpGenerator",
179+
DiagnosticSeverity.Error,
180+
isEnabledByDefault: true);
181+
182+
public static readonly DiagnosticDescriptor HttpApiAuthorizerTypeMismatch = new DiagnosticDescriptor(
183+
id: "AWSLambda0123",
184+
title: "Authorizer Type Mismatch",
185+
messageFormat: "Cannot use REST API authorizer '{0}' with [HttpApi] attribute. Use an [HttpApiAuthorizer] instead.",
186+
category: "AWSLambdaCSharpGenerator",
187+
DiagnosticSeverity.Error,
188+
isEnabledByDefault: true);
189+
190+
public static readonly DiagnosticDescriptor RestApiAuthorizerTypeMismatch = new DiagnosticDescriptor(
191+
id: "AWSLambda0124",
192+
title: "Authorizer Type Mismatch",
193+
messageFormat: "Cannot use HTTP API authorizer '{0}' with [RestApi] attribute. Use a [RestApiAuthorizer] instead.",
194+
category: "AWSLambdaCSharpGenerator",
195+
DiagnosticSeverity.Error,
196+
isEnabledByDefault: true);
197+
198+
public static readonly DiagnosticDescriptor DuplicateAuthorizerName = new DiagnosticDescriptor(
199+
id: "AWSLambda0125",
200+
title: "Duplicate Authorizer Name",
201+
messageFormat: "Duplicate authorizer name '{0}'. Authorizer names must be unique within the same API type.",
202+
category: "AWSLambdaCSharpGenerator",
203+
DiagnosticSeverity.Error,
204+
isEnabledByDefault: true);
205+
206+
public static readonly DiagnosticDescriptor InvalidAuthorizerResultTtl = new DiagnosticDescriptor(
207+
id: "AWSLambda0127",
208+
title: "Invalid Result TTL",
209+
messageFormat: "Invalid ResultTtlInSeconds '{0}'. Must be between 0 and 3600.",
210+
category: "AWSLambdaCSharpGenerator",
211+
DiagnosticSeverity.Error,
212+
isEnabledByDefault: true);
213+
214+
public static readonly DiagnosticDescriptor AuthorizerPayloadVersionMismatch = new DiagnosticDescriptor(
215+
id: "AWSLambda0128",
216+
title: "Authorizer Payload Version Mismatch",
217+
messageFormat: "The authorizer '{0}' uses AuthorizerPayloadFormatVersion {1} but the endpoint uses HttpApiVersion {2}. This may cause unexpected behavior.",
218+
category: "AWSLambdaCSharpGenerator",
219+
DiagnosticSeverity.Warning,
220+
isEnabledByDefault: true);
221+
222+
public static readonly DiagnosticDescriptor MissingLambdaFunctionAttribute = new DiagnosticDescriptor(
223+
id: "AWSLambda0129",
224+
title: "Missing LambdaFunction Attribute",
225+
messageFormat: "Method has [{0}] attribute but is missing the required [LambdaFunction] attribute. Add [LambdaFunction] to this method.",
226+
category: "AWSLambdaCSharpGenerator",
227+
DiagnosticSeverity.Error,
228+
isEnabledByDefault: true);
156229
}
157230
}

0 commit comments

Comments
 (0)