PSAutoRBAC.psm1

#Requires -Version 5.1

# Root module for PSAutoRBAC. Loads the private engine, registers the platform
# probe providers, then exports the public surface. Load order matters: Private
# defines the provider registry and helpers, Providers register themselves into
# it, and Public consumes both. Add a .ps1 to the matching folder to extend the
# module - a new platform is just a new file under Providers/ that calls
# Register-RBACProvider.

Set-StrictMode -Version Latest

$script:ModuleRoot    = $PSScriptRoot
$script:RBACProviders = @{}
$script:RBACDataCache = @{}

$private   = @(Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private')   -Filter '*.ps1' -ErrorAction SilentlyContinue)
$providers = @(Get-ChildItem -Path (Join-Path $PSScriptRoot 'Providers') -Filter '*.ps1' -ErrorAction SilentlyContinue)
$public    = @(Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public')    -Filter '*.ps1' -ErrorAction SilentlyContinue)

foreach ($file in @($private + $providers + $public)) {
    try {
        . $file.FullName
    }
    catch {
        throw "PSAutoRBAC failed to load '$($file.FullName)': $($_.Exception.Message)"
    }
}

Write-PSFMessage -Level Verbose -Message "PSAutoRBAC loaded: $($private.Count) private, $($providers.Count) provider, $($public.Count) public file(s); $($script:RBACProviders.Values | Select-Object -ExpandProperty Name -Unique | Measure-Object | Select-Object -ExpandProperty Count) provider(s) registered." -Tag 'PSAutoRBAC', 'Load'

Export-ModuleMember -Function $public.BaseName