Skip to content

Commit 037ca4a

Browse files
committed
Comments fixed for parameter set
1 parent 91259cc commit 037ca4a

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

src/IotHub/IotHub/IotHub/AddAzureRmIotHubKey.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,22 @@ namespace Microsoft.Azure.Commands.Management.IotHub
2727
[OutputType(typeof(PSSharedAccessSignatureAuthorizationRule))]
2828
public class AddAzureRmIotHubKey : IotHubBaseCmdlet
2929
{
30+
private const string ResourceIdParameterSet = "ResourceIdSet";
31+
private const string ResourceParameterSet = "ResourceSet";
32+
33+
[Parameter(
34+
Position = 0,
35+
Mandatory = true,
36+
ParameterSetName = ResourceIdParameterSet,
37+
ValueFromPipelineByPropertyName = true,
38+
HelpMessage = "IotHub Resource Id")]
39+
[ValidateNotNullOrEmpty]
40+
public string ResourceId { get; set; }
41+
3042
[Parameter(
3143
Position = 0,
3244
Mandatory = true,
45+
ParameterSetName = ResourceParameterSet,
3346
ValueFromPipelineByPropertyName = true,
3447
HelpMessage = "Name of the Resource Group")]
3548
[ResourceGroupCompleter]
@@ -39,14 +52,21 @@ public class AddAzureRmIotHubKey : IotHubBaseCmdlet
3952
[Parameter(
4053
Position = 1,
4154
Mandatory = true,
55+
ParameterSetName = ResourceParameterSet,
4256
ValueFromPipelineByPropertyName = true,
4357
HelpMessage = "Name of the Iot Hub")]
4458
[ValidateNotNullOrEmpty]
4559
public string Name { get; set; }
4660

61+
[Parameter(
62+
Position = 1,
63+
Mandatory = true,
64+
ParameterSetName = ResourceIdParameterSet,
65+
HelpMessage = "Name of the Key")]
4766
[Parameter(
4867
Position = 2,
4968
Mandatory = true,
69+
ParameterSetName = ResourceParameterSet,
5070
HelpMessage = "Name of the Key")]
5171
[ValidateNotNullOrEmpty]
5272
public string KeyName { get; set; }
@@ -71,6 +91,12 @@ public override void ExecuteCmdlet()
7191
{
7292
if (ShouldProcess(KeyName, Properties.Resources.AddIotHubKey))
7393
{
94+
if (ParameterSetName.Equals(ResourceIdParameterSet))
95+
{
96+
this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId);
97+
this.Name = IotHubUtils.GetIotHubName(this.ResourceId);
98+
}
99+
74100
var psAuthRule = new PSSharedAccessSignatureAuthorizationRule()
75101
{
76102
KeyName = this.KeyName,

src/IotHub/IotHub/IotHub/GetAzureRmIotHubKey.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,22 @@ namespace Microsoft.Azure.Commands.Management.IotHub
2727
[OutputType(typeof(PSSharedAccessSignatureAuthorizationRule))]
2828
public class GetAzureRmIotHubKey : IotHubBaseCmdlet
2929
{
30+
private const string ResourceIdParameterSet = "ResourceIdSet";
31+
private const string ResourceParameterSet = "ResourceSet";
32+
33+
[Parameter(
34+
Position = 0,
35+
Mandatory = true,
36+
ParameterSetName = ResourceIdParameterSet,
37+
ValueFromPipelineByPropertyName = true,
38+
HelpMessage = "IotHub Resource Id")]
39+
[ValidateNotNullOrEmpty]
40+
public string ResourceId { get; set; }
41+
3042
[Parameter(
3143
Position = 0,
3244
Mandatory = true,
45+
ParameterSetName = ResourceParameterSet,
3346
ValueFromPipelineByPropertyName = true,
3447
HelpMessage = "Name of the Resource Group")]
3548
[ResourceGroupCompleter]
@@ -39,20 +52,26 @@ public class GetAzureRmIotHubKey : IotHubBaseCmdlet
3952
[Parameter(
4053
Position = 1,
4154
Mandatory = true,
55+
ParameterSetName = ResourceParameterSet,
4256
ValueFromPipelineByPropertyName = true,
4357
HelpMessage = "Name of the Iot Hub")]
4458
[ValidateNotNullOrEmpty]
4559
public string Name { get; set; }
4660

4761
[Parameter(
48-
Position = 2,
4962
Mandatory = false,
5063
HelpMessage = "Name of the Key")]
5164
[ValidateNotNullOrEmpty]
5265
public string KeyName { get; set; }
5366

5467
public override void ExecuteCmdlet()
5568
{
69+
if (ParameterSetName.Equals(ResourceIdParameterSet))
70+
{
71+
this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId);
72+
this.Name = IotHubUtils.GetIotHubName(this.ResourceId);
73+
}
74+
5675
if (KeyName != null)
5776
{
5877
SharedAccessSignatureAuthorizationRule authPolicy = this.IotHubClient.IotHubResource.GetKeysForKeyName(this.ResourceGroupName, this.Name, this.KeyName);

src/IotHub/IotHub/IotHub/NewAzureRmIotHubKey.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,22 @@ namespace Microsoft.Azure.Commands.Management.IotHub
3030
[OutputType(typeof(PSSharedAccessSignatureAuthorizationRule))]
3131
public class NewAzureRmIotHubKey : IotHubBaseCmdlet
3232
{
33+
private const string ResourceIdParameterSet = "ResourceIdSet";
34+
private const string ResourceParameterSet = "ResourceSet";
35+
3336
[Parameter(
3437
Position = 0,
3538
Mandatory = true,
39+
ParameterSetName = ResourceIdParameterSet,
40+
ValueFromPipelineByPropertyName = true,
41+
HelpMessage = "IotHub Resource Id")]
42+
[ValidateNotNullOrEmpty]
43+
public string ResourceId { get; set; }
44+
45+
[Parameter(
46+
Position = 0,
47+
Mandatory = true,
48+
ParameterSetName = ResourceParameterSet,
3649
ValueFromPipelineByPropertyName = true,
3750
HelpMessage = "Name of the Resource Group")]
3851
[ResourceGroupCompleter]
@@ -42,22 +55,35 @@ public class NewAzureRmIotHubKey : IotHubBaseCmdlet
4255
[Parameter(
4356
Position = 1,
4457
Mandatory = true,
58+
ParameterSetName = ResourceParameterSet,
4559
ValueFromPipelineByPropertyName = true,
4660
HelpMessage = "Name of the Iot Hub")]
4761
[ValidateNotNullOrEmpty]
4862
public string Name { get; set; }
4963

64+
[Parameter(
65+
Position = 1,
66+
Mandatory = true,
67+
ParameterSetName = ResourceIdParameterSet,
68+
HelpMessage = "Name of the Key")]
5069
[Parameter(
5170
Position = 2,
5271
Mandatory = true,
72+
ParameterSetName = ResourceParameterSet,
5373
ValueFromPipelineByPropertyName = true,
5474
HelpMessage = "Name of the Key")]
5575
[ValidateNotNullOrEmpty]
5676
public string KeyName { get; set; }
5777

78+
[Parameter(
79+
Position = 2,
80+
Mandatory = true,
81+
ParameterSetName = ResourceIdParameterSet,
82+
HelpMessage = "Regenerate Key.")]
5883
[Parameter(
5984
Position = 3,
6085
Mandatory = true,
86+
ParameterSetName = ResourceParameterSet,
6187
HelpMessage = "Regenerate Key.")]
6288
[ValidateNotNullOrEmpty]
6389
[PSArgumentCompleter(new string[] { "Primary", "Secondary", "Swap" })]
@@ -67,6 +93,12 @@ public override void ExecuteCmdlet()
6793
{
6894
if (ShouldProcess(KeyName, Properties.Resources.NewIotHubKey))
6995
{
96+
if (ParameterSetName.Equals(ResourceIdParameterSet))
97+
{
98+
this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId);
99+
this.Name = IotHubUtils.GetIotHubName(this.ResourceId);
100+
}
101+
70102
var regeneratedAuthRule = new PSSharedAccessSignatureAuthorizationRule();
71103

72104
IotHubDescription iothubDesc = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name);

src/IotHub/IotHub/IotHub/RemoveAzureRmIotHubKey.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@ namespace Microsoft.Azure.Commands.Management.IotHub
3030
[OutputType(typeof(PSSharedAccessSignatureAuthorizationRule))]
3131
public class RemoveAzureRmIotHubKey : IotHubBaseCmdlet
3232
{
33+
private const string ResourceIdParameterSet = "ResourceIdSet";
34+
private const string ResourceParameterSet = "ResourceSet";
3335

3436
[Parameter(
3537
Position = 0,
3638
Mandatory = true,
39+
ParameterSetName = ResourceIdParameterSet,
40+
ValueFromPipelineByPropertyName = true,
41+
HelpMessage = "IotHub Resource Id")]
42+
[ValidateNotNullOrEmpty]
43+
public string ResourceId { get; set; }
44+
45+
[Parameter(
46+
Position = 0,
47+
Mandatory = true,
48+
ParameterSetName = ResourceParameterSet,
3749
ValueFromPipelineByPropertyName = true,
3850
HelpMessage = "Name of the Resource Group")]
3951
[ResourceGroupCompleter]
@@ -43,14 +55,22 @@ public class RemoveAzureRmIotHubKey : IotHubBaseCmdlet
4355
[Parameter(
4456
Position = 1,
4557
Mandatory = true,
58+
ParameterSetName = ResourceParameterSet,
4659
ValueFromPipelineByPropertyName = true,
4760
HelpMessage = "Name of the Iot Hub")]
4861
[ValidateNotNullOrEmpty]
4962
public string Name { get; set; }
5063

64+
65+
[Parameter(
66+
Position = 1,
67+
Mandatory = true,
68+
ParameterSetName = ResourceIdParameterSet,
69+
HelpMessage = "Name of the Key")]
5170
[Parameter(
5271
Position = 2,
5372
Mandatory = true,
73+
ParameterSetName = ResourceParameterSet,
5474
ValueFromPipelineByPropertyName = true,
5575
HelpMessage = "Name of the Key")]
5676
[ValidateNotNullOrEmpty]
@@ -60,6 +80,12 @@ public override void ExecuteCmdlet()
6080
{
6181
if (ShouldProcess(KeyName, Properties.Resources.RemoveIotHubKey))
6282
{
83+
if (ParameterSetName.Equals(ResourceIdParameterSet))
84+
{
85+
this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId);
86+
this.Name = IotHubUtils.GetIotHubName(this.ResourceId);
87+
}
88+
6389
IotHubDescription iothubDesc = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name);
6490
IList<SharedAccessSignatureAuthorizationRule> authRules = (List<SharedAccessSignatureAuthorizationRule>)this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.Name).ToList();
6591

src/IotHub/IotHub/help/New-AzIotHubKey.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@ Generate an Azure IoT Hub key.
2525
### Example 1 Regenerate primary key
2626
```
2727
PS C:\> New-AzIotHubKey -ResourceGroupName "myresourcegroup" -Name "myiothub" -KeyName "testKey" -RenewKey "primary"
28+
29+
KeyName PrimaryKey SecondaryKey Rights
30+
------- ---------- ------------ ------
31+
test SXSdm31aT+i3939xSnA191f8g3uRhIUCTsO26b9s/nE= 6JqGKGUTL0mhQwvcOeIRT7OnT6noK/tie6jBY77sJTE= ServiceConnect
2832
```
2933

3034
Regenerated primary key for the authorization policy "testKey" of an azure iot hub.
3135

3236
### Example 2 Swapping keys
3337
```
3438
PS C:\> New-AzIotHubKey -ResourceGroupName "myresourcegroup" -Name "myiothub" -KeyName "testKey" -RenewKey "swap"
39+
40+
KeyName PrimaryKey SecondaryKey Rights
41+
------- ---------- ------------ ------
42+
test 6JqGKGUTL0mhQwvcOeIRT7OnT6noK/tie6jBY77sJTE= SXSdm31aT+i3939xSnA191f8g3uRhIUCTsO26b9s/nE= ServiceConnect
3543
```
3644

3745
Swapping keys for the authorization policy "testKey" of an azure iot hub.

0 commit comments

Comments
 (0)