53 lines
2.1 KiB
PowerShell
53 lines
2.1 KiB
PowerShell
|
function Test-ServiceManifestRequiresDbAccess {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Used by both categorization and installer package to denote that the manifest requires db access
|
||
|
Using it in both places allows us to change/update the logic if we need to in the future.
|
||
|
|
||
|
.PARAMETER ServiceManifest
|
||
|
[object] <packageManifest><serviceManifest> childnode or equivalent json dotted child
|
||
|
#>
|
||
|
[CmdletBinding()]
|
||
|
[OutputType([bool])]
|
||
|
param (
|
||
|
[object]$ServiceManifest
|
||
|
)
|
||
|
|
||
|
$logLead = Get-LogLeadName
|
||
|
|
||
|
# this lets the categorizer pass in an empty or null node to reduce complexity of testing
|
||
|
# Additionally, a bad value clearly means we don't need to check with the database
|
||
|
if ($null -eq $ServiceManifest) {
|
||
|
return $false
|
||
|
}
|
||
|
|
||
|
# These are necessary for running any migrations etc
|
||
|
$migrationsAssemblies = @($ServiceManifest.migrations.assembly).Where({$null -ne $_})
|
||
|
$migrationsPackages = @($ServiceManifest.migrations.package).Where({$null -ne $_})
|
||
|
$dbRole = $ServiceManifest.db_role
|
||
|
|
||
|
$hasMigrationAssemblies = (!(Test-IsCollectionNullOrEmpty -Collection $migrationsAssemblies))
|
||
|
$hasMigrationPackages = (!(Test-IsCollectionNullOrEmpty -Collection $migrationsPackages))
|
||
|
$hasDbRole = ![string]::IsNullOrWhiteSpace($dbRole)
|
||
|
$hasAssemblyRole = $false
|
||
|
foreach($assembly in $migrationsAssemblies){
|
||
|
if(!(Test-StringIsNullOrWhiteSpace($assembly.role))){
|
||
|
$hasAssemblyRole = $true
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# If there is a db role, or an assembly role, or packages then there's no database access required
|
||
|
if ($hasDbRole -or $hasAssemblyRole -or $hasMigrationPackages) {
|
||
|
$databaseAccessRequired = $true
|
||
|
} else {
|
||
|
$databaseAccessRequired = $false
|
||
|
}
|
||
|
|
||
|
Write-Host "$logLead : Service has migration assemblies [$hasMigrationAssemblies]"
|
||
|
Write-Host "$logLead : Service has migration packages [$hasMigrationPackages]"
|
||
|
Write-Host "$logLead : Service has dbRole [$hasDbRole]"
|
||
|
Write-Host "$logLead : Service requires database access [$databaseAccessRequired] <-- returned value"
|
||
|
|
||
|
return $databaseAccessRequired
|
||
|
}
|