104 lines
4.0 KiB
PowerShell
104 lines
4.0 KiB
PowerShell
function Test-AlkamiServiceManifest10 {
|
|
<#
|
|
.SYNOPSIS
|
|
Please don't use this file by hand, please use Test-AlkamiManifest
|
|
This function is intended to validate the ServiceManifest dotted object/hashtable so we can ensure that the values provided meet a minimum standard of valid
|
|
|
|
.PARAMETER ServiceManifest
|
|
A dotted object ([xml](Get-Content -Path $somePath)) or hashtable of values
|
|
#>
|
|
[CmdletBinding()]
|
|
[OutputType([System.Collections.Hashtable])]
|
|
Param(
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[object]$ServiceManifest
|
|
)
|
|
|
|
$success = $true
|
|
$resultMessages = @()
|
|
$validServiceRuntimes = @('core', 'dotnetcore', 'legacy', 'framework')
|
|
|
|
if ([string]::IsNullOrWhiteSpace($ServiceManifest.runtime)) {
|
|
$resultMessages += "packageManifest/serviceManifest/runtime must be non-empty"
|
|
$success = $false
|
|
}
|
|
|
|
if (-not ($validServiceRuntimes -contains $ServiceManifest.runtime)) {
|
|
$resultMessages += "packageManifest/serviceManifest/runtime must be one of these values: $($validServiceRuntimes -join ',')"
|
|
$success = $false
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($ServiceManifest.entryPoint)) {
|
|
$resultMessages += "packageManifest/serviceManifest/entryPoint must be non-empty"
|
|
$success = $false
|
|
}
|
|
|
|
$migrations = $ServiceManifest.migrations
|
|
|
|
# Assembly checks
|
|
if ($migrations -and $migrations.assembly) {
|
|
# We should have EITHER assemblies OR packages
|
|
if ($migrations.package) {
|
|
$resultMessages += "packageManifest/serviceManifest/migrations can only have an assembly, or a package list. Not both."
|
|
$success = $false
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($migrations.assembly.target)) {
|
|
$resultMessages += "packageManifest/serviceManifest/migrations/assembly/target must be non-empty, if a migration and assembly are provided."
|
|
$success = $false
|
|
}
|
|
}
|
|
|
|
if ($migrations -and -not $migrations.assembly) {
|
|
# If we have no packages, we expect assemblies.
|
|
if (-not $migrations.package) {
|
|
$resultMessages += "packageManifest/serviceManifest/migrations must have one or more assembly, or package specified"
|
|
$success = $false
|
|
}
|
|
}
|
|
|
|
$provider = $ServiceManifest.provider
|
|
if ($provider) {
|
|
if ([string]::IsNullOrWhiteSpace($provider.providerName)) {
|
|
$resultMessages += "packageManifest/serviceManifest/provider/providerName must be non-empty, if a provider node is provided."
|
|
$success = $false
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($provider.providerType)) {
|
|
$resultMessages += "packageManifest/serviceManifest/provider/providerType must be non-empty, if a provider node is provided."
|
|
$success = $false
|
|
}
|
|
}
|
|
|
|
$foundSomePackages = $false
|
|
$packageErrors = @()
|
|
foreach ($package in $migrations.package) {
|
|
$foundSomePackages = $true
|
|
if ([string]::IsNullOrWhiteSpace($package.id)) {
|
|
$packageErrors += "Found an empty packageid value in the manifest for migrations"
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($package.version)) {
|
|
if (-not [string]::IsNullOrWhiteSpace($package.id)) {
|
|
$packageErrors += "Found an empty/missing package version value in the manifest for package id $($package.id)"
|
|
} else {
|
|
$packageErrors += "Found an empty/missing packageid value in the manifest"
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($foundSomePackages -and $packageErrors) {
|
|
$resultMessages += ($packageErrors -join '`n')
|
|
$success = $false
|
|
}
|
|
|
|
if (($null -ne $ServiceManifest.db_role) -and [string]::IsNullOrWhiteSpace($ServiceManifest.db_role)) {
|
|
$resultMessages += "packageManifest/serviceManifest/db_role must be populated when provided"
|
|
$success = $false
|
|
}
|
|
|
|
return @{
|
|
success = $success
|
|
results = $resultMessages
|
|
}
|
|
} |