Skip to content

Commit 0b3c654

Browse files
committed
adding support for listing pending certificates
1 parent e32b143 commit 0b3c654

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault/Commands.KeyVault.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<Compile Include="Commands\UndoAzureKeyVaultKeyRemoval.cs" />
9292
<Compile Include="Commands\UndoAzureKeyVaultSecretRemoval.cs" />
9393
<Compile Include="Commands\UpdateAzureKeyVaultSecret.cs" />
94+
<Compile Include="Models\KeyVaultCertificateFilterOptions.cs" />
9495
<Compile Include="Models\ManagedStorageAccounts\PSDeletedKeyVaultManagedStorageAccount.cs" />
9596
<Compile Include="Models\ManagedStorageAccounts\PSDeletedKeyVaultManagedStorageAccountIdentityItem.cs" />
9697
<Compile Include="Models\ManagedStorageAccounts\PSDeletedKeyVaultManagedStorageSasDefinition.cs" />

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ public class GetAzureKeyVaultCertificate : KeyVaultCmdletBase
186186
ParameterSetName = ResourceIdByVaultNameParameterSet,
187187
HelpMessage = "Specifies whether to show the previously deleted certificates in the output.")]
188188
public SwitchParameter InRemovedState { get; set; }
189+
190+
/// <summary>
191+
/// Switch specifying whether to include the pending certificates in the enumeration.
192+
/// </summary>
193+
[Parameter(Mandatory = false,
194+
ParameterSetName = ByVaultNameParameterSet,
195+
HelpMessage = "Specifies whether to include the pending certificates in the output.")]
196+
[Parameter(Mandatory = false,
197+
ParameterSetName = InputObjectByVaultNameParameterSet,
198+
HelpMessage = "Specifies whether to include the pending certificates in the output.")]
199+
[Parameter(Mandatory = false,
200+
ParameterSetName = ResourceIdByVaultNameParameterSet,
201+
HelpMessage = "Specifies whether to include the pending certificates in the output.")]
202+
public SwitchParameter IncludePending { get; set; }
189203
#endregion
190204

191205
public override void ExecuteCmdlet()
@@ -241,10 +255,11 @@ public override void ExecuteCmdlet()
241255

242256
private void GetAndWriteCertificates(string vaultName)
243257
{
244-
KeyVaultObjectFilterOptions options = new KeyVaultObjectFilterOptions
258+
var options = new KeyVaultCertificateFilterOptions
245259
{
246260
VaultName = VaultName,
247-
NextLink = null
261+
NextLink = null,
262+
IncludePending = IncludePending
248263
};
249264

250265
do
@@ -272,10 +287,11 @@ private void GetAndWriteCertificatesVersions(string vaultName, string name, stri
272287

273288
private void GetAndWriteDeletedCertificates( string vaultName )
274289
{
275-
KeyVaultObjectFilterOptions options = new KeyVaultObjectFilterOptions
290+
var options = new KeyVaultCertificateFilterOptions
276291
{
277292
VaultName = VaultName,
278-
NextLink = null
293+
NextLink = null,
294+
IncludePending = IncludePending
279295
};
280296

281297
do

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public interface IKeyVaultDataServiceClient
8585

8686
PSDeletedKeyVaultCertificate GetDeletedCertificate( string vaultName, string certName );
8787

88-
IEnumerable<PSKeyVaultCertificateIdentityItem> GetCertificates(KeyVaultObjectFilterOptions options);
88+
IEnumerable<PSKeyVaultCertificateIdentityItem> GetCertificates(KeyVaultCertificateFilterOptions options);
8989

90-
IEnumerable<PSDeletedKeyVaultCertificateIdentityItem> GetDeletedCertificates( KeyVaultObjectFilterOptions options );
90+
IEnumerable<PSDeletedKeyVaultCertificateIdentityItem> GetDeletedCertificates( KeyVaultCertificateFilterOptions options );
9191

9292
IEnumerable<PSKeyVaultCertificateIdentityItem> GetCertificateVersions(KeyVaultObjectFilterOptions options);
9393

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.KeyVault.Models
16+
{
17+
public sealed class KeyVaultCertificateFilterOptions : KeyVaultObjectFilterOptions
18+
{
19+
public bool? IncludePending { get; set; }
20+
}
21+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public PSKeyVaultKey GetKey(string vaultName, string keyName, string keyVersion)
340340
return new PSKeyVaultKey(keyBundle, this.vaultUriHelper);
341341
}
342342

343-
public IEnumerable<PSKeyVaultCertificateIdentityItem> GetCertificates(KeyVaultObjectFilterOptions options)
343+
public IEnumerable<PSKeyVaultCertificateIdentityItem> GetCertificates(KeyVaultCertificateFilterOptions options)
344344
{
345345
if (options == null)
346346
throw new ArgumentNullException(nameof(options));
@@ -355,7 +355,7 @@ public IEnumerable<PSKeyVaultCertificateIdentityItem> GetCertificates(KeyVaultOb
355355
IPage<CertificateItem> result;
356356

357357
if (string.IsNullOrEmpty(options.NextLink))
358-
result = this.keyVaultClient.GetCertificatesAsync(vaultAddress).GetAwaiter().GetResult();
358+
result = this.keyVaultClient.GetCertificatesAsync(vaultAddress, maxresults: null, includePending: options.IncludePending).GetAwaiter().GetResult();
359359
else
360360
result = this.keyVaultClient.GetCertificatesNextAsync(options.NextLink).GetAwaiter().GetResult();
361361

@@ -1667,7 +1667,7 @@ public PSDeletedKeyVaultCertificate GetDeletedCertificate( string vaultName, str
16671667
return new PSDeletedKeyVaultCertificate(deletedCertificate);
16681668
}
16691669

1670-
public IEnumerable<PSDeletedKeyVaultCertificateIdentityItem> GetDeletedCertificates( KeyVaultObjectFilterOptions options )
1670+
public IEnumerable<PSDeletedKeyVaultCertificateIdentityItem> GetDeletedCertificates( KeyVaultCertificateFilterOptions options )
16711671
{
16721672
if ( options == null )
16731673
throw new ArgumentNullException( nameof( options ) );
@@ -1681,7 +1681,7 @@ public IEnumerable<PSDeletedKeyVaultCertificateIdentityItem> GetDeletedCertifica
16811681
IPage<DeletedCertificateItem> result;
16821682

16831683
if ( string.IsNullOrEmpty( options.NextLink ) )
1684-
result = this.keyVaultClient.GetDeletedCertificatesAsync( vaultAddress ).GetAwaiter( ).GetResult( );
1684+
result = this.keyVaultClient.GetDeletedCertificatesAsync( vaultAddress, maxresults: null, includePending: options.IncludePending ).GetAwaiter( ).GetResult( );
16851685
else
16861686
result = this.keyVaultClient.GetDeletedCertificatesNextAsync( options.NextLink ).GetAwaiter( ).GetResult( );
16871687

0 commit comments

Comments
 (0)