Skip to content

Commit

Permalink
VMware shared functions #474
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Sep 29, 2023
1 parent 2322f83 commit 4a80a13
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Evergreen/Shared/Get-VMwareAPIPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function Get-VMwareAPIPath {
[CmdletBinding(SupportsShouldProcess = $false)]
[OutputType("System.String")]
param (
[Parameter(Mandatory = $false)]
[ValidateSet('products', 'dlg')]
[System.String] $Endpoint = "products"
)
$ApiPath = "https://customerconnect.vmware.com/channel/public/api/v1.0/${Endpoint}"
Write-Verbose -Message "$($MyInvocation.MyCommand): Return $ApiPath"
return $ApiPath
}
20 changes: 20 additions & 0 deletions Evergreen/Shared/Get-VMwareDLGDetailsQuery.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function Get-VMwareDLGDetailsQuery {
[OutputType("System.String")]
param (
[Parameter(Mandatory = $true)]
[System.String] $DownloadGroup,

[Parameter(Mandatory = $false)]
[System.String] $Locale = 'en_US'
)

$APIResource = 'details'
$queryParameters = @{
locale = $Locale
downloadGroup = $DownloadGroup
}
$queryString = ($queryParameters.GetEnumerator() | ForEach-Object { "&$($_.Key)=$($_.Value)" }) -join ''
$DlgQuery = "$(Get-VMwareAPIPath -Endpoint 'dlg')/$($APIResource)?$($queryString.TrimStart('&'))"
Write-Verbose -Message "$($MyInvocation.MyCommand): $DlgQuery"
return $DlgQuery
}
41 changes: 41 additions & 0 deletions Evergreen/Shared/Get-VMwareProductDownload.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function Get-VMwareProductDownload {
<#
.EXTERNALHELP Evergreen.VMware-help.xml
#>
param (
[Parameter(Mandatory = $true,
Position = 0,
ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[System.String[]] $Name
)

process {
foreach ($Product in $Name) {
$VMwareProduct = Get-VMwareProductList -Name $Product
$VMwareDLG = $VMwareProduct | Get-VMwareRelatedDLGList

foreach ($Dlg in $VMwareDLG) {
$params = @{
Uri = $(Get-VMwareDLGDetailsQuery -DownloadGroup $Dlg.code)
}
$DownloadFiles = $(Invoke-RestMethodWrapper @params).downloadFiles

foreach ($File in $DownloadFiles) {
if ([System.String]::IsNullOrEmpty($File.title)) {
}
else {
$Result = [PSCustomObject]@{
Version = $File.version
ReleaseDate = $([System.DateTime]::ParseExact($File.releaseDate, "yyyy-MM-dd", [System.Globalization.CultureInfo]::CurrentUICulture.DateTimeFormat))
Md5 = $File.md5checksum
Type = Get-FileType -File $File.fileName
URI = "https://download3.vmware.com/software/$($Dlg.code)/$($File.fileName)"
}
Write-Output -InputObject $Result
}
}
}
}
}
}
32 changes: 32 additions & 0 deletions Evergreen/Shared/Get-VMwareProductList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function Get-VMwareProductList {
<#
.EXTERNALHELP Evergreen.VMware-help.xml
#>
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $false)]
[System.String] $Name
)

$APIResource = 'getProductsAtoZ'
$params = @{
Uri = "$(Get-VMwareAPIPath)/${APIResource}"
}
$WebResult = Invoke-RestMethodWrapper @params

$FilteredProductList = $WebResult.productCategoryList.ProductList
if ($PSBoundParameters.ContainsKey('Name')) {
$FilteredProductList = $FilteredProductList | Where-Object -FilterScript { $_.Name -eq $Name }
}

$Result = $FilteredProductList | ForEach-Object -Process {
$Action = $_.actions | Where-Object -FilterScript { $_.linkname -eq "Download Product" }
[PSCustomObject]@{
Name = $_.Name
CategoryMap = $($Action.target -split '/')[-3]
ProductMap = $($Action.target -split '/')[-2]
VersionMap = $($Action.target -split '/')[-1]
}
}
Write-Output -InputObject $Result
}
42 changes: 42 additions & 0 deletions Evergreen/Shared/Get-VMwareRelatedDLGList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function Get-VMwareRelatedDLGList {
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $true,
Position = 0,
ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[System.String] $CategoryMap,

[Parameter(Mandatory = $true,
Position = 1,
ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[System.String] $ProductMap,

[Parameter(Mandatory = $true,
Position = 2,
ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[System.String] $VersionMap,

[Parameter(Mandatory = $false)]
[ValidateSet('PRODUCT_BINARY', 'DRIVERS_TOOLS', 'OPEN_SOURCE', 'CUSTOM_ISO', 'ADDONS')]
[System.String] $DLGType = 'PRODUCT_BINARY'
)

process {
$APIResource = 'getRelatedDLGList'
$queryParameters = @{
category = $CategoryMap
product = $ProductMap
version = $VersionMap
dlgType = $DLGType
}
$queryString = ( $queryParameters.GetEnumerator() | ForEach-Object { "&$($_.Key)=$($_.Value)" }) -join ''
$params = @{
Uri = "$(Get-VMwareAPIPath)/$($APIResource)?$($queryString.TrimStart('&'))"
}
$WebResult = Invoke-RestMethodWrapper @params
Write-Output -InputObject $WebResult.dlgEditionsLists.dlgList
}
}

0 comments on commit 4a80a13

Please sign in to comment.