Skip to content

Commit 8621c2c

Browse files
authored
Added parameter ContentType in Import-AzKeyVaultCertificate to support importing pem via certificate string (Azure#19174)
1 parent fb96063 commit 8621c2c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/KeyVault/KeyVault/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Added parameter `ContentType` in `Import-AzKeyVaultCertificate` to support importing pem via certificate string
2122
* Allowed `DnsName` in `New-AzKeyVaultCertificatePolicy` to accept an empty list [#18954]
2223

2324
## Version 4.6.1

src/KeyVault/KeyVault/Commands/Certificate/ImportAzureKeyVaultCertificate.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ public class ImportAzureKeyVaultCertificate : KeyVaultCmdletBase
8888
HelpMessage = "Base64 encoded representation of the certificate object to import. This certificate needs to contain the private key.")]
8989
public string CertificateString { get; set; }
9090

91+
/// <summary>
92+
/// Specifies type of the certificate to be imported.
93+
/// </summary>
94+
[Parameter(Mandatory = false,
95+
ParameterSetName = ImportWithPrivateKeyFromStringParameterSet,
96+
HelpMessage = "Specifies the type of the certificate to be imported. Regards certificate string as PFX format by default.")]
97+
[PSArgumentCompleter(Constants.Pkcs12ContentType, Constants.PemContentType)]
98+
public string ContentType { get; set; } = Constants.Pkcs12ContentType;
99+
91100
/// <summary>
92101
/// Password
93102
/// </summary>
@@ -190,7 +199,7 @@ public override void ExecuteCmdlet()
190199
break;
191200

192201
case ImportWithPrivateKeyFromStringParameterSet:
193-
certBundle = this.DataServiceClient.ImportCertificate(VaultName, Name, CertificateString, Password, Tag?.ConvertToDictionary());
202+
certBundle = this.Track2DataClient.ImportCertificate(VaultName, Name, CertificateString, Password, Tag?.ConvertToDictionary(), ContentType);
194203

195204
break;
196205
}

src/KeyVault/KeyVault/Track2Models/Track2KeyVaultDataServiceClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using System.Collections.Generic;
88
using System.Security;
99
using System.Security.Cryptography.X509Certificates;
10+
using System.Text;
11+
1012
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
1113

1214
namespace Microsoft.Azure.Commands.KeyVault.Track2Models
@@ -239,7 +241,7 @@ public IEnumerable<PSDeletedKeyVaultCertificateIdentityItem> GetDeletedCertifica
239241

240242
public PSKeyVaultCertificate ImportCertificate(string vaultName, string certName, string certificate, SecureString certPassword, IDictionary<string, string> tags, string contentType = Constants.Pkcs12ContentType)
241243
{
242-
throw new NotImplementedException();
244+
return VaultClient.ImportCertificate(vaultName, certName, Encoding.ASCII.GetBytes(certificate), certPassword, tags, contentType);
243245
}
244246

245247
public PSKeyVaultCertificate ImportCertificate(string vaultName, string certName, byte[] certificate, SecureString certPassword, IDictionary<string, string> tags, string contentType = Constants.Pkcs12ContentType)

0 commit comments

Comments
 (0)