-
Notifications
You must be signed in to change notification settings - Fork 1
/
Extensions.cs
49 lines (38 loc) · 2.03 KB
/
Extensions.cs
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
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.Lambda;
using System.Collections.Generic;
using System.Linq;
using kms = Amazon.CDK.AWS.KMS;
namespace Olive.Aws.Cdk
{
public static class Extensions
{
public static ArnFormatter GetArnFormatter(this IResource resource) => new(resource.Stack);
public static string GetArn(this kms.IKey key) => key.GetArnFormatter().CreateArn("kms", "key/" + key.KeyId);
public static string GetArn(this Amazon.CDK.AWS.EFS.FileSystem @this) =>
@this.GetArnFormatter().CreateArn("elasticfilesystem", "filesystem/" + @this.FileSystemId);
internal static string ToAwsResourceName(this string name) => name.ToLower();
internal static Duration Seconds(this int @this) => Duration.Seconds(@this);
internal static Duration Seconds(this double @this) => Duration.Seconds(@this);
public static Function AddApplicationConfig(this Function @this, string key, string value) =>
@this.AddEnvironment("CONFIG__" + key.Replace(":", "__"), value);
internal static SubnetSelection ToSubnetSelection(this IEnumerable<ISubnet> @this) => new() { Subnets = @this.ToArray() };
internal static ISubnet[] GetLambdaSubnets(this IVpc @this) => @this.GetSubnets("Lambda");
internal static ISubnet[] GetDatabaseSubnets(this IVpc @this) => @this.GetSubnets("Database");
internal static ISubnet[] GetSubnets(this IVpc @this, string groupName)
=> @this.SelectSubnets(new SubnetSelection
{
SubnetGroupName = "Database"
}).Subnets;
internal static void GrantWrite(this Amazon.CDK.AWS.EFS.FileSystem @this, Amazon.CDK.AWS.IAM.Role role)
{
role.AddToPolicy(PolicyStatementFactory.CreateAllow(actions: new[]
{
Action.ElasticFileSystem.ClientWrite,
Action.ElasticFileSystem.ClientMount,
Action.ElasticFileSystem.DescribeMountTargets
}, resourceArns: @this.GetArn()));
}
}
}