Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Az.EventHub] Get-AzEventHub accepts pipeline input from Get-AzEventHubNamespace. #13732

Merged
merged 5 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/EventHub/EventHub/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Added functionality to accept input from pipeline for `Get-AzEventHub` from `Get-AzEventHubNamespace`.

## Version 1.7.1
* Fixed Cluster commands for EventHub cluster without tags
Expand Down
23 changes: 18 additions & 5 deletions src/EventHub/EventHub/Cmdlets/EventHub/GetAzureEventHubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

using Microsoft.Azure.Commands.EventHub.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
Expand All @@ -25,34 +27,45 @@ namespace Microsoft.Azure.Commands.EventHub.Commands.EventHub
/// <para> If EventHub name provided, a single EventHub detials will be returned</para>
/// <para> If EventHub name not provided, list of EventHub will be returned</para>
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "EventHub"), OutputType(typeof(PSEventHubAttributes))]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "EventHub", DefaultParameterSetName = EventhubPropertiesParameterSet), OutputType(typeof(PSEventHubAttributes))]
public class GetAzureRmEventHub : AzureEventHubsCmdletBase
{
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0, HelpMessage = "Resource Group Name")]
[Parameter(Mandatory = true, Position = 0, HelpMessage = "Resource Group Name", ParameterSetName= EventhubPropertiesParameterSet)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lost the definition for parameter set NamespaceInputObjectParameterSet.

Copy link
Member Author

@hakashya hakashya Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I introduced NamespaceInputObjectParameterSet and EventHubPropertiesParameterSet. Doing so eliminated the _AllParameterSets that was being evaluated originally. The functionality exhibited by the cmdlet earlier was to evaluate _AllParameterSets. This same functionality is now exhibited by EventHubPropertiesParameterSet, thereby not having any breaking changes (although static analyzer considers this to be breaking change due to the loss of _AllParameterSets).

The introduction of the two parameter sets was to ensure that InputObject was accepted via the pipeline for the cmdlet.

[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 1, HelpMessage = "Namespace Name")]
[Parameter(Mandatory = true, Position = 1, HelpMessage = "Namespace Name", ParameterSetName = EventhubPropertiesParameterSet)]
[ValidateNotNullOrEmpty]
[Alias(AliasNamespaceName)]
public string Namespace { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 2, HelpMessage = "EventHub Name")]
[Parameter(Mandatory = false, Position = 2, HelpMessage = "EventHub Name", ParameterSetName = EventhubPropertiesParameterSet)]
[Parameter(Mandatory = false, Position = 1, HelpMessage = "EventHub Name", ParameterSetName = NamespaceInputObjectParameterSet)]
[Alias(AliasEventHubName)]
public string Name { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Determine the maximum number of EventHubs to return.")]
[Parameter(Mandatory = false, HelpMessage = "Determine the maximum number of EventHubs to return.", ParameterSetName = EventhubPropertiesParameterSet)]
[ValidateNotNull]
public int? MaxCount { get; set; }

[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "Namespace object", ParameterSetName = NamespaceInputObjectParameterSet)]
[ValidateNotNull]
public PSNamespaceAttributes NamespaceObject { get; set; }

/// <summary>
///
/// </summary>
public override void ExecuteCmdlet()
{
try
{
if (this.IsParameterBound(c => c.NamespaceObject))
{
this.ResourceGroupName = this.NamespaceObject.ResourceGroupName;
this.Namespace = this.NamespaceObject.Name;
}

if (!string.IsNullOrEmpty(Name))
{
// Get a EventHub
Expand Down
38 changes: 30 additions & 8 deletions src/EventHub/EventHub/help/Get-AzEventHub.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
external help file: Microsoft.Azure.PowerShell.Cmdlets.EventHub.dll-Help.xml
Module Name: Az.EventHub
online version: https://docs.microsoft.com/en-us/powershell/module/az.eventhub/get-azeventhub
Expand All @@ -12,11 +12,18 @@ Gets the details of a single Event Hub, or gets a list of Event Hubs.

## SYNTAX

### EventhubPropertiesSet (Default)
```
Get-AzEventHub [-ResourceGroupName] <String> [-Namespace] <String> [[-Name] <String>] [-MaxCount <Int32>]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### NamespaceInputObjectSet
```
Get-AzEventHub [[-Name] <String>] [-NamespaceObject] <PSNamespaceAttributes>
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

## DESCRIPTION
The Get-AzEventHub cmdlet returns either the details of an Event Hub, or a list of all Event Hubs in the current namespace.
If the Event Hub name is provided, the details of a single Event Hub are returned.
Expand Down Expand Up @@ -60,7 +67,7 @@ Determine the maximum number of EventHubs to return.

```yaml
Type: System.Nullable`1[System.Int32]
Parameter Sets: (All)
Parameter Sets: EventhubPropertiesSet
Aliases:

Required: False
Expand All @@ -81,7 +88,7 @@ Aliases: EventHubName
Required: False
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept pipeline input: False
Accept wildcard characters: False
```

Expand All @@ -90,13 +97,28 @@ Namespace Name

```yaml
Type: System.String
Parameter Sets: (All)
Parameter Sets: EventhubPropertiesSet
Aliases: NamespaceName

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept pipeline input: False
Accept wildcard characters: False
```

### -NamespaceObject
Namespace object

```yaml
Type: Microsoft.Azure.Commands.EventHub.Models.PSNamespaceAttributes
Parameter Sets: NamespaceInputObjectSet
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

Expand All @@ -105,18 +127,18 @@ Resource Group Name

```yaml
Type: System.String
Parameter Sets: (All)
Parameter Sets: EventhubPropertiesSet
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand Down
4 changes: 2 additions & 2 deletions src/EventHub/EventHub/help/Get-AzEventHubNamespace.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
external help file: Microsoft.Azure.PowerShell.Cmdlets.EventHub.dll-Help.xml
Module Name: Az.EventHub
online version: https://docs.microsoft.com/en-us/powershell/module/az.eventhub/get-azeventhubnamespace
Expand Down Expand Up @@ -95,7 +95,7 @@ Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand Down