-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding WebPubSubService provisioning (#43027)
* Add WebPubSub provisioning * Add api * Resolve comments * Fix build failure * Fix tests
- Loading branch information
Showing
21 changed files
with
445 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Release History | ||
|
||
## 0.1.0-beta.1 (2024-05-10) | ||
|
||
### Features Added | ||
|
||
- Initial beta release of Azure.Provisioning.WebPubSub. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Azure Provisioning client library for .NET | ||
|
||
Azure.Provisioning.WebPubSub simplifies declarative resource provisioning in .NET for Azure Web PubSub. | ||
|
||
## Getting started | ||
|
||
### Install the package | ||
|
||
Install the client library for .NET with [NuGet](https://www.nuget.org/ ): | ||
|
||
```dotnetcli | ||
dotnet add package Azure.Provisioning.WebPubSub --prerelease | ||
``` | ||
|
||
### Prerequisites | ||
|
||
> You must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/). | ||
### Authenticate the Client | ||
|
||
## Key concepts | ||
|
||
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. | ||
|
||
## Examples | ||
|
||
Here is a simple example which creates a KeyVault. | ||
|
||
First create your Infrastructure class. | ||
|
||
```C# Snippet:SampleInfrastructure | ||
public class SampleInfrastructure : Infrastructure | ||
{ | ||
public SampleInfrastructure() : base(envName: "Sample", tenantId: Guid.Empty, subscriptionId: Guid.Empty, configuration: new Configuration { UseInteractiveMode = true }) | ||
{ | ||
} | ||
} | ||
``` | ||
|
||
Next add your resources into your infrastructure and then Build. | ||
|
||
```C# Snippet:KeyVaultOnly | ||
// Create a new infrastructure | ||
var infrastructure = new SampleInfrastructure(); | ||
|
||
// Add a new key vault | ||
var keyVault = infrastructure.AddKeyVault(); | ||
|
||
// You can call Build to convert the infrastructure into bicep files. | ||
infrastructure.Build(); | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues). | ||
- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags. | ||
|
||
## Next steps | ||
|
||
## Contributing | ||
|
||
For details on contributing to this repository, see the [contributing | ||
guide][cg]. | ||
|
||
This project welcomes contributions and suggestions. Most contributions | ||
require you to agree to a Contributor License Agreement (CLA) declaring | ||
that you have the right to, and actually do, grant us the rights to use | ||
your contribution. For details, visit <https://cla.microsoft.com>. | ||
|
||
When you submit a pull request, a CLA-bot will automatically determine | ||
whether you need to provide a CLA and decorate the PR appropriately | ||
(for example, label, comment). Follow the instructions provided by the | ||
bot. You'll only need to do this action once across all repositories | ||
using our CLA. | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For | ||
more information, see the [Code of Conduct FAQ][coc_faq] or contact | ||
<opencode@microsoft.com> with any other questions or comments. | ||
|
||
<!-- LINKS --> | ||
[cg]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/CONTRIBUTING.md | ||
[coc]: https://opensource.microsoft.com/codeofconduct/ | ||
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ | ||
|
15 changes: 15 additions & 0 deletions
15
...visioning/Azure.Provisioning.WebPubSub/api/Azure.Provisioning.WebPubSub.netstandard2.0.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Azure.Provisioning.WebPubSub | ||
{ | ||
public partial class WebPubSubHub : Azure.Provisioning.Resource<Azure.ResourceManager.WebPubSub.WebPubSubHubData> | ||
{ | ||
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)) { } | ||
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } | ||
public static Azure.Provisioning.WebPubSub.WebPubSubHub FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.WebPubSub.WebPubSubService? parent = null) { throw null; } | ||
} | ||
public partial class WebPubSubService : Azure.Provisioning.Resource<Azure.ResourceManager.WebPubSub.WebPubSubData> | ||
{ | ||
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)) { } | ||
public static Azure.Provisioning.WebPubSub.WebPubSubService FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) { throw null; } | ||
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"AssetsRepo": "Azure/azure-sdk-assets", | ||
"AssetsRepoPrefixPath": "net", | ||
"TagPrefix": "net/provisioning/Azure.Provisioning.WebPubSub", | ||
"Tag": "net/provisioning/Azure.Provisioning.WebPubSub_ee1c01a8d9" | ||
} |
14 changes: 14 additions & 0 deletions
14
sdk/provisioning/Azure.Provisioning.WebPubSub/src/Azure.Provisioning.WebPubSub.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Description>Azure.Provisioning.WebPubSub simplifies declarative resource provisioning in .NET for Azure Web PubSub.</Description> | ||
<Version>0.1.0-beta.1</Version> | ||
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks> | ||
<NoWarn>$(NoWarn);AZC0001</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.ResourceManager.WebPubSub" /> | ||
</ItemGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
sdk/provisioning/Azure.Provisioning.WebPubSub/src/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
[assembly: Experimental("AZPROVISION001")] |
66 changes: 66 additions & 0 deletions
66
sdk/provisioning/Azure.Provisioning.WebPubSub/src/WebPubSubHub.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Azure.ResourceManager.WebPubSub; | ||
using Azure.ResourceManager.WebPubSub.Models; | ||
|
||
namespace Azure.Provisioning.WebPubSub | ||
{ | ||
/// <summary> | ||
/// Represents a hub setting for WebPubSub. | ||
/// </summary> | ||
public class WebPubSubHub : Resource<WebPubSubHubData> | ||
{ | ||
// https://learn.microsoft.com/azure/templates/microsoft.signalrservice/2023-02-01/webPubSub/hubs?pivots=deployment-language-bicep | ||
private const string ResourceTypeName = "Microsoft.SignalRService/webPubSub/hubs"; | ||
|
||
private static WebPubSubHubData Empty(string name) => ArmWebPubSubModelFactory.WebPubSubHubData(); | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="WebPubSubHub"/> class. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="properties">The properties of the hub settings.</param> | ||
/// <param name="parent">The parent.</param> | ||
/// <param name="name">The name.</param> | ||
/// <param name="version">The version.</param> | ||
public WebPubSubHub(IConstruct scope, | ||
WebPubSubHubProperties properties, | ||
WebPubSubService? parent = null, | ||
string name = "hub", | ||
string version = WebPubSubService.DefaultVersion) | ||
: this(scope, parent, name, version, false, (name) => ArmWebPubSubModelFactory.WebPubSubHubData( | ||
name: name, | ||
properties: properties)) | ||
{ | ||
} | ||
|
||
private WebPubSubHub( | ||
IConstruct scope, | ||
WebPubSubService? parent, | ||
string name, | ||
string version = WebPubSubService.DefaultVersion, | ||
bool isExisting = false, | ||
Func<string, WebPubSubHubData>? creator = null) | ||
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="WebPubSubHub"/> class referencing an existing instance. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="name">The resource name.</param> | ||
/// <param name="parent">The resource group.</param> | ||
/// <returns>The WebPubSub service instance.</returns> | ||
public static WebPubSubHub FromExisting(IConstruct scope, string name, WebPubSubService? parent = null) | ||
=> new WebPubSubHub(scope, parent: parent, name: name, isExisting: true); | ||
|
||
/// <inheritdoc/> | ||
protected override Resource? FindParentInScope(IConstruct scope) | ||
{ | ||
return scope.GetSingleResource<WebPubSubService>() ?? new WebPubSubService(scope); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
sdk/provisioning/Azure.Provisioning.WebPubSub/src/WebPubSubService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Azure.Core; | ||
using Azure.Provisioning.ResourceManager; | ||
using Azure.ResourceManager.WebPubSub; | ||
using Azure.ResourceManager.WebPubSub.Models; | ||
|
||
namespace Azure.Provisioning.WebPubSub | ||
{ | ||
/// <summary> | ||
/// Represents a WebPubSub. | ||
/// </summary> | ||
public class WebPubSubService : Resource<WebPubSubData> | ||
{ | ||
// https://learn.microsoft.com/azure/templates/microsoft.signalrservice/2023-02-01/webPubSub?pivots=deployment-language-bicep | ||
private const string ResourceTypeName = "Microsoft.SignalRService/webPubSub"; | ||
// https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/webpubsub/Azure.ResourceManager.WebPubSub/src/Generated/RestOperations/WebPubSubRestOperations.cs#L36 | ||
internal const string DefaultVersion = "2021-10-01"; | ||
|
||
private static WebPubSubData Empty(string name) => ArmWebPubSubModelFactory.WebPubSubData(); | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="WebPubSubService"/> class. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="sku">The SKU.</param> | ||
/// <param name="parent">The parent.</param> | ||
/// <param name="name">The name.</param> | ||
/// <param name="version">The version.</param> | ||
/// <param name="location">The location.</param> | ||
public WebPubSubService( | ||
IConstruct scope, | ||
BillingInfoSku? sku = default, | ||
ResourceGroup? parent = default, | ||
string name = "webpubsub", | ||
string version = DefaultVersion, | ||
AzureLocation? location = default) | ||
: this(scope, parent, name, version, false, (name) => ArmWebPubSubModelFactory.WebPubSubData( | ||
name: name, | ||
location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, | ||
sku: sku ?? new BillingInfoSku("Free_F1") { Capacity = 1 })) | ||
{ | ||
AssignProperty(data => data.Name, GetAzureName(scope, name)); | ||
} | ||
|
||
private WebPubSubService( | ||
IConstruct scope, | ||
ResourceGroup? parent, | ||
string name, | ||
string version = DefaultVersion, | ||
bool isExisting = false, | ||
Func<string, WebPubSubData>? creator = null) | ||
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="WebPubSubService"/> class referencing an existing instance. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="name">The resource name.</param> | ||
/// <param name="parent">The resource group.</param> | ||
/// <returns>The WebPubSub service instance.</returns> | ||
public static WebPubSubService FromExisting(IConstruct scope, string name, ResourceGroup? parent = null) | ||
=> new WebPubSubService(scope, parent: parent, name: name, isExisting: true); | ||
|
||
/// <inheritdoc/> | ||
protected override string GetAzureName(IConstruct scope, string resourceName) => GetGloballyUniqueName(resourceName); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...provisioning/Azure.Provisioning.WebPubSub/tests/Azure.Provisioning.WebPubSub.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj" /> | ||
<ProjectReference Include="..\src\Azure.Provisioning.WebPubSub.csproj" /> | ||
<ProjectReference Include="..\..\Azure.Provisioning.Resources\src\Azure.Provisioning.Resources.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
15 changes: 15 additions & 0 deletions
15
...g/Azure.Provisioning.WebPubSub/tests/Infrastructure/ExistingWebPubSubResources/main.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
targetScope = 'subscription' | ||
|
||
|
||
resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { | ||
name: 'rg-TEST' | ||
location: 'westus' | ||
tags: { | ||
'azd-env-name': 'TEST' | ||
} | ||
} | ||
|
||
module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { | ||
name: 'rg_TEST_module' | ||
scope: resourceGroup_I6QNkoPsb | ||
} |
4 changes: 4 additions & 0 deletions
4
...s/Infrastructure/ExistingWebPubSubResources/resources/rg_TEST_module/rg_TEST_module.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
resource webPubSubService_f0nsipxGj 'Microsoft.SignalRService/webPubSub@2021-10-01' existing = { | ||
name: 'existingWebPubSub' | ||
} |
40 changes: 40 additions & 0 deletions
40
sdk/provisioning/Azure.Provisioning.WebPubSub/tests/Infrastructure/WebPubSub/main.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
targetScope = 'resourceGroup' | ||
|
||
@description('') | ||
param location string = resourceGroup().location | ||
|
||
|
||
resource webPubSubService_EAdO6ICWi 'Microsoft.SignalRService/webPubSub@2021-10-01' = { | ||
name: toLower(take('webpubsub${uniqueString(resourceGroup().id)}', 24)) | ||
location: location | ||
sku: { | ||
name: 'Standard_S1' | ||
} | ||
properties: { | ||
} | ||
} | ||
|
||
resource roleAssignment_eQVZzvRPP 'Microsoft.Authorization/roleAssignments@2022-04-01' = { | ||
scope: webPubSubService_EAdO6ICWi | ||
name: guid(webPubSubService_EAdO6ICWi.id, '00000000-0000-0000-0000-000000000000', subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '12cf5a90-567b-43ae-8102-96cf46c7d9b4')) | ||
properties: { | ||
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '12cf5a90-567b-43ae-8102-96cf46c7d9b4') | ||
principalId: '00000000-0000-0000-0000-000000000000' | ||
principalType: 'ServicePrincipal' | ||
} | ||
} | ||
|
||
resource webPubSubHub_tKhq1vFqb 'Microsoft.SignalRService/webPubSub/hubs@2021-10-01' = { | ||
parent: webPubSubService_EAdO6ICWi | ||
name: 'hub' | ||
properties: { | ||
eventHandlers: [ | ||
{ | ||
urlTemplate: 'tunnel:///eventhandler' | ||
userEventPattern: '*' | ||
} | ||
] | ||
} | ||
} | ||
|
||
output hostName string = webPubSubService_EAdO6ICWi.properties.hostName |
38 changes: 38 additions & 0 deletions
38
...visioning/Azure.Provisioning.WebPubSub/tests/Infrastructure/WebPubSubResources/main.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
targetScope = 'resourceGroup' | ||
|
||
@description('') | ||
param location string = resourceGroup().location | ||
|
||
|
||
resource signalRService_TvD5y8AYq 'Microsoft.SignalRService/signalR@2022-02-01' = { | ||
name: toLower(take('signalr${uniqueString(resourceGroup().id)}', 24)) | ||
location: location | ||
sku: { | ||
name: 'Standard_S1' | ||
} | ||
properties: { | ||
features: [ | ||
{ | ||
flag: 'ServiceMode' | ||
value: 'Serverless' | ||
} | ||
] | ||
cors: { | ||
allowedOrigins: [ | ||
'*' | ||
] | ||
} | ||
} | ||
} | ||
|
||
resource roleAssignment_hFSNN5tl8 'Microsoft.Authorization/roleAssignments@2022-04-01' = { | ||
scope: signalRService_TvD5y8AYq | ||
name: guid(signalRService_TvD5y8AYq.id, '00000000-0000-0000-0000-000000000000', subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '420fcaa2-552c-430f-98ca-3264be4806c7')) | ||
properties: { | ||
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '420fcaa2-552c-430f-98ca-3264be4806c7') | ||
principalId: '00000000-0000-0000-0000-000000000000' | ||
principalType: 'ServicePrincipal' | ||
} | ||
} | ||
|
||
output hostName string = signalRService_TvD5y8AYq.properties.hostName |
Oops, something went wrong.