-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathALBApiAttributeBuilder.cs
More file actions
65 lines (60 loc) · 2.7 KB
/
ALBApiAttributeBuilder.cs
File metadata and controls
65 lines (60 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Amazon.Lambda.Annotations.ALB;
using Microsoft.CodeAnalysis;
using System;
using System.Linq;
namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
{
/// <summary>
/// Builder for <see cref="ALBApiAttribute"/>.
/// </summary>
public class ALBApiAttributeBuilder
{
public static ALBApiAttribute Build(AttributeData att)
{
if (att.ConstructorArguments.Length != 3)
{
throw new NotSupportedException($"{TypeFullNames.ALBApiAttribute} must have constructor with 3 arguments.");
}
var listenerArn = att.ConstructorArguments[0].Value as string;
var pathPattern = att.ConstructorArguments[1].Value as string;
var priority = (int)att.ConstructorArguments[2].Value;
var data = new ALBApiAttribute(listenerArn, pathPattern, priority);
foreach (var pair in att.NamedArguments)
{
if (pair.Key == nameof(data.MultiValueHeaders) && pair.Value.Value is bool multiValueHeaders)
{
data.MultiValueHeaders = multiValueHeaders;
}
else if (pair.Key == nameof(data.HostHeader) && pair.Value.Value is string hostHeader)
{
data.HostHeader = hostHeader;
}
else if (pair.Key == nameof(data.HttpMethod) && pair.Value.Value is string httpMethod)
{
data.HttpMethod = httpMethod;
}
else if (pair.Key == nameof(data.ResourceName) && pair.Value.Value is string resourceName)
{
data.ResourceName = resourceName;
}
else if (pair.Key == nameof(data.HttpHeaderConditionName) && pair.Value.Value is string httpHeaderConditionName)
{
data.HttpHeaderConditionName = httpHeaderConditionName;
}
else if (pair.Key == nameof(data.HttpHeaderConditionValues) && !pair.Value.IsNull)
{
data.HttpHeaderConditionValues = pair.Value.Values.Select(v => v.Value as string).ToArray();
}
else if (pair.Key == nameof(data.QueryStringConditions) && !pair.Value.IsNull)
{
data.QueryStringConditions = pair.Value.Values.Select(v => v.Value as string).ToArray();
}
else if (pair.Key == nameof(data.SourceIpConditions) && !pair.Value.IsNull)
{
data.SourceIpConditions = pair.Value.Values.Select(v => v.Value as string).ToArray();
}
}
return data;
}
}
}