public void CanRemoveSecretWithPassThruTest() { SecureString secureSecretValue = SecretValue.ConvertToSecureString(); PSDeletedKeyVaultSecret expected = new PSDeletedKeyVaultSecret() { Name = SecretName, VaultName = VaultName, SecretValue = secureSecretValue }; keyVaultClientMock.Setup(kv => kv.DeleteSecret(VaultName, SecretName)).Returns(expected).Verifiable(); // Mock the should process to return true commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny <string>())).Returns(true); cmdlet.Name = SecretName; cmdlet.Force = true; cmdlet.PassThru = true; cmdlet.ExecuteCmdlet(); keyVaultClientMock.VerifyAll(); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); //No force but should continue commandRuntimeMock.Setup(cr => cr.ShouldProcess(SecretName, It.IsAny <string>())).Returns(true); commandRuntimeMock.Setup(cr => cr.ShouldContinue(It.IsAny <string>(), It.IsAny <string>())).Returns(true); cmdlet.Force = false; cmdlet.PassThru = true; cmdlet.ExecuteCmdlet(); keyVaultClientMock.VerifyAll(); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Exactly(2)); }
public override void ExecuteCmdlet() { PSKeyVaultSecret secret; if (InputObject != null) { VaultName = InputObject.VaultName.ToString(); } else if (!string.IsNullOrEmpty(ResourceId)) { var parsedResourceId = new ResourceIdentifier(ResourceId); VaultName = parsedResourceId.ResourceName; } if (!string.IsNullOrEmpty(Version)) { secret = DataServiceClient.GetSecret(VaultName, Name, Version); WriteObject(secret); } else if (IncludeVersions) { secret = DataServiceClient.GetSecret(VaultName, Name, string.Empty); if (secret != null) { WriteObject(new PSKeyVaultSecretIdentityItem(secret)); GetAndWriteSecretVersions(VaultName, Name, secret.Version); } } else if (InRemovedState) { if (Name == null) { GetAndWriteDeletedSecrets(VaultName); } else { PSDeletedKeyVaultSecret deletedSecret = DataServiceClient.GetDeletedSecret(VaultName, Name); WriteObject(deletedSecret); } } else { if (string.IsNullOrEmpty(Name)) { GetAndWriteSecrets(VaultName); } else { secret = DataServiceClient.GetSecret(VaultName, Name, string.Empty); WriteObject(secret); } } }
public override void ExecuteCmdlet() { if (InputObject != null) { VaultName = InputObject.VaultName; Name = InputObject.Name; } if (InRemovedState.IsPresent) { ConfirmAction( Force.IsPresent, string.Format( CultureInfo.InvariantCulture, Resources.RemoveDeletedSecretWarning, Name), string.Format( CultureInfo.InvariantCulture, Resources.RemoveDeletedSecretWhatIfMessage, Name), Name, () => { DataServiceClient.PurgeSecret(VaultName, Name); }); return; } PSDeletedKeyVaultSecret deletedSecret = null; ConfirmAction( Force.IsPresent, string.Format( CultureInfo.InvariantCulture, Resources.RemoveSecretWarning, Name), string.Format( CultureInfo.InvariantCulture, Resources.RemoveSecretWhatIfMessage, Name), Name, () => { deletedSecret = DataServiceClient.DeleteSecret(VaultName, Name); }); if (PassThru) { WriteObject(deletedSecret); } }