From d828a2daaa4fba24d9c8b8b532c978a02d4e8a5b Mon Sep 17 00:00:00 2001 From: Greg Brownstein Date: Thu, 28 Nov 2024 08:45:42 -0500 Subject: [PATCH] api deprecation (#308) --- RELEASE.md | 7 ++--- VenafiPS/Private/Get-VcData.ps1 | 24 +++++++-------- VenafiPS/Public/Get-VcConnector.ps1 | 29 ++----------------- VenafiPS/Public/Get-VcMachine.ps1 | 6 +--- VenafiPS/Public/New-VcMachine.ps1 | 20 ++++++------- .../Public/New-VcMachineCommonKeystore.ps1 | 2 +- VenafiPS/Public/New-VcMachineIis.ps1 | 2 +- VenafiPS/VenafiPS.psm1 | 2 +- 8 files changed, 31 insertions(+), 61 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index d6d4cf3c..54f6f0cb 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,2 @@ -- Add `Get-VcSatelliteWorker`, either all, by id or all workers associated with a specific satellite -- Add `Remove-VcSatelliteWorker`, you guessed it...removes vsat workers -- Add `Get-VcSatellite -IncludeWorkers` to get vsats and their associated workers in one call. -- Add `Invoke-VcCertificateAction -Provision` to push a certificate to associated machine identities. You can also use `-Renew -Provision` together and it will renew and then provision the new certificate. -- Add `Set-VcApplication -IssuingTemplate` to add one or more issuing templates to an application. It will overwrite by default or use `-NoOverwrite` to append. \ No newline at end of file +- Fix bogus error during `New-VcMachineCommonKeystore` [#304](https://github.com/Venafi/VenafiPS/issues/304) +- Update VC machine creation components due to API deprecation \ No newline at end of file diff --git a/VenafiPS/Private/Get-VcData.ps1 b/VenafiPS/Private/Get-VcData.ps1 index 4e943a65..1ef50796 100644 --- a/VenafiPS/Private/Get-VcData.ps1 +++ b/VenafiPS/Private/Get-VcData.ps1 @@ -15,13 +15,9 @@ function Get-VcData { [string] $InputObject, [parameter(Mandatory)] - [ValidateSet('Application', 'MachineType', 'VSatellite', 'Certificate', 'IssuingTemplate', 'Team', 'Machine', 'Tag')] + [ValidateSet('Application', 'VSatellite', 'Certificate', 'IssuingTemplate', 'Team', 'Machine', 'Tag', 'MachinePlugin', 'CaPlugin', 'TppPlugin')] [string] $Type, - # [parameter()] - # [ValidateSet('InputObject', 'Name', 'Object', 'First')] - # [string] $OutType = 'InputObject', - [parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'Name')] [switch] $Name, @@ -44,7 +40,7 @@ function Get-VcData { process { - # if we already have a guid, just return it + # if we already have a guid and are just looking for the ID, return it if ( $PSCmdlet.ParameterSetName -eq 'ID' -and (Test-IsGuid($InputObject)) ) { return $InputObject } @@ -98,7 +94,9 @@ function Get-VcData { $thisObject = $allObject | Where-Object { $InputObject -in $_.name, $_.teamId } } - 'MachineType' { + { $_ -match 'Plugin$' } { + # for machine, ca, tpp, etc plugins + # if ( -not $script:vcMachineType ) { # $script:vcMachineType = Invoke-VenafiRestMethod -UriLeaf 'machinetypes' | # Select-Object -ExpandProperty machineTypes | @@ -108,11 +106,13 @@ function Get-VcData { # $allObject = $script:vcMachineType # $thisObject = $script:vcMachineType | Where-Object { $InputObject -in $_.machineType, $_.machineTypeId } - $allObject = Invoke-VenafiRestMethod -UriLeaf 'machinetypes' | - Select-Object -ExpandProperty machineTypes | - Select-Object -Property @{'n' = 'machineTypeId'; 'e' = { $_.Id } }, * -ExcludeProperty id | - Sort-Object -Property machineType - $thisObject = $allObject | Where-Object { $InputObject -in $_.machineType, $_.machineTypeId } + $pluginType = $_.Replace('Plugin', '').ToUpper() + + $allObject = Invoke-VenafiRestMethod -UriLeaf "plugins?pluginType=$pluginType" | + Select-Object -ExpandProperty plugins | + Select-Object -Property @{'n' = ('{0}Id' -f $Type); 'e' = { $_.Id } }, * -ExcludeProperty id + + $thisObject = $allObject | Where-Object { $InputObject -in $_.name, $_.('{0}Id' -f $Type) } } 'Certificate' { diff --git a/VenafiPS/Public/Get-VcConnector.ps1 b/VenafiPS/Public/Get-VcConnector.ps1 index 6ecb5045..7a468441 100644 --- a/VenafiPS/Public/Get-VcConnector.ps1 +++ b/VenafiPS/Public/Get-VcConnector.ps1 @@ -4,7 +4,7 @@ Get connector info .DESCRIPTION - Get details on 1 or all connectors + Get details on 1 or all connectors associated with your tenant .PARAMETER Connector Connector ID or name @@ -18,31 +18,7 @@ A TLSPC key can also provided. .INPUTS - ID - - .EXAMPLE - Get-VcConnector -Connector 'ca7ff555-88d2-4bfc-9efa-2630ac44c1f2' | ConvertTo-Json - - { - "connectorId": "a7ddd210-0a39-11ee-8763-134b935c90aa", - "name": "ServiceNow-expiry, - "properties": { - "connectorKind": "WEBHOOK", - "filter": { - "filterType": "EXPIRATION", - "applicationIds": [] - }, - "target": { - "type": "generic", - "connection": { - "secret": "MySecret", - "url": "https://instance.service-now.com/api/company/endpoint" - } - } - } - } - - Get a single object by ID + Connector .EXAMPLE Get-VcConnector -Connector 'My Connector' @@ -92,6 +68,7 @@ } } else { + # getting all by default excludes disabled connectors so let's include them $params.Body = @{'includeDisabled' = $true } } diff --git a/VenafiPS/Public/Get-VcMachine.ps1 b/VenafiPS/Public/Get-VcMachine.ps1 index 013d25cc..50f57fde 100644 --- a/VenafiPS/Public/Get-VcMachine.ps1 +++ b/VenafiPS/Public/Get-VcMachine.ps1 @@ -140,6 +140,7 @@ if ( Test-IsGuid($Machine) ) { try { $response = Invoke-VenafiRestMethod -UriLeaf ('machines/{0}' -f $Machine) + $response | Select-Object @{ 'n' = 'machineId'; 'e' = { $_.Id } }, * -ExcludeProperty Id } catch { if ( $_.Exception.Response.StatusCode.value__ -eq 404 ) { @@ -155,11 +156,6 @@ # no lookup by name directly. search for it and then get details Find-VcObject -Type 'Machine' -Name $Machine | Get-VcMachine } - - if ( $response ) { - $response | Select-Object @{ 'n' = 'machineId'; 'e' = { $_.Id } }, * -ExcludeProperty Id - } } - } } diff --git a/VenafiPS/Public/New-VcMachine.ps1 b/VenafiPS/Public/New-VcMachine.ps1 index cc1f2d81..a7f5e943 100644 --- a/VenafiPS/Public/New-VcMachine.ps1 +++ b/VenafiPS/Public/New-VcMachine.ps1 @@ -15,7 +15,7 @@ function New-VcMachine { .PARAMETER MachineType Machine type by either ID or name, eg. 'Citrix ADC'. - A list can be found by create a new session and executing $VenafiSession.MachineType. + Get a list of available types by running `Get-VcConnector -All` and looking for connectorType is MACHINE. .PARAMETER VSatellite ID or name of a vsatellite. @@ -110,7 +110,7 @@ function New-VcMachine { .NOTES To see a full list of tab-completion options, be sure to set the Tab option, Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete. - This function requires the use of sodium encryption. + This function requires the use of sodium encryption via PSSodium, https://github.com/TylerLeonhardt/PSSodium, to be installed. .net standard 2.0 or greater is required via PS Core (recommended) or supporting .net runtime. On Windows, the latest Visual C++ redist must be installed. See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist. #> @@ -176,23 +176,24 @@ function New-VcMachine { Initialize-PSSodium $allMachines = [System.Collections.Generic.List[hashtable]]::new() - - if ( $Credential ) { - if ( $MachineType -in 'c1521d80-db7a-11ec-b79a-f3ded6c9808c', 'Microsoft IIS' ) { throw 'To create IIS machines, please use New-VcMachineIis' } - if ( $MachineType -in '575389b0-e6be-11ec-9172-d3c56ea8bcf6', 'Common Keystore (PEM, JKS, PKCS#12)' ) { throw 'To create Common Keystore machines, please use New-VcMachineCommonKeystore' } - } } process { Write-Verbose $PSCmdlet.ParameterSetName - $thisMachineType = Get-VcData -InputObject $MachineType -Type 'MachineType' -Object + $thisMachineType = Get-VcData -InputObject $MachineType -Type 'MachinePlugin' -Object if ( -not $thisMachineType ) { Write-Error "'$MachineType' is not a valid machine type id or name" return } + if ( $PSCmdlet.ParameterSetName -eq 'BasicMachine' ) { + if ( $thisMachineType.name -in 'Microsoft IIS', 'Common Keystore (PEM, JKS, PKCS#12)' ) { + throw 'To create IIS or Common Keystore machines, please use the dedicated function.' + } + } + $ownerId = Get-VcData -InputObject $Owner -Type 'Team' if ( -not $ownerId ) { Write-Error "'$Owner' is not a valid team id or name" @@ -242,8 +243,7 @@ function New-VcMachine { name = $Name edgeInstanceId = $thisEdgeInstanceId dekId = $thisDekId - machineTypeId = $thisMachineType.machineTypeId - pluginId = $thisMachineType.pluginId + pluginId = $thisMachineType.machinePluginId owningTeamId = $ownerId connectionDetails = $thisConnectionDetail } diff --git a/VenafiPS/Public/New-VcMachineCommonKeystore.ps1 b/VenafiPS/Public/New-VcMachineCommonKeystore.ps1 index e5a527c8..9c9e2d43 100644 --- a/VenafiPS/Public/New-VcMachineCommonKeystore.ps1 +++ b/VenafiPS/Public/New-VcMachineCommonKeystore.ps1 @@ -190,7 +190,7 @@ function New-VcMachineCommonKeystore { Test-VenafiSession -VenafiSession $VenafiSession -Platform 'VC' $allMachines = [System.Collections.Generic.List[pscustomobject]]::new() - $machineTypeId = '575389b0-e6be-11ec-9172-d3c56ea8bcf6' + $machineTypeId = Get-VcData -InputObject 'Common KeyStore (PEM, JKS, PKCS#12)' -Type 'MachinePlugin' Initialize-PSSodium } diff --git a/VenafiPS/Public/New-VcMachineIis.ps1 b/VenafiPS/Public/New-VcMachineIis.ps1 index cbdebd96..e03600de 100644 --- a/VenafiPS/Public/New-VcMachineIis.ps1 +++ b/VenafiPS/Public/New-VcMachineIis.ps1 @@ -168,7 +168,7 @@ function New-VcMachineIis { Test-VenafiSession -VenafiSession $VenafiSession -Platform 'VC' $allMachines = [System.Collections.Generic.List[pscustomobject]]::new() - $machineTypeId = 'c1521d80-db7a-11ec-b79a-f3ded6c9808c' + $machineTypeId = Get-VcData -InputObject 'Microsoft IIS' -Type 'MachinePlugin' Initialize-PSSodium } diff --git a/VenafiPS/VenafiPS.psm1 b/VenafiPS/VenafiPS.psm1 index e70233ff..2ca79b29 100644 --- a/VenafiPS/VenafiPS.psm1 +++ b/VenafiPS/VenafiPS.psm1 @@ -83,7 +83,7 @@ $vcGenericArgCompleterSb = { 'MachineType' { if ( -not $script:vcMachineType ) { - $script:vcMachineType = Invoke-VenafiRestMethod -UriLeaf 'machinetypes' | + $script:vcMachineType = Invoke-VenafiRestMethod -UriLeaf 'plugins?pluginType=MACHINE' | Select-Object -ExpandProperty machineTypes | Select-Object -Property @{'n' = 'machineTypeId'; 'e' = { $_.Id } }, * -ExcludeProperty id | Sort-Object -Property machineType