-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSDKResourceExtensions.cs
72 lines (62 loc) · 2.39 KB
/
SDKResourceExtensions.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
using Amazon;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.AWS;
namespace Aspire.Hosting;
/// <summary>
/// Extension methods for configuring the AWS SDK for .NET
/// </summary>
public static class SDKResourceExtensions
{
/// <summary>
/// Add a configuration for resolving region and credentials for the AWS SDK for .NET.
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> instance.</param>
/// <returns></returns>
public static IAWSSDKConfig AddAWSSDKConfig(this IDistributedApplicationBuilder builder)
{
var config = new AWSSDKConfig();
return config;
}
/// <summary>
/// Assign the AWS credential profile to the IAWSSDKConfigResource.
/// </summary>
/// <param name="config">An <see cref="IAWSSDKConfig"/> instance.</param>
/// <param name="profile">The name of the AWS credential profile.</param>
/// <returns></returns>
public static IAWSSDKConfig WithProfile(this IAWSSDKConfig config, string profile)
{
config.Profile = profile;
return config;
}
/// <summary>
/// Assign the region for the IAWSSDKConfigResource.
/// </summary>
/// <param name="config">An <see cref="IAWSSDKConfig"/> instance.</param>
/// <param name="region">The AWS region.</param>
public static IAWSSDKConfig WithRegion(this IAWSSDKConfig config, RegionEndpoint region)
{
config.Region = region;
return config;
}
/// <summary>
/// Add a reference to an AWS SDK configuration to the resource.
/// </summary>
/// <param name="builder">An <see cref="IResourceBuilder{T}"/> for <see cref="IResourceWithEnvironment"/></param>
/// <param name="awsSdkConfig">The AWS SDK configuration</param>
/// <returns></returns>
public static IResourceBuilder<TDestination> WithReference<TDestination>(this IResourceBuilder<TDestination> builder, IAWSSDKConfig awsSdkConfig)
where TDestination : IResourceWithEnvironment
{
builder.WithAnnotation(new SDKResourceAnnotation(awsSdkConfig));
builder.WithEnvironment(context =>
{
if (context.ExecutionContext.IsPublishMode)
{
return;
}
SdkUtilities.ApplySDKConfig(context, awsSdkConfig, true);
});
return builder;
}
}