Skip to content

Commit a8b3c4c

Browse files
author
Dragos Avadanei
committed
Reverting Certificate cmdlets to use PSH-defined types
1 parent c083c5f commit a8b3c4c

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/VaultManagementTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ function Initialize-TemporaryState
373373
"objectId" = $objectId
374374
"applicationId" = ""
375375
"permissions" = @{
376-
"keys" = @("all")
377-
"secrets" = @("all")
378-
"certificates" = @("all")
376+
"keys" = @("all", "purge")
377+
"secrets" = @("all", "purge")
378+
"certificates" = @("all", "purge")
379379
"storage" = @("all")
380380
}
381381
}

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/GetAzureKeyVaultCertificate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.KeyVault
2828
[Cmdlet(VerbsCommon.Get, CmdletNoun.AzureKeyVaultCertificate,
2929
DefaultParameterSetName = ByVaultNameParameterSet,
3030
HelpUri = Constants.KeyVaultHelpUri)]
31-
[OutputType(typeof(List<CertificateIdentityItem>), typeof(KeyVaultCertificate), typeof(DeletedCertificateBundle), typeof(List<DeletedCertificateIdentityItem>))]
31+
[OutputType(typeof(List<CertificateIdentityItem>), typeof(KeyVaultCertificate), typeof(DeletedKeyVaultCertificate), typeof(List<DeletedCertificateIdentityItem>))]
3232
public class GetAzureKeyVaultCertificate : KeyVaultCmdletBase
3333
{
3434
#region Parameter Set Names
@@ -131,7 +131,7 @@ protected override void ProcessRecord()
131131
break;
132132
}
133133

134-
DeletedCertificateBundle deletedCert = DataServiceClient.GetDeletedCertificate(VaultName, Name);
134+
DeletedKeyVaultCertificate deletedCert = DeletedKeyVaultCertificate.FromDeletedCertificateBundle( DataServiceClient.GetDeletedCertificate(VaultName, Name) );
135135
WriteObject( deletedCert );
136136

137137
break;

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/RemoveAzureKeyVaultCertificate.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using System.Management.Automation;
1717
using Microsoft.Azure.Commands.KeyVault.Models;
1818
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
19-
using Microsoft.Azure.KeyVault.Models;
2019

2120
namespace Microsoft.Azure.Commands.KeyVault
2221
{
@@ -27,7 +26,7 @@ namespace Microsoft.Azure.Commands.KeyVault
2726
SupportsShouldProcess = true,
2827
ConfirmImpact = ConfirmImpact.High,
2928
HelpUri = Constants.KeyVaultHelpUri)]
30-
[OutputType(typeof(DeletedCertificateBundle))]
29+
[OutputType(typeof(DeletedKeyVaultCertificate))]
3130
public class RemoveAzureKeyVaultCertificate : KeyVaultCmdletBase
3231
{
3332
#region Input Parameter Definitions
@@ -55,7 +54,8 @@ public class RemoveAzureKeyVaultCertificate : KeyVaultCmdletBase
5554
/// <summary>
5655
/// If present, do not ask for confirmation
5756
/// </summary>
58-
[Parameter(HelpMessage = "Do not ask for confirmation.")]
57+
[Parameter( Mandatory = false,
58+
HelpMessage = "Do not ask for confirmation.")]
5959
public SwitchParameter Force { get; set; }
6060

6161
/// <summary>
@@ -65,7 +65,8 @@ public class RemoveAzureKeyVaultCertificate : KeyVaultCmdletBase
6565
HelpMessage = "Permanently remove the previously deleted certificate." )]
6666
public SwitchParameter InRemovedState { get; set; }
6767

68-
[Parameter(HelpMessage = "Cmdlet does not return an object by default. If this switch is specified, the cmdlet returns the certificate object that was deleted.")]
68+
[Parameter( Mandatory = false,
69+
HelpMessage = "Cmdlet does not return an object by default. If this switch is specified, the cmdlet returns the certificate object that was deleted.")]
6970
public SwitchParameter PassThru { get; set; }
7071

7172
#endregion
@@ -90,7 +91,7 @@ protected override void ProcessRecord()
9091
return;
9192
}
9293

93-
DeletedCertificateBundle certBundle = null;
94+
DeletedKeyVaultCertificate certBundle = null;
9495

9596
ConfirmAction(
9697
Force.IsPresent,
@@ -103,7 +104,7 @@ protected override void ProcessRecord()
103104
KeyVaultProperties.Resources.RemoveCertWhatIfMessage,
104105
Name),
105106
Name,
106-
() => { certBundle = this.DataServiceClient.DeleteCertificate(VaultName, Name); });
107+
() => { certBundle = DeletedKeyVaultCertificate.FromDeletedCertificateBundle( this.DataServiceClient.DeleteCertificate(VaultName, Name) ); });
107108

108109
if (PassThru.IsPresent)
109110
{

src/ResourceManager/KeyVault/Commands.KeyVault/Models/KeyVaultCertificate.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
namespace Microsoft.Azure.Commands.KeyVault.Models
2121
{
22-
public class KeyVaultCertificate
22+
public class KeyVaultCertificate
2323
{
2424
public string Name { get; set; }
25+
public string VaultName { get; set; }
2526
public X509Certificate2 Certificate { get; set; }
2627
public string Id { get; internal set; }
2728
public string KeyId { get; internal set; }
@@ -46,6 +47,12 @@ public KeyVaultCertificate( CertificateBundle certificateBundle )
4647
{
4748
Id = certificateBundle.CertificateIdentifier.Identifier;
4849
Name = certificateBundle.CertificateIdentifier.Name;
50+
51+
// TODO [dragosav] Bring Certificate classes on par with keys/secrets:
52+
// - inherit from ObjectIdentifier
53+
// - constructors should accept the VaultUriHelper as a parameter
54+
var vaultUri = new Uri( certificateBundle.CertificateIdentifier.Vault );
55+
VaultName = vaultUri.Host.Split( '.' ).First( );
4956
}
5057

5158
if ( certificateBundle.Cer != null )

0 commit comments

Comments
 (0)