- Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSDKResourceExtensions.cs
84 lines (72 loc) · 2.84 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
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
usingAmazon;
usingAspire.Hosting.ApplicationModel;
usingAspire.Hosting.AWS;
namespaceAspire.Hosting;
/// <summary>
/// Extension methods for configuring the AWS SDK for .NET
/// </summary>
publicstaticclassSDKResourceExtensions
{
/// <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>
publicstaticIAWSSDKConfigAddAWSSDKConfig(thisIDistributedApplicationBuilderbuilder)
{
varconfig=newAWSSDKConfig();
returnconfig;
}
/// <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>
publicstaticIAWSSDKConfigWithProfile(thisIAWSSDKConfigconfig,stringprofile)
{
config.Profile=profile;
returnconfig;
}
/// <summary>
/// Assign the region for the IAWSSDKConfigResource.
/// </summary>
/// <param name="config">An <see cref="IAWSSDKConfig"/> instance.</param>
/// <param name="region">The AWS region.</param>
publicstaticIAWSSDKConfigWithRegion(thisIAWSSDKConfigconfig,RegionEndpointregion)
{
config.Region=region;
returnconfig;
}
/// <summary>
/// Set validation preference for profile in sdk.
/// </summary>
/// <param name="config">An <see cref="IAWSSDKConfig"/> instance.</param>
/// <param name="sdkValidationEnabled">option for toggle sdk validation</param>
publicstaticIAWSSDKConfigWithSdkValidation(thisIAWSSDKConfigconfig,boolsdkValidationEnabled)
{
config.SDKValidationEnabled=sdkValidationEnabled;
returnconfig;
}
/// <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>
publicstaticIResourceBuilder<TDestination>WithReference<TDestination>(thisIResourceBuilder<TDestination>builder,IAWSSDKConfigawsSdkConfig)
whereTDestination:IResourceWithEnvironment
{
builder.WithAnnotation(newSDKResourceAnnotation(awsSdkConfig));
builder.WithEnvironment(context =>
{
if(context.ExecutionContext.IsPublishMode)
{
return;
}
SdkUtilities.ApplySDKConfig(context,awsSdkConfig,true);
});
returnbuilder;
}
}