Skip to content

Commit 14f1ccd

Browse files
authored
Adding WebPubSubService provisioning (Azure#43027)
* Add WebPubSub provisioning * Add api * Resolve comments * Fix build failure * Fix tests
1 parent b3b6c8a commit 14f1ccd

21 files changed

+445
-1
lines changed

eng/Packages.Data.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
<PackageReference Update="Azure.ResourceManager.Redis" Version="1.3.1" />
145145
<PackageReference Update="Azure.ResourceManager.Resources" Version="1.7.1" />
146146
<PackageReference Update="Azure.ResourceManager.Search" Version="1.2.2" />
147-
<PackageReference Update="Azure.ResourceManager.ServiceBus" Version="1.0.1" />
147+
<PackageReference Update="Azure.ResourceManager.ServiceBus" Version="1.0.1" />
148+
<PackageReference Update="Azure.ResourceManager.WebPubSub" Version="1.2.0-beta.1" />
148149
<PackageReference Update="Azure.ResourceManager.SignalR" Version="1.1.1" />
149150
<PackageReference Update="Azure.ResourceManager.Sql" Version="1.2.1" />
150151
<PackageReference Update="Azure.ResourceManager.Storage" Version="1.2.1" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Release History
2+
3+
## 0.1.0-beta.1 (2024-05-10)
4+
5+
### Features Added
6+
7+
- Initial beta release of Azure.Provisioning.WebPubSub.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Azure Provisioning client library for .NET
2+
3+
Azure.Provisioning.WebPubSub simplifies declarative resource provisioning in .NET for Azure Web PubSub.
4+
5+
## Getting started
6+
7+
### Install the package
8+
9+
Install the client library for .NET with [NuGet](https://www.nuget.org/ ):
10+
11+
```dotnetcli
12+
dotnet add package Azure.Provisioning.WebPubSub --prerelease
13+
```
14+
15+
### Prerequisites
16+
17+
> You must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/).
18+
19+
### Authenticate the Client
20+
21+
## Key concepts
22+
23+
This library allows you to specify your infrastructure in a declarative style using dotnet. You can then use azd to deploy your infrastructure to Azure diretly without needing to write or maintain bicep or arm templates.
24+
25+
## Examples
26+
27+
Here is a simple example which creates a KeyVault.
28+
29+
First create your Infrastructure class.
30+
31+
```C# Snippet:SampleInfrastructure
32+
public class SampleInfrastructure : Infrastructure
33+
{
34+
public SampleInfrastructure() : base(envName: "Sample", tenantId: Guid.Empty, subscriptionId: Guid.Empty, configuration: new Configuration { UseInteractiveMode = true })
35+
{
36+
}
37+
}
38+
```
39+
40+
Next add your resources into your infrastructure and then Build.
41+
42+
```C# Snippet:KeyVaultOnly
43+
// Create a new infrastructure
44+
var infrastructure = new SampleInfrastructure();
45+
46+
// Add a new key vault
47+
var keyVault = infrastructure.AddKeyVault();
48+
49+
// You can call Build to convert the infrastructure into bicep files.
50+
infrastructure.Build();
51+
```
52+
53+
## Troubleshooting
54+
55+
- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues).
56+
- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags.
57+
58+
## Next steps
59+
60+
## Contributing
61+
62+
For details on contributing to this repository, see the [contributing
63+
guide][cg].
64+
65+
This project welcomes contributions and suggestions. Most contributions
66+
require you to agree to a Contributor License Agreement (CLA) declaring
67+
that you have the right to, and actually do, grant us the rights to use
68+
your contribution. For details, visit <https://cla.microsoft.com>.
69+
70+
When you submit a pull request, a CLA-bot will automatically determine
71+
whether you need to provide a CLA and decorate the PR appropriately
72+
(for example, label, comment). Follow the instructions provided by the
73+
bot. You'll only need to do this action once across all repositories
74+
using our CLA.
75+
76+
This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For
77+
more information, see the [Code of Conduct FAQ][coc_faq] or contact
78+
<[email protected]> with any other questions or comments.
79+
80+
<!-- LINKS -->
81+
[cg]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/CONTRIBUTING.md
82+
[coc]: https://opensource.microsoft.com/codeofconduct/
83+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
84+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Azure.Provisioning.WebPubSub
2+
{
3+
public partial class WebPubSubHub : Azure.Provisioning.Resource<Azure.ResourceManager.WebPubSub.WebPubSubHubData>
4+
{
5+
public WebPubSubHub(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.WebPubSub.Models.WebPubSubHubProperties properties, Azure.Provisioning.WebPubSub.WebPubSubService? parent = null, string name = "hub", string version = "2021-10-01") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func<string, Azure.ResourceManager.WebPubSub.WebPubSubHubData>), default(bool)) { }
6+
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
7+
public static Azure.Provisioning.WebPubSub.WebPubSubHub FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.WebPubSub.WebPubSubService? parent = null) { throw null; }
8+
}
9+
public partial class WebPubSubService : Azure.Provisioning.Resource<Azure.ResourceManager.WebPubSub.WebPubSubData>
10+
{
11+
public WebPubSubService(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.WebPubSub.Models.BillingInfoSku? sku = null, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "webpubsub", string version = "2021-10-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func<string, Azure.ResourceManager.WebPubSub.WebPubSubData>), default(bool)) { }
12+
public static Azure.Provisioning.WebPubSub.WebPubSubService FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) { throw null; }
13+
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
14+
}
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"AssetsRepo": "Azure/azure-sdk-assets",
3+
"AssetsRepoPrefixPath": "net",
4+
"TagPrefix": "net/provisioning/Azure.Provisioning.WebPubSub",
5+
"Tag": "net/provisioning/Azure.Provisioning.WebPubSub_ee1c01a8d9"
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>Azure.Provisioning.WebPubSub simplifies declarative resource provisioning in .NET for Azure Web PubSub.</Description>
5+
<Version>0.1.0-beta.1</Version>
6+
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
7+
<NoWarn>$(NoWarn);AZC0001</NoWarn>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Azure.ResourceManager.WebPubSub" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
[assembly: Experimental("AZPROVISION001")]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using Azure.ResourceManager.WebPubSub;
6+
using Azure.ResourceManager.WebPubSub.Models;
7+
8+
namespace Azure.Provisioning.WebPubSub
9+
{
10+
/// <summary>
11+
/// Represents a hub setting for WebPubSub.
12+
/// </summary>
13+
public class WebPubSubHub : Resource<WebPubSubHubData>
14+
{
15+
// https://learn.microsoft.com/azure/templates/microsoft.signalrservice/2023-02-01/webPubSub/hubs?pivots=deployment-language-bicep
16+
private const string ResourceTypeName = "Microsoft.SignalRService/webPubSub/hubs";
17+
18+
private static WebPubSubHubData Empty(string name) => ArmWebPubSubModelFactory.WebPubSubHubData();
19+
20+
/// <summary>
21+
/// Creates a new instance of the <see cref="WebPubSubHub"/> class.
22+
/// </summary>
23+
/// <param name="scope">The scope.</param>
24+
/// <param name="properties">The properties of the hub settings.</param>
25+
/// <param name="parent">The parent.</param>
26+
/// <param name="name">The name.</param>
27+
/// <param name="version">The version.</param>
28+
public WebPubSubHub(IConstruct scope,
29+
WebPubSubHubProperties properties,
30+
WebPubSubService? parent = null,
31+
string name = "hub",
32+
string version = WebPubSubService.DefaultVersion)
33+
: this(scope, parent, name, version, false, (name) => ArmWebPubSubModelFactory.WebPubSubHubData(
34+
name: name,
35+
properties: properties))
36+
{
37+
}
38+
39+
private WebPubSubHub(
40+
IConstruct scope,
41+
WebPubSubService? parent,
42+
string name,
43+
string version = WebPubSubService.DefaultVersion,
44+
bool isExisting = false,
45+
Func<string, WebPubSubHubData>? creator = null)
46+
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting)
47+
{
48+
}
49+
50+
/// <summary>
51+
/// Creates a new instance of the <see cref="WebPubSubHub"/> class referencing an existing instance.
52+
/// </summary>
53+
/// <param name="scope">The scope.</param>
54+
/// <param name="name">The resource name.</param>
55+
/// <param name="parent">The resource group.</param>
56+
/// <returns>The WebPubSub service instance.</returns>
57+
public static WebPubSubHub FromExisting(IConstruct scope, string name, WebPubSubService? parent = null)
58+
=> new WebPubSubHub(scope, parent: parent, name: name, isExisting: true);
59+
60+
/// <inheritdoc/>
61+
protected override Resource? FindParentInScope(IConstruct scope)
62+
{
63+
return scope.GetSingleResource<WebPubSubService>() ?? new WebPubSubService(scope);
64+
}
65+
}
66+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using Azure.Core;
6+
using Azure.Provisioning.ResourceManager;
7+
using Azure.ResourceManager.WebPubSub;
8+
using Azure.ResourceManager.WebPubSub.Models;
9+
10+
namespace Azure.Provisioning.WebPubSub
11+
{
12+
/// <summary>
13+
/// Represents a WebPubSub.
14+
/// </summary>
15+
public class WebPubSubService : Resource<WebPubSubData>
16+
{
17+
// https://learn.microsoft.com/azure/templates/microsoft.signalrservice/2023-02-01/webPubSub?pivots=deployment-language-bicep
18+
private const string ResourceTypeName = "Microsoft.SignalRService/webPubSub";
19+
// https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/webpubsub/Azure.ResourceManager.WebPubSub/src/Generated/RestOperations/WebPubSubRestOperations.cs#L36
20+
internal const string DefaultVersion = "2021-10-01";
21+
22+
private static WebPubSubData Empty(string name) => ArmWebPubSubModelFactory.WebPubSubData();
23+
24+
/// <summary>
25+
/// Creates a new instance of the <see cref="WebPubSubService"/> class.
26+
/// </summary>
27+
/// <param name="scope">The scope.</param>
28+
/// <param name="sku">The SKU.</param>
29+
/// <param name="parent">The parent.</param>
30+
/// <param name="name">The name.</param>
31+
/// <param name="version">The version.</param>
32+
/// <param name="location">The location.</param>
33+
public WebPubSubService(
34+
IConstruct scope,
35+
BillingInfoSku? sku = default,
36+
ResourceGroup? parent = default,
37+
string name = "webpubsub",
38+
string version = DefaultVersion,
39+
AzureLocation? location = default)
40+
: this(scope, parent, name, version, false, (name) => ArmWebPubSubModelFactory.WebPubSubData(
41+
name: name,
42+
location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS,
43+
sku: sku ?? new BillingInfoSku("Free_F1") { Capacity = 1 }))
44+
{
45+
AssignProperty(data => data.Name, GetAzureName(scope, name));
46+
}
47+
48+
private WebPubSubService(
49+
IConstruct scope,
50+
ResourceGroup? parent,
51+
string name,
52+
string version = DefaultVersion,
53+
bool isExisting = false,
54+
Func<string, WebPubSubData>? creator = null)
55+
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting)
56+
{
57+
}
58+
59+
/// <summary>
60+
/// Creates a new instance of the <see cref="WebPubSubService"/> class referencing an existing instance.
61+
/// </summary>
62+
/// <param name="scope">The scope.</param>
63+
/// <param name="name">The resource name.</param>
64+
/// <param name="parent">The resource group.</param>
65+
/// <returns>The WebPubSub service instance.</returns>
66+
public static WebPubSubService FromExisting(IConstruct scope, string name, ResourceGroup? parent = null)
67+
=> new WebPubSubService(scope, parent: parent, name: name, isExisting: true);
68+
69+
/// <inheritdoc/>
70+
protected override string GetAzureName(IConstruct scope, string resourceName) => GetGloballyUniqueName(resourceName);
71+
}
72+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj" />
5+
<ProjectReference Include="..\src\Azure.Provisioning.WebPubSub.csproj" />
6+
<ProjectReference Include="..\..\Azure.Provisioning.Resources\src\Azure.Provisioning.Resources.csproj" />
7+
</ItemGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)