Skip to content

Commit

Permalink
Add EventHubs resources (#42636)
Browse files Browse the repository at this point in the history
* Add EventHubs resources

* rename

* Add test cases
  • Loading branch information
JoshLove-msft authored Mar 12, 2024
1 parent d61f695 commit 4266e1f
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 1 deletion.
1 change: 1 addition & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<PackageReference Update="Azure.ResourceManager.Authorization" Version="1.2.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.CognitiveServices" Version="1.4.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.CosmosDB" Version="1.4.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.EventHubs" Version="1.1.0-alpha.20240311.3" />
<PackageReference Update="Azure.ResourceManager.KeyVault" Version="1.3.0-alpha.20240310.2" />
<PackageReference Update="Azure.ResourceManager.PostgreSql" Version="1.2.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.Redis" Version="1.4.0-alpha.20240309.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public partial class RoleAssignment : Azure.Provisioning.Resource<Azure.Resource
public RoleDefinition(string value) { throw null; }
public static Azure.Provisioning.Authorization.RoleDefinition AppConfigurationDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition CognitiveServicesOpenAIContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition EventHubsDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition KeyVaultAdministrator { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition SearchIndexDataContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition SearchServiceContributor { get { throw null; } }
Expand Down Expand Up @@ -255,6 +256,27 @@ public partial class CosmosDBSqlDatabase : Azure.Provisioning.Resource<Azure.Res
public static Azure.Provisioning.CosmosDB.CosmosDBSqlDatabase FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.CosmosDB.CosmosDBAccount parent) { throw null; }
}
}
namespace Azure.Provisioning.EventHubs
{
public partial class EventHub : Azure.Provisioning.Resource<Azure.ResourceManager.EventHubs.EventHubData>
{
public EventHub(Azure.Provisioning.IConstruct scope, Azure.Provisioning.EventHubs.EventHubsNamespace? parent = null, string name = "hub", string version = "2021-11-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.EventHubs.EventHubData>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
public static Azure.Provisioning.EventHubs.EventHub FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.EventHubs.EventHubsNamespace parent) { throw null; }
}
public partial class EventHubsConsumerGroup : Azure.Provisioning.Resource<Azure.ResourceManager.EventHubs.EventHubsConsumerGroupData>
{
public EventHubsConsumerGroup(Azure.Provisioning.IConstruct scope, Azure.Provisioning.EventHubs.EventHub? parent = null, string name = "hub", string version = "2021-11-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.EventHubs.EventHubsConsumerGroupData>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
public static Azure.Provisioning.EventHubs.EventHubsConsumerGroup FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.EventHubs.EventHub parent) { throw null; }
}
public partial class EventHubsNamespace : Azure.Provisioning.Resource<Azure.ResourceManager.EventHubs.EventHubsNamespaceData>
{
public EventHubsNamespace(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.EventHubs.Models.EventHubsSku? sku = null, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "eh", string version = "2021-11-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.EventHubs.EventHubsNamespaceData>)) { }
public static Azure.Provisioning.EventHubs.EventHubsNamespace 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; }
}
}
namespace Azure.Provisioning.KeyVaults
{
public partial class KeyVault : Azure.Provisioning.Resource<Azure.ResourceManager.KeyVault.KeyVaultData>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public partial class RoleAssignment : Azure.Provisioning.Resource<Azure.Resource
public RoleDefinition(string value) { throw null; }
public static Azure.Provisioning.Authorization.RoleDefinition AppConfigurationDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition CognitiveServicesOpenAIContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition EventHubsDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition KeyVaultAdministrator { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition SearchIndexDataContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition SearchServiceContributor { get { throw null; } }
Expand Down Expand Up @@ -255,6 +256,27 @@ public partial class CosmosDBSqlDatabase : Azure.Provisioning.Resource<Azure.Res
public static Azure.Provisioning.CosmosDB.CosmosDBSqlDatabase FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.CosmosDB.CosmosDBAccount parent) { throw null; }
}
}
namespace Azure.Provisioning.EventHubs
{
public partial class EventHub : Azure.Provisioning.Resource<Azure.ResourceManager.EventHubs.EventHubData>
{
public EventHub(Azure.Provisioning.IConstruct scope, Azure.Provisioning.EventHubs.EventHubsNamespace? parent = null, string name = "hub", string version = "2021-11-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.EventHubs.EventHubData>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
public static Azure.Provisioning.EventHubs.EventHub FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.EventHubs.EventHubsNamespace parent) { throw null; }
}
public partial class EventHubsConsumerGroup : Azure.Provisioning.Resource<Azure.ResourceManager.EventHubs.EventHubsConsumerGroupData>
{
public EventHubsConsumerGroup(Azure.Provisioning.IConstruct scope, Azure.Provisioning.EventHubs.EventHub? parent = null, string name = "hub", string version = "2021-11-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.EventHubs.EventHubsConsumerGroupData>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
public static Azure.Provisioning.EventHubs.EventHubsConsumerGroup FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.EventHubs.EventHub parent) { throw null; }
}
public partial class EventHubsNamespace : Azure.Provisioning.Resource<Azure.ResourceManager.EventHubs.EventHubsNamespaceData>
{
public EventHubsNamespace(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.EventHubs.Models.EventHubsSku? sku = null, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "eh", string version = "2021-11-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.EventHubs.EventHubsNamespaceData>)) { }
public static Azure.Provisioning.EventHubs.EventHubsNamespace 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; }
}
}
namespace Azure.Provisioning.KeyVaults
{
public partial class KeyVault : Azure.Provisioning.Resource<Azure.ResourceManager.KeyVault.KeyVaultData>
Expand Down
2 changes: 1 addition & 1 deletion sdk/provisioning/Azure.Provisioning/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/provisioning/Azure.Provisioning",
"Tag": "net/provisioning/Azure.Provisioning_b877da6a2b"
"Tag": "net/provisioning/Azure.Provisioning_a7f71bfdc6"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="Azure.ResourceManager.CognitiveServices" />
<PackageReference Include="Azure.ResourceManager.ServiceBus" />
<PackageReference Include="Azure.ResourceManager.Search" />
<PackageReference Include="Azure.ResourceManager.EventHubs" />
<PackageReference Include="System.ClientModel" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public RoleDefinition(string value)
/// </summary>
public static RoleDefinition ServiceBusDataOwner { get; } = new RoleDefinition("090c5cfd-751d-490a-894a-3ce6f1109419");

/// <summary>
/// Event Hubs data owner role.
/// </summary>
public static RoleDefinition EventHubsDataOwner { get; } = new RoleDefinition("f526a384-b230-433a-b45c-95f59c4a2dec");

/// <summary>
/// App configuration data owner role.
/// </summary>
Expand Down
56 changes: 56 additions & 0 deletions sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;
using Azure.ResourceManager.EventHubs;
using Azure.ResourceManager.EventHubs.Models;

namespace Azure.Provisioning.EventHubs
{
/// <summary>
/// Represents an Event Hub.
/// </summary>
public class EventHub : Resource<EventHubData>
{
private const string ResourceTypeName = "Microsoft.EventHub/namespaces/eventhubs";
private static readonly Func<string, EventHubData> Empty = (name) => ArmEventHubsModelFactory.EventHubData();

/// <summary>
/// Initializes a new instance of the <see cref="EventHub"/>.
/// </summary>
/// <param name="scope">The scope.</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 EventHub(IConstruct scope, EventHubsNamespace? parent = null, string name = "hub", string version = EventHubsNamespace.DefaultVersion, AzureLocation? location = default)
: this(scope, parent, name, version, false, (name) => ArmEventHubsModelFactory.EventHubData(
name: name,
resourceType: ResourceTypeName,
location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS))
{
}

private EventHub(IConstruct scope, EventHubsNamespace? parent = null, string name = "hub", string version = EventHubsNamespace.DefaultVersion, bool isExisting = true, Func<string, EventHubData>? creator = null)
: base(scope, parent, name, ResourceTypeName, EventHubsNamespace.DefaultVersion, creator ?? Empty, isExisting)
{
}

/// <summary>
/// Creates a new instance of the <see cref="EventHub"/> 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 KeyVault instance.</returns>
public static EventHub FromExisting(IConstruct scope, string name, EventHubsNamespace parent)
=> new EventHub(scope, parent: parent, name: name, isExisting: true);

/// <inheritdoc/>
protected override Resource? FindParentInScope(IConstruct scope)
{
return scope.GetSingleResource<EventHubsNamespace>() ?? new EventHubsNamespace(scope);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;
using Azure.ResourceManager.EventHubs;
using Azure.ResourceManager.EventHubs.Models;

namespace Azure.Provisioning.EventHubs
{
/// <summary>
/// Represents an Event Hub consumer group.
/// </summary>
public class EventHubsConsumerGroup : Resource<EventHubsConsumerGroupData>
{
private const string ResourceTypeName = "Microsoft.EventHub/namespaces/eventhubs/consumergroups";
private static readonly Func<string, EventHubsConsumerGroupData> Empty = (name) => ArmEventHubsModelFactory.EventHubsConsumerGroupData();

/// <summary>
/// Initializes a new instance of the <see cref="EventHub"/>.
/// </summary>
/// <param name="scope">The scope.</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 EventHubsConsumerGroup(IConstruct scope, EventHub? parent = null, string name = "hub", string version = EventHubsNamespace.DefaultVersion, AzureLocation? location = default)
: this(scope, parent, name, version, false, (name) => ArmEventHubsModelFactory.EventHubsConsumerGroupData(
name: name,
resourceType: ResourceTypeName,
location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS))
{
}

private EventHubsConsumerGroup(IConstruct scope, EventHub? parent = null, string name = "hub", string version = EventHubsNamespace.DefaultVersion, bool isExisting = true, Func<string, EventHubsConsumerGroupData>? creator = null)
: base(scope, parent, name, ResourceTypeName, EventHubsNamespace.DefaultVersion, creator ?? Empty, isExisting)
{
}

/// <summary>
/// Creates a new instance of the <see cref="EventHub"/> 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 KeyVault instance.</returns>
public static EventHubsConsumerGroup FromExisting(IConstruct scope, string name, EventHub parent)
=> new EventHubsConsumerGroup(scope, parent: parent, name: name, isExisting: true);

/// <inheritdoc/>
protected override Resource? FindParentInScope(IConstruct scope)
{
return scope.GetSingleResource<EventHub>() ?? new EventHub(scope);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;
using Azure.Provisioning.ResourceManager;
using Azure.ResourceManager.EventHubs;
using Azure.ResourceManager.EventHubs.Models;

namespace Azure.Provisioning.EventHubs
{
/// <summary>
/// Represents an EventHubsNamespace.
/// </summary>
public class EventHubsNamespace : Resource<EventHubsNamespaceData>
{
private const string ResourceTypeName = "Microsoft.EventHub/namespaces";
private static readonly Func<string, EventHubsNamespaceData> Empty = (name) => ArmEventHubsModelFactory.EventHubsNamespaceData();
internal const string DefaultVersion = "2021-11-01";

/// <summary>
/// Initializes a new instance of the <see cref="EventHubsNamespace"/>.
/// </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 EventHubsNamespace(IConstruct scope, EventHubsSku? sku = default, ResourceGroup? parent = null, string name = "eh", string version = DefaultVersion, AzureLocation? location = default)
: this(scope, parent, name, version, false, (name) => ArmEventHubsModelFactory.EventHubsNamespaceData(
name: name,
resourceType: ResourceTypeName,
location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS,
sku: sku ?? new EventHubsSku(EventHubsSkuName.Standard),
minimumTlsVersion: EventHubsTlsVersion.Tls1_2))
{
AssignProperty(data => data.Name, GetAzureName(scope, name));
}

private EventHubsNamespace(IConstruct scope, ResourceGroup? parent = null, string name = "eh", string version = DefaultVersion, bool isExisting = true, Func<string, EventHubsNamespaceData>? creator = null)
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting)
{
}

/// <summary>
/// Creates a new instance of the <see cref="EventHubsNamespace"/> 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 KeyVault instance.</returns>
public static EventHubsNamespace FromExisting(IConstruct scope, string name, ResourceGroup? parent = null)
=> new EventHubsNamespace(scope, parent: parent, name: name, isExisting: true);

/// <inheritdoc/>
protected override string GetAzureName(IConstruct scope, string resourceName) => GetGloballyUniqueName(resourceName);
}
}
Loading

0 comments on commit 4266e1f

Please sign in to comment.