Skip to content

Commit 9073e07

Browse files
authored
Mega CDK polish PR. (#2875)
1 parent a57c102 commit 9073e07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1068
-1868
lines changed

playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
builder.AddAzureProvisioning();
77

8-
var openai = builder.AddAzureOpenAIConstruct("openai")
8+
var openai = builder.AddAzureOpenAI("openai")
99
.AddDeployment(new("gpt-35-turbo", "gpt-35-turbo", "0613"));
1010

1111
builder.AddProject<Projects.OpenAIEndToEnd_WebStory>("webstory")

playground/cdk/CdkSample.AppHost/CdkSample.AppHost.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<Nullable>enable</Nullable>
88
<IsAspireHost>true</IsAspireHost>
99
<UserSecretsId>44b9bf37-1892-4852-8b5f-153e3ac5d24c</UserSecretsId>
10+
<EnablePreviewFeatures>True</EnablePreviewFeatures>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

playground/cdk/CdkSample.AppHost/Program.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,64 @@
66
var builder = DistributedApplication.CreateBuilder(args);
77
builder.AddAzureProvisioning();
88

9-
var cosmosdb = builder.AddAzureCosmosDBConstruct("cosmos").AddDatabase("cosmosdb");
9+
var cosmosdb = builder.AddAzureCosmosDB("cosmos").AddDatabase("cosmosdb");
1010

1111
var sku = builder.AddParameter("storagesku");
1212
var locationOverride = builder.AddParameter("locationOverride");
13-
var storage = builder.AddAzureConstructStorage("storage", (_, account) =>
13+
var storage = builder.AddAzureStorage("storage", (_, _, account) =>
1414
{
1515
account.AssignProperty(sa => sa.Sku.Name, sku);
1616
account.AssignProperty(sa => sa.Location, locationOverride);
1717
});
1818

1919
var blobs = storage.AddBlobs("blobs");
2020

21-
var sqldb = builder.AddSqlServer("sql").AsAzureSqlDatabaseConstruct().AddDatabase("sqldb");
21+
var sqldb = builder.AddSqlServer("sql").AsAzureSqlDatabase().AddDatabase("sqldb");
2222

2323
var signaturesecret = builder.AddParameter("signaturesecret");
24-
var keyvault = builder.AddAzureKeyVaultConstruct("mykv", (construct, keyVault) =>
24+
var keyvault = builder.AddAzureKeyVault("mykv", (_, construct, keyVault) =>
2525
{
2626
var secret = new KeyVaultSecret(construct, name: "mysecret");
2727
secret.AssignProperty(x => x.Properties.Value, signaturesecret);
2828
});
2929

30-
var cache = builder.AddRedis("cache").AsAzureRedisConstruct();
30+
var cache = builder.AddRedis("cache").AsAzureRedis();
3131

3232
var pgsqlAdministratorLogin = builder.AddParameter("pgsqlAdministratorLogin");
3333
var pgsqlAdministratorLoginPassword = builder.AddParameter("pgsqlAdministratorLoginPassword", secret: true);
3434
var pgsqldb = builder.AddPostgres("pgsql")
35-
.AsAzurePostgresFlexibleServerConstruct(pgsqlAdministratorLogin, pgsqlAdministratorLoginPassword)
35+
.AsAzurePostgresFlexibleServer(pgsqlAdministratorLogin, pgsqlAdministratorLoginPassword)
3636
.AddDatabase("pgsqldb");
3737

38-
var pgsql2 = builder.AddPostgres("pgsql2").AsAzurePostgresFlexibleServerConstruct();
38+
var pgsql2 = builder.AddPostgres("pgsql2").AsAzurePostgresFlexibleServer();
3939

40-
var sb = builder.AddAzureServiceBusConstruct("servicebus")
40+
var sb = builder.AddAzureServiceBus("servicebus")
4141
.AddQueue("queue1",
42-
(construct, queue) =>
42+
(_, construct, queue) =>
4343
{
4444
queue.Properties.MaxDeliveryCount = 5;
4545
queue.Properties.LockDuration = TimeSpan.FromMinutes(5);
4646
})
4747
.AddTopic("topic1",
48-
(construct, topic) =>
48+
(_, construct, topic) =>
4949
{
5050
topic.Properties.EnablePartitioning = true;
5151
})
5252
.AddTopic("topic2")
5353
.AddSubscription("topic1", "subscription1",
54-
(construct, subscription) =>
54+
(_, construct, subscription) =>
5555
{
5656
subscription.Properties.LockDuration = TimeSpan.FromMinutes(5);
5757
subscription.Properties.RequiresSession = true;
5858
})
5959
.AddSubscription("topic1", "subscription2")
6060
.AddTopic("topic3", new[] { "sub1", "sub2" });
6161

62-
var appConfig = builder.AddAzureAppConfigurationConstruct("appConfig");
62+
var appConfig = builder.AddAzureAppConfiguration("appConfig");
6363

64-
var search = builder.AddAzureConstructSearch("search");
64+
var search = builder.AddAzureSearch("search");
6565

66-
var signalr = builder.AddAzureSignalRConstruct("signalr");
66+
var signalr = builder.AddAzureSignalR("signalr");
6767

6868
builder.AddProject<Projects.CdkSample_ApiService>("api")
6969
.WithReference(signalr)

src/Aspire.Hosting.Azure/Aspire.Hosting.Azure.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<PackageTags>aspire hosting azure</PackageTags>
77
<Description>Azure resource types for .NET Aspire.</Description>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9+
<GenerateRequiresPreviewFeaturesAttribute>False</GenerateRequiresPreviewFeaturesAttribute>
910
</PropertyGroup>
1011

1112
<ItemGroup>

src/Aspire.Hosting.Azure/AzureAppConfigurationResource.cs

+1-21
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,12 @@
55

66
namespace Aspire.Hosting.Azure;
77

8-
/// <summary>
9-
/// A resource that represents Azure App Configuration.
10-
/// </summary>
11-
/// <param name="name">The name of the resource.</param>
12-
public class AzureAppConfigurationResource(string name) :
13-
AzureBicepResource(name, templateResourceName: "Aspire.Hosting.Azure.Bicep.appconfig.bicep"),
14-
IResourceWithConnectionString
15-
{
16-
/// <summary>
17-
/// Gets the appConfigEndpoint output reference for the Azure App Configuration resource.
18-
/// </summary>
19-
public BicepOutputReference Endpoint => new("appConfigEndpoint", this);
20-
21-
/// <summary>
22-
/// Gets the connection string template for the manifest for the Azure App Configuration resource.
23-
/// </summary>
24-
public ReferenceExpression ConnectionStringExpression =>
25-
ReferenceExpression.Create($"{Endpoint}");
26-
}
27-
288
/// <summary>
299
/// A resource that represents Azure App Configuration.
3010
/// </summary>
3111
/// <param name="name">The name of the resource.</param>
3212
/// <param name="configureConstruct"></param>
33-
public class AzureAppConfigurationConstructResource(string name, Action<ResourceModuleConstruct> configureConstruct) :
13+
public class AzureAppConfigurationResource(string name, Action<ResourceModuleConstruct> configureConstruct) :
3414
AzureConstructResource(name, configureConstruct),
3515
IResourceWithConnectionString
3616
{

src/Aspire.Hosting.Azure/AzureBlobStorageResource.cs

-31
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,3 @@ internal void WriteToManifest(ManifestPublishingContext context)
3636
context.WriteConnectionString(this);
3737
}
3838
}
39-
40-
/// <summary>
41-
/// A resource that represents an Azure Blob Storage account.
42-
/// </summary>
43-
/// <param name="name">The name of the resource.</param>
44-
/// <param name="storage">The <see cref="AzureStorageResource"/> that the resource is stored in.</param>
45-
public class AzureBlobStorageConstructResource(string name, AzureStorageConstructResource storage) : Resource(name),
46-
IResourceWithConnectionString,
47-
IResourceWithParent<AzureStorageConstructResource>
48-
{
49-
/// <summary>
50-
/// Gets the parent AzureStorageResource of this AzureBlobStorageResource.
51-
/// </summary>
52-
public AzureStorageConstructResource Parent => storage;
53-
54-
/// <summary>
55-
/// Gets the connection string template for the manifest for the Azure Blob Storage resource.
56-
/// </summary>
57-
public ReferenceExpression ConnectionStringExpression =>
58-
Parent.GetBlobConnectionString();
59-
60-
/// <summary>
61-
/// Called by manifest publisher to write manifest resource.
62-
/// </summary>
63-
/// <param name="context">The context for the manifest publishing operation.</param>
64-
internal void WriteToManifest(ManifestPublishingContext context)
65-
{
66-
context.Writer.WriteString("type", "value.v0");
67-
context.WriteConnectionString(this);
68-
}
69-
}

src/Aspire.Hosting.Azure/AzureCosmosDBResource.cs

+9-71
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Runtime.Versioning;
45
using Aspire.Hosting.ApplicationModel;
56
using Aspire.Hosting.Azure;
67
using Aspire.Hosting.Azure.Cosmos;
@@ -14,38 +15,7 @@ namespace Aspire.Hosting;
1415
/// <summary>
1516
/// A resource that represents an Azure Cosmos DB.
1617
/// </summary>
17-
public class AzureCosmosDBResource(string name) :
18-
AzureBicepResource(name, templateResourceName: "Aspire.Hosting.Azure.Bicep.cosmosdb.bicep"),
19-
IResourceWithConnectionString,
20-
IResourceWithEndpoints
21-
{
22-
internal List<string> Databases { get; } = [];
23-
24-
internal EndpointReference EmulatorEndpoint => new(this, "emulator");
25-
26-
/// <summary>
27-
/// Gets the "connectionString" reference from the secret outputs of the Azure Cosmos DB resource.
28-
/// </summary>
29-
public BicepSecretOutputReference ConnectionString => new("connectionString", this);
30-
31-
/// <summary>
32-
/// Gets a value indicating whether the Azure Cosmos DB resource is running in the local emulator.
33-
/// </summary>
34-
public bool IsEmulator => this.IsContainer();
35-
36-
/// <summary>
37-
/// Gets the connection string template for the manifest for the Azure Cosmos DB resource.
38-
/// </summary>
39-
public ReferenceExpression ConnectionStringExpression =>
40-
IsEmulator
41-
? ReferenceExpression.Create($"{AzureCosmosDBEmulatorConnectionString.Create(EmulatorEndpoint.Port)}")
42-
: ReferenceExpression.Create($"{ConnectionString}");
43-
}
44-
45-
/// <summary>
46-
/// A resource that represents an Azure Cosmos DB.
47-
/// </summary>
48-
public class AzureCosmosDBConstructResource(string name, Action<ResourceModuleConstruct> configureConstruct) :
18+
public class AzureCosmosDBResource(string name, Action<ResourceModuleConstruct> configureConstruct) :
4919
AzureConstructResource(name, configureConstruct),
5020
IResourceWithConnectionString,
5121
IResourceWithEndpoints
@@ -86,22 +56,19 @@ public static class AzureCosmosExtensions
8656
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
8757
public static IResourceBuilder<AzureCosmosDBResource> AddAzureCosmosDB(this IDistributedApplicationBuilder builder, string name)
8858
{
89-
var resource = new AzureCosmosDBResource(name);
90-
return builder.AddResource(resource)
91-
.WithParameter("databaseAccountName", resource.CreateBicepResourceName())
92-
.WithParameter("databases", resource.Databases)
93-
.WithParameter(AzureBicepResource.KnownParameters.KeyVaultName)
94-
.WithManifestPublishingCallback(resource.WriteToManifest);
59+
#pragma warning disable CA2252 // This API requires opting into preview features
60+
return builder.AddAzureCosmosDB(name, static (_, _, _, _) => { });
61+
#pragma warning restore CA2252 // This API requires opting into preview features
9562
}
96-
9763
/// <summary>
9864
/// Adds an Azure Cosmos DB connection to the application model.
9965
/// </summary>
10066
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param>
10167
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param>
10268
/// <param name="configureResource"></param>
10369
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
104-
public static IResourceBuilder<AzureCosmosDBConstructResource> AddAzureCosmosDBConstruct(this IDistributedApplicationBuilder builder, string name, Action<IResourceBuilder<AzureCosmosDBConstructResource>, ResourceModuleConstruct, CosmosDBAccount, IEnumerable<CosmosDBSqlDatabase>>? configureResource = null)
70+
[RequiresPreviewFeatures]
71+
public static IResourceBuilder<AzureCosmosDBResource> AddAzureCosmosDB(this IDistributedApplicationBuilder builder, string name, Action<IResourceBuilder<AzureCosmosDBResource>, ResourceModuleConstruct, CosmosDBAccount, IEnumerable<CosmosDBSqlDatabase>>? configureResource = null)
10572
{
10673
var configureConstruct = (ResourceModuleConstruct construct) =>
10774
{
@@ -116,7 +83,7 @@ public static IResourceBuilder<AzureCosmosDBConstructResource> AddAzureCosmosDBC
11683
var keyVaultNameParameter = new Parameter("keyVaultName");
11784
construct.AddParameter(keyVaultNameParameter);
11885

119-
var azureResource = (AzureCosmosDBConstructResource)construct.Resource;
86+
var azureResource = (AzureCosmosDBResource)construct.Resource;
12087
var azureResourceBuilder = builder.CreateResourceBuilder(azureResource);
12188
List<CosmosDBSqlDatabase> cosmosSqlDatabases = new List<CosmosDBSqlDatabase>();
12289
foreach (var databaseName in azureResource.Databases)
@@ -134,7 +101,7 @@ public static IResourceBuilder<AzureCosmosDBConstructResource> AddAzureCosmosDBC
134101
}
135102
};
136103

137-
var resource = new AzureCosmosDBConstructResource(name, configureConstruct);
104+
var resource = new AzureCosmosDBResource(name, configureConstruct);
138105
return builder.AddResource(resource)
139106
.WithParameter(AzureBicepResource.KnownParameters.KeyVaultName)
140107
.WithManifestPublishingCallback(resource.WriteToManifest);
@@ -166,23 +133,6 @@ public static IResourceBuilder<AzureCosmosDBResource> RunAsEmulator(this IResour
166133
return builder;
167134
}
168135

169-
/// <summary>
170-
/// Configures an Azure Cosmos DB resource to be emulated using the Azure Cosmos DB emulator with the NoSQL API. This resource requires an <see cref="AzureCosmosDBResource"/> to be added to the application model.
171-
/// For more information on the Azure Cosmos DB emulator, see <a href="https://learn.microsoft.com/azure/cosmos-db/emulator#authentication"></a>
172-
/// </summary>
173-
/// <param name="builder">The Azure Cosmos DB resource builder.</param>
174-
/// <param name="configureContainer">Callback that exposes underlying container used for emulation to allow for customization.</param>
175-
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
176-
/// <remarks>
177-
/// When using the Azure Cosmos DB emulator, the container requires a TLS/SSL certificate.
178-
/// For more information, see <a href="https://learn.microsoft.com/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux#export-the-emulators-tlsssl-certificate"></a>
179-
/// </remarks>
180-
[Obsolete("Renamed to RunAsEmulator. Will be removed in next preview")]
181-
public static IResourceBuilder<AzureCosmosDBResource> UseEmulator(this IResourceBuilder<AzureCosmosDBResource> builder, Action<IResourceBuilder<AzureCosmosDBEmulatorResource>>? configureContainer = null)
182-
{
183-
return builder.RunAsEmulator(configureContainer);
184-
}
185-
186136
/// <summary>
187137
/// Configures the gateway port for the Azure Cosmos DB emulator.
188138
/// </summary>
@@ -208,18 +158,6 @@ public static IResourceBuilder<AzureCosmosDBResource> AddDatabase(this IResource
208158
builder.Resource.Databases.Add(databaseName);
209159
return builder;
210160
}
211-
212-
/// <summary>
213-
/// Adds a database to the associated Cosmos DB account resource.
214-
/// </summary>
215-
/// <param name="builder">AzureCosmosDB resource builder.</param>
216-
/// <param name="databaseName">Name of database.</param>
217-
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
218-
public static IResourceBuilder<AzureCosmosDBConstructResource> AddDatabase(this IResourceBuilder<AzureCosmosDBConstructResource> builder, string databaseName)
219-
{
220-
builder.Resource.Databases.Add(databaseName);
221-
return builder;
222-
}
223161
}
224162

225163
file static class AzureCosmosDBEmulatorConnectionString

src/Aspire.Hosting.Azure/AzureKeyVaultResource.cs

+1-21
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,12 @@
55

66
namespace Aspire.Hosting.Azure;
77

8-
/// <summary>
9-
/// A resource that represents an Azure Key Vault.
10-
/// </summary>
11-
/// <param name="name">The name of the resource.</param>
12-
public class AzureKeyVaultResource(string name) :
13-
AzureBicepResource(name, templateResourceName: "Aspire.Hosting.Azure.Bicep.keyvault.bicep"),
14-
IResourceWithConnectionString
15-
{
16-
/// <summary>
17-
/// Gets the "vaultUri" output reference for the Azure Key Vault resource.
18-
/// </summary>
19-
public BicepOutputReference VaultUri => new("vaultUri", this);
20-
21-
/// <summary>
22-
/// Gets the connection string template for the manifest for the Azure Key Vault resource.
23-
/// </summary>
24-
public ReferenceExpression ConnectionStringExpression =>
25-
ReferenceExpression.Create($"{VaultUri}");
26-
}
27-
288
/// <summary>
299
/// A resource that represents an Azure Key Vault.
3010
/// </summary>
3111
/// <param name="name">The name of the resource.</param>
3212
/// <param name="configureConstruct"></param>
33-
public class AzureKeyVaultConstructResource(string name, Action<ResourceModuleConstruct> configureConstruct) : AzureConstructResource(name, configureConstruct), IResourceWithConnectionString
13+
public class AzureKeyVaultResource(string name, Action<ResourceModuleConstruct> configureConstruct) : AzureConstructResource(name, configureConstruct), IResourceWithConnectionString
3414
{
3515
/// <summary>
3616
/// Gets the "vaultUri" output reference for the Azure Key Vault resource.

src/Aspire.Hosting.Azure/AzureOpenAIResource.cs

+1-35
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,12 @@
44

55
namespace Aspire.Hosting.ApplicationModel;
66

7-
/// <summary>
8-
/// Represents an Azure OpenAI resource.
9-
/// </summary>
10-
/// <param name="name">The name of the resource.</param>
11-
public class AzureOpenAIResource(string name) :
12-
AzureBicepResource(name, templateResourceName: "Aspire.Hosting.Azure.Bicep.openai.bicep"),
13-
IResourceWithConnectionString
14-
{
15-
private readonly List<AzureOpenAIDeployment> _deployments = [];
16-
17-
/// <summary>
18-
/// Gets the "connectionString" output reference from the Azure OpenAI resource.
19-
/// </summary>
20-
public BicepOutputReference ConnectionString => new("connectionString", this);
21-
22-
/// <summary>
23-
/// Gets the connection string template for the manifest for the resource.
24-
/// </summary>
25-
public ReferenceExpression ConnectionStringExpression =>
26-
ReferenceExpression.Create($"{ConnectionString}");
27-
28-
/// <summary>
29-
/// Gets the list of deployments of the Azure OpenAI resource.
30-
/// </summary>
31-
public IReadOnlyList<AzureOpenAIDeployment> Deployments => _deployments;
32-
33-
internal void AddDeployment(AzureOpenAIDeployment deployment)
34-
{
35-
ArgumentNullException.ThrowIfNull(deployment);
36-
37-
_deployments.Add(deployment);
38-
}
39-
}
40-
417
/// <summary>
428
/// Represents an Azure OpenAI resource.
439
/// </summary>
4410
/// <param name="name">The name of the resource.</param>
4511
/// <param name="configureConstruct">Configures the underlying Azure resource using the CDK.</param>
46-
public class AzureOpenAIConstructResource(string name, Action<ResourceModuleConstruct> configureConstruct) :
12+
public class AzureOpenAIResource(string name, Action<ResourceModuleConstruct> configureConstruct) :
4713
AzureConstructResource(name, configureConstruct),
4814
IResourceWithConnectionString
4915
{

0 commit comments

Comments
 (0)