Skip to content

Commit 792136f

Browse files
author
Maddie Clayton
authored
Merge pull request #6045 from maddieclayton/msafix
Make compliance changes to ManagedStorageAccount KeyVault cmdlets
2 parents 41132b7 + 76f434b commit 792136f

21 files changed

+439
-103
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ManagedStorageAccounts/GetAzureKeyVaultManagedStorageAccount.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
using System.Management.Automation;
1919
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
2020
using Microsoft.Azure.Commands.KeyVault.Models.ManagedStorageAccounts;
21+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
2122

2223
namespace Microsoft.Azure.Commands.KeyVault
2324
{
24-
[Cmdlet( VerbsCommon.Get, CmdletNoun.AzureKeyVaultManagedStorageAccount)]
25-
[OutputType( typeof( List<PSKeyVaultManagedStorageAccount> ), typeof( PSKeyVaultManagedStorageAccount ), typeof(List<PSDeletedKeyVaultManagedStorageAccountIdentityItem>), typeof(PSDeletedKeyVaultManagedStorageAccount) )]
25+
[Cmdlet( VerbsCommon.Get, CmdletNoun.AzureKeyVaultManagedStorageAccount, DefaultParameterSetName = ByAccountNameParameterSet)]
26+
[OutputType( typeof(PSKeyVaultManagedStorageAccountIdentityItem), typeof(PSKeyVaultManagedStorageAccount), typeof(PSDeletedKeyVaultManagedStorageAccountIdentityItem), typeof(PSDeletedKeyVaultManagedStorageAccount) )]
2627
public class GetAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
2728
{
2829
#region Parameter Set Names
2930

3031
private const string ByAccountNameParameterSet = "ByAccountName";
32+
private const string ByInputObjectParameterSet = "ByInputObject";
33+
private const string ByResourceIdParameterSet = "ByResourceId";
3134

3235
#endregion
3336

@@ -38,15 +41,36 @@ public class GetAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
3841
/// </summary>
3942
[Parameter( Mandatory = true,
4043
Position = 0,
41-
ValueFromPipelineByPropertyName = true,
44+
ParameterSetName = ByAccountNameParameterSet,
4245
HelpMessage = "Vault name. Cmdlet constructs the FQDN of a vault based on the name and currently selected environment." )]
4346
[ValidateNotNullOrEmpty]
4447
public string VaultName { get; set; }
4548

49+
/// <summary>
50+
/// Vault object
51+
/// </summary>
52+
[Parameter(Mandatory = true,
53+
Position = 0,
54+
ParameterSetName = ByInputObjectParameterSet,
55+
ValueFromPipeline = true,
56+
HelpMessage = "Vault object.")]
57+
[ValidateNotNullOrEmpty]
58+
public PSKeyVault InputObject { get; set; }
59+
60+
/// <summary>
61+
/// Vault ResourceId
62+
/// </summary>
63+
[Parameter(Mandatory = true,
64+
Position = 0,
65+
ParameterSetName = ByResourceIdParameterSet,
66+
ValueFromPipelineByPropertyName = true,
67+
HelpMessage = "Vault resource id.")]
68+
[ValidateNotNullOrEmpty]
69+
public string ResourceId { get; set; }
70+
4671
[Parameter( Mandatory = false,
4772
Position = 1,
4873
ParameterSetName = ByAccountNameParameterSet,
49-
ValueFromPipelineByPropertyName = true,
5074
HelpMessage = "Key Vault managed storage account name. Cmdlet constructs the FQDN of a managed storage account name from vault name, currently " +
5175
"selected environment and manged storage account name." )]
5276
[ValidateNotNullOrEmpty]
@@ -60,6 +84,16 @@ public class GetAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
6084

6185
public override void ExecuteCmdlet()
6286
{
87+
if (InputObject != null)
88+
{
89+
VaultName = InputObject.VaultName;
90+
}
91+
else if (ResourceId != null)
92+
{
93+
var resourceIdentifier = new ResourceIdentifier(ResourceId);
94+
VaultName = resourceIdentifier.ResourceName;
95+
}
96+
6397
if (InRemovedState)
6498
{
6599
if (String.IsNullOrWhiteSpace(AccountName))

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ManagedStorageAccounts/GetAzureKeyVaultManagedStorageSasDefinition.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121

2222
namespace Microsoft.Azure.Commands.KeyVault
2323
{
24-
[Cmdlet( VerbsCommon.Get, CmdletNoun.AzureKeyVaultManagedStorageSasDefinition)]
25-
[OutputType( typeof( List<PSKeyVaultManagedStorageSasDefinitionIdentityItem> ), typeof( PSKeyVaultManagedStorageSasDefinition ), typeof(PSDeletedKeyVaultManagedStorageSasDefinition), typeof(PSDeletedKeyVaultManagedStorageSasDefinitionIdentityItem) )]
24+
[Cmdlet( VerbsCommon.Get, CmdletNoun.AzureKeyVaultManagedStorageSasDefinition, DefaultParameterSetName = ByDefinitionNameParameterSet)]
25+
[OutputType( typeof(PSKeyVaultManagedStorageSasDefinitionIdentityItem), typeof(PSKeyVaultManagedStorageSasDefinition), typeof(PSDeletedKeyVaultManagedStorageSasDefinition), typeof(PSDeletedKeyVaultManagedStorageSasDefinitionIdentityItem) )]
2626
public class GetAzureKeyVaultManagedStorageSasDefinition : KeyVaultCmdletBase
2727
{
2828
#region Parameter Set Names
2929

3030
private const string ByDefinitionNameParameterSet = "ByDefinitionName";
31+
private const string ByInputObjectParameterSet = "ByInputObject";
3132

3233
#endregion
3334

@@ -38,24 +39,33 @@ public class GetAzureKeyVaultManagedStorageSasDefinition : KeyVaultCmdletBase
3839
/// </summary>
3940
[Parameter( Mandatory = true,
4041
Position = 0,
41-
ValueFromPipelineByPropertyName = true,
42+
ParameterSetName = ByDefinitionNameParameterSet,
4243
HelpMessage = "Vault name. Cmdlet constructs the FQDN of a vault based on the name and currently selected environment." )]
4344
[ValidateNotNullOrEmpty]
4445
public string VaultName { get; set; }
4546

4647
[Parameter( Mandatory = true,
4748
Position = 1,
48-
ValueFromPipelineByPropertyName = true,
49+
ParameterSetName = ByDefinitionNameParameterSet,
4950
HelpMessage = "Key Vault managed storage account name. Cmdlet constructs the FQDN of a managed storage account name from vault name, currently " +
5051
"selected environment and manged storage account name." )]
5152
[ValidateNotNullOrEmpty]
5253
[Alias( Constants.StorageAccountName )]
5354
public string AccountName { get; set; }
5455

56+
/// <summary>
57+
/// PSKeyVaultManagedStorageAccountIdentityItem object
58+
/// </summary>
59+
[Parameter(Mandatory = true,
60+
Position = 0,
61+
ParameterSetName = ByInputObjectParameterSet,
62+
ValueFromPipeline = true,
63+
HelpMessage = "ManagedStorageAccount object.")]
64+
[ValidateNotNullOrEmpty]
65+
public PSKeyVaultManagedStorageAccountIdentityItem InputObject { get; set; }
66+
5567
[Parameter( Mandatory = false,
5668
Position = 2,
57-
ValueFromPipelineByPropertyName = true,
58-
ParameterSetName = ByDefinitionNameParameterSet,
5969
HelpMessage = "Storage sas definition name. Cmdlet constructs the FQDN of a storage sas definition from vault name, currently " +
6070
"selected environment, storage account name and sas definition name." )]
6171
[ValidateNotNullOrEmpty]
@@ -69,6 +79,12 @@ public class GetAzureKeyVaultManagedStorageSasDefinition : KeyVaultCmdletBase
6979

7080
public override void ExecuteCmdlet()
7181
{
82+
if (InputObject != null)
83+
{
84+
VaultName = InputObject.VaultName;
85+
AccountName = InputObject.AccountName;
86+
}
87+
7288
if (InRemovedState)
7389
{
7490
if (String.IsNullOrWhiteSpace(Name))

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ManagedStorageAccounts/RemoveAzureKeyVaultManagedStorageAccount.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,46 @@
2121

2222
namespace Microsoft.Azure.Commands.KeyVault
2323
{
24-
[Cmdlet( VerbsCommon.Remove, CmdletNoun.AzureKeyVaultManagedStorageAccount,
24+
[Cmdlet( VerbsCommon.Remove, CmdletNoun.AzureKeyVaultManagedStorageAccount, DefaultParameterSetName = ByDefinitionNameParameterSet,
2525
SupportsShouldProcess = true)]
2626
[OutputType( typeof( PSDeletedKeyVaultManagedStorageAccount ) )]
2727
public class RemoveAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
2828
{
29+
#region Parameter Set Names
30+
31+
private const string ByDefinitionNameParameterSet = "ByDefinitionName";
32+
private const string ByInputObjectParameterSet = "ByInputObject";
33+
34+
#endregion
35+
2936
#region Input Parameter Definitions
3037
[Parameter( Mandatory = true,
3138
Position = 0,
32-
ValueFromPipelineByPropertyName = true,
39+
ParameterSetName = ByDefinitionNameParameterSet,
3340
HelpMessage = "Vault name. Cmdlet constructs the FQDN of a vault based on the name and currently selected environment." )]
3441
[ValidateNotNullOrEmpty]
3542
public string VaultName { get; set; }
3643

3744
[Parameter( Mandatory = true,
3845
Position = 1,
39-
ValueFromPipelineByPropertyName = true,
46+
ParameterSetName = ByDefinitionNameParameterSet,
4047
HelpMessage = "Key Vault managed storage account name. Cmdlet constructs the FQDN of a managed storage account name from vault name, currently " +
4148
"selected environment and manged storage account name." )]
4249
[ValidateNotNullOrEmpty]
4350
[Alias( Constants.StorageAccountName, Constants.Name )]
4451
public string AccountName { get; set; }
4552

53+
/// <summary>
54+
/// PSKeyVaultManagedStorageAccountIdentityItem object
55+
/// </summary>
56+
[Parameter(Mandatory = true,
57+
Position = 0,
58+
ParameterSetName = ByInputObjectParameterSet,
59+
ValueFromPipeline = true,
60+
HelpMessage = "ManagedStorageAccount object.")]
61+
[ValidateNotNullOrEmpty]
62+
public PSKeyVaultManagedStorageAccountIdentityItem InputObject { get; set; }
63+
4664
/// <summary>
4765
/// If present, operate on the deleted entity.
4866
/// </summary>
@@ -65,6 +83,12 @@ public class RemoveAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
6583

6684
public override void ExecuteCmdlet()
6785
{
86+
if (InputObject != null)
87+
{
88+
VaultName = InputObject.VaultName;
89+
AccountName = InputObject.AccountName;
90+
}
91+
6892
if (InRemovedState.IsPresent)
6993
{
7094
ConfirmAction(

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ManagedStorageAccounts/RemoveAzureKeyVaultManagedStorageSasDefinition.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,28 @@
2121
namespace Microsoft.Azure.Commands.KeyVault
2222
{
2323
[Cmdlet( VerbsCommon.Remove, CmdletNoun.AzureKeyVaultManagedStorageSasDefinition,
24-
SupportsShouldProcess = true)]
24+
DefaultParameterSetName = ByDefinitionNameParameterSet, SupportsShouldProcess = true)]
2525
[OutputType( typeof( PSDeletedKeyVaultManagedStorageSasDefinition ) )]
2626
public class RemoveAzureKeyVaultSasDefinition : KeyVaultCmdletBase
2727
{
28+
#region Parameter Set Names
29+
30+
private const string ByDefinitionNameParameterSet = "ByDefinitionName";
31+
private const string ByInputObjectParameterSet = "ByInputObject";
32+
33+
#endregion
34+
2835
#region Input Parameter Definitions
2936
[Parameter( Mandatory = true,
3037
Position = 0,
31-
ValueFromPipelineByPropertyName = true,
38+
ParameterSetName = ByDefinitionNameParameterSet,
3239
HelpMessage = "Vault name. Cmdlet constructs the FQDN of a vault based on the name and currently selected environment." )]
3340
[ValidateNotNullOrEmpty]
3441
public string VaultName { get; set; }
3542

3643
[Parameter( Mandatory = true,
3744
Position = 1,
38-
ValueFromPipelineByPropertyName = true,
45+
ParameterSetName = ByDefinitionNameParameterSet,
3946
HelpMessage = "Key Vault managed storage account name. Cmdlet constructs the FQDN of a managed storage account name from vault name, currently " +
4047
"selected environment and manged storage account name." )]
4148
[ValidateNotNullOrEmpty]
@@ -44,13 +51,24 @@ public class RemoveAzureKeyVaultSasDefinition : KeyVaultCmdletBase
4451

4552
[Parameter( Mandatory = true,
4653
Position = 2,
47-
ValueFromPipelineByPropertyName = true,
54+
ParameterSetName = ByDefinitionNameParameterSet,
4855
HelpMessage = "Storage sas definition name. Cmdlet constructs the FQDN of a storage sas definition from vault name, currently " +
4956
"selected environment, storage account name and sas definition name." )]
5057
[ValidateNotNullOrEmpty]
5158
[Alias( Constants.SasDefinitionName )]
5259
public string Name { get; set; }
5360

61+
/// <summary>
62+
/// PSKeyVaultManagedStorageSasDefinitionIdentityItem object
63+
/// </summary>
64+
[Parameter(Mandatory = true,
65+
Position = 0,
66+
ParameterSetName = ByInputObjectParameterSet,
67+
ValueFromPipeline = true,
68+
HelpMessage = "ManagedStorageSasDefinition object.")]
69+
[ValidateNotNullOrEmpty]
70+
public PSKeyVaultManagedStorageSasDefinitionIdentityItem InputObject { get; set; }
71+
5472
/// <summary>
5573
/// If present, do not ask for confirmation
5674
/// </summary>
@@ -66,6 +84,13 @@ public class RemoveAzureKeyVaultSasDefinition : KeyVaultCmdletBase
6684

6785
public override void ExecuteCmdlet()
6886
{
87+
if (InputObject != null)
88+
{
89+
VaultName = InputObject.VaultName;
90+
AccountName = InputObject.AccountName;
91+
Name = InputObject.Name;
92+
}
93+
6994
PSDeletedKeyVaultManagedStorageSasDefinition managedStorageSasDefinition = null;
7095
ConfirmAction(
7196
Force.IsPresent,

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ManagedStorageAccounts/SetAzureKeyVaultManagedStorageSasDefinition.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,40 @@ public class SetAzureKeyVaultManagedStorageSasDefinition : KeyVaultCmdletBase
2929
#region Parameter Set Names
3030

3131
private const string DefaultParameterSet = "Default";
32+
private const string ByInputObjectParameterSet = "ByInputObject";
3233

3334
#endregion
3435

3536
#region Input Parameter Definitions
3637
[Parameter( Mandatory = true,
3738
Position = 0,
38-
ValueFromPipelineByPropertyName = true,
3939
ParameterSetName = DefaultParameterSet,
4040
HelpMessage = "Vault name. Cmdlet constructs the FQDN of a vault based on the name and currently selected environment." )]
4141
[ValidateNotNullOrEmpty]
4242
public string VaultName { get; set; }
4343

4444
[Parameter( Mandatory = true,
4545
Position = 1,
46-
ValueFromPipelineByPropertyName = true,
4746
ParameterSetName = DefaultParameterSet,
4847
HelpMessage = "Key Vault managed storage account name. Cmdlet constructs the FQDN of a managed storage account name from vault name, currently " +
4948
"selected environment and manged storage account name." )]
5049
[ValidateNotNullOrEmpty]
5150
[Alias( Constants.StorageAccountName )]
5251
public string AccountName { get; set; }
5352

53+
/// <summary>
54+
/// PSKeyVaultManagedStorageAccountIdentityItem object
55+
/// </summary>
56+
[Parameter(Mandatory = true,
57+
Position = 0,
58+
ParameterSetName = ByInputObjectParameterSet,
59+
ValueFromPipeline = true,
60+
HelpMessage = "ManagedStorageAccount object.")]
61+
[ValidateNotNullOrEmpty]
62+
public PSKeyVaultManagedStorageAccountIdentityItem InputObject { get; set; }
63+
5464
[Parameter( Mandatory = true,
5565
Position = 2,
56-
ParameterSetName = DefaultParameterSet,
57-
ValueFromPipelineByPropertyName = true,
5866
HelpMessage = "Storage sas definition name. Cmdlet constructs the FQDN of a storage sas definition from vault name, currently " +
5967
"selected environment, storage account name and sas definition name." )]
6068
[ValidateNotNullOrEmpty]
@@ -64,16 +72,12 @@ public class SetAzureKeyVaultManagedStorageSasDefinition : KeyVaultCmdletBase
6472
[ValidateNotNullOrEmpty]
6573
[Parameter( Mandatory = true,
6674
Position = 3,
67-
ParameterSetName = DefaultParameterSet,
68-
ValueFromPipelineByPropertyName = false,
6975
HelpMessage = "Storage SAS definition template uri.")]
7076
public string TemplateUri { get; set; }
7177

7278
[ValidateNotNullOrEmpty]
7379
[Parameter( Mandatory = true,
7480
Position = 4,
75-
ParameterSetName = DefaultParameterSet,
76-
ValueFromPipelineByPropertyName = false,
7781
HelpMessage = "Storage SAS type.")]
7882
public string SasType { get; set; }
7983

@@ -82,21 +86,25 @@ public class SetAzureKeyVaultManagedStorageSasDefinition : KeyVaultCmdletBase
8286
public SwitchParameter Disable { get; set; }
8387

8488
[Parameter( Mandatory = false,
85-
ValueFromPipelineByPropertyName = true,
8689
HelpMessage = "A hashtable representing tags of sas definition." )]
8790
[Alias( Constants.TagsAlias )]
8891
public Hashtable Tag { get; set; }
8992

9093
private const string ValidityPeriodHelpMessage = "Validity period that will get used to set the expiry time of sas token from the time it gets generated";
9194
[Parameter( Mandatory = true,
92-
ParameterSetName = DefaultParameterSet,
9395
HelpMessage = ValidityPeriodHelpMessage)]
9496
[ValidateNotNull]
9597
public TimeSpan? ValidityPeriod { get; set; }
9698
#endregion
9799

98100
public override void ExecuteCmdlet()
99101
{
102+
if (InputObject != null)
103+
{
104+
VaultName = InputObject.VaultName;
105+
AccountName = InputObject.AccountName;
106+
}
107+
100108
if ( ShouldProcess( Name, Properties.Resources.SetManagedStorageSasDefinition ) )
101109
{
102110
var sasDefinition = DataServiceClient.SetManagedStorageSasDefinition(

0 commit comments

Comments
 (0)