Skip to content

Commit

Permalink
-Force parameter for Revoke functions (#18)
Browse files Browse the repository at this point in the history
* -force for revoke functions

* changelog update

* small help update

* help update

* pssa fixes

* wakey wakey GitHub Actions

* help update

* pssa fix
  • Loading branch information
gdbarron authored Jul 21, 2021
1 parent 6c95aed commit ce1ec62
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.1.3
- Add `-Force` parameter to `Revoke-TppToken` and `Revoke-TppCertificate` to bypass confirmation prompt

## 3.1.2
- Add `-EventId` parameter to `Read-TppLog` to filter by a specific event id.
- Add EventId to `Read-TppLog` output. The value matches the hex value seen in Event Definitions in TPP.
Expand Down
18 changes: 9 additions & 9 deletions VenafiPS/Private/New-HttpQueryString.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
.LINK
https://powershellmagazine.com/2019/06/14/pstip-a-better-way-to-generate-http-query-strings-in-powershell/
#>
function New-HttpQueryString
{
function New-HttpQueryString {
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'No state is actually changing')]

[CmdletBinding()]
param
param
(
[Parameter(Mandatory = $true)]
[String]
Expand All @@ -19,18 +20,17 @@ function New-HttpQueryString
)
# Add System.Web
Add-Type -AssemblyName System.Web

# Create a http name value collection from an empty string
$nvCollection = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)

foreach ($key in $QueryParameter.Keys)
{

foreach ($key in $QueryParameter.Keys) {
$nvCollection.Add($key, $QueryParameter.$key)
}

# Build the uri
$uriRequest = [System.UriBuilder]$uri
$uriRequest.Query = $nvCollection.ToString()

return $uriRequest.Uri.OriginalString
}
2 changes: 1 addition & 1 deletion VenafiPS/Public/New-VenafiSession.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function New-VenafiSession {
# [pscustomobject] $TppToken,

# [Parameter(Mandatory, ParameterSetName = 'TppToken', ValueFromPipelineByPropertyName)]
[Parameter(Mandatory, ParameterSetName = 'AccessToken', ValueFromPipelineByPropertyName)]
[Parameter(Mandatory, ParameterSetName = 'AccessToken')]
[PSCredential] $AccessToken,

[Parameter(Mandatory, ParameterSetName = 'TokenCertificate')]
Expand Down
27 changes: 16 additions & 11 deletions VenafiPS/Public/Revoke-TppCertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Provide this switch to mark the certificate as disabled and no new certificate w
.PARAMETER Wait
Wait for the requested revocation to be complete
.PARAMETER Force
Bypass the confirmation prompt
.PARAMETER VenafiSession
Session object created from New-VenafiSession method. The value defaults to the script session object $VenafiSession.
Expand All @@ -48,6 +51,10 @@ PSCustomObject with the following properties:
$cert | Revoke-TppCertificate -Reason 2
Revoke the certificate with a reason of the CA being compromised
.EXAMPLE
$cert | Revoke-TppCertificate -Force
Revoke the certificate bypassing the confirmation prompt
.EXAMPLE
Revoke-TppCertificate -Path '\VED\Policy\My folder\app.mycompany.com' -Reason 2 -Wait
Revoke the certificate with a reason of the CA being compromised and wait for it to complete
Expand All @@ -63,13 +70,10 @@ https://docs.venafi.com/Docs/20.4SDK/TopNav/Content/SDK/WebSDK/r-SDK-POST-Certif
#>
function Revoke-TppCertificate {
[CmdletBinding(DefaultParameterSetName = 'ByObject', SupportsShouldProcess, ConfirmImpact = 'High')]
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
param (

[Parameter(Mandatory, ParameterSetName = 'ByObject', ValueFromPipeline)]
[TppObject] $InputObject,

[Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'ByPath')]
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[ValidateScript( {
if ( $_ | Test-TppDnPath ) {
Expand All @@ -95,6 +99,9 @@ function Revoke-TppCertificate {
[Parameter()]
[Switch] $Wait,

[Parameter()]
[switch] $Force,

[Parameter()]
[VenafiSession] $VenafiSession = $script:VenafiSession
)
Expand All @@ -112,12 +119,6 @@ function Revoke-TppCertificate {

process {

Write-Verbose $PsCmdlet.ParameterSetName

if ( $PSBoundParameters.ContainsKey('InputObject') ) {
$path = $InputObject.Path
}

Write-Verbose "Revoking $Path..."

$params.Body = @{
Expand All @@ -136,6 +137,10 @@ function Revoke-TppCertificate {
$params.Body.Disable = $true
}

if ( $Force ) {
$ConfirmPreference = 'None'
}

if ( $PSCmdlet.ShouldProcess($Path, 'Revoke certificate') ) {
$response = Invoke-TppRestMethod @params

Expand Down
20 changes: 17 additions & 3 deletions VenafiPS/Public/Revoke-TppToken.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@ Access token to be revoked. Provide a credential object with the access token a
.PARAMETER TppToken
Token object obtained from New-TppToken
.PARAMETER Force
Bypass the confirmation prompt
.PARAMETER VenafiSession
Session object created from New-VenafiSession method. The value defaults to the script session object $VenafiSession.
.INPUTS
TppToken
.OUTPUTS
Version
none
.EXAMPLE
Revoke-TppToken
Revoke token stored in session variable from New-VenafiSession
Revoke token stored in session variable $VenafiSession from New-VenafiSession
.EXAMPLE
Revoke-TppToken -Force
Revoke token bypassing confirmation prompt
.EXAMPLE
Revoke-TppToken -AuthServer venafi.company.com -AccessToken $cred
Expand Down Expand Up @@ -65,6 +72,9 @@ function Revoke-TppToken {
[Parameter(Mandatory, ParameterSetName = 'TppToken', ValueFromPipeline)]
[pscustomobject] $TppToken,

[Parameter()]
[switch] $Force,

[Parameter(ParameterSetName = 'Session')]
[VenafiSession] $VenafiSession = $script:VenafiSession
)
Expand Down Expand Up @@ -114,7 +124,11 @@ function Revoke-TppToken {

Write-Verbose ($params | Out-String)

if ( $PSCmdlet.ShouldProcess($target, 'Revoke token') ) {
if ( $Force ) {
$ConfirmPreference = 'None'
}

if ( $PSCmdlet.ShouldProcess($target) ) {
Invoke-TppRestMethod @params
}
}
Expand Down

0 comments on commit ce1ec62

Please sign in to comment.