Public/Get-MacadressConfiguration.ps1
|
function Get-MacadressConfiguration { <# .SYNOPSIS Show the current session configuration for the Macadress module. .DESCRIPTION Returns the base URI, request timeout, and whether an API key is available (from Set-MacadressConfiguration or the MACADRESS_API_KEY environment variable). The key itself is never returned in full; only a masked hint and its source. .EXAMPLE Get-MacadressConfiguration .LINK https://github.com/sapisos/macadress-powershell #> [CmdletBinding()] [OutputType('Macadress.Configuration')] param() $cfg = Get-MacadressConfigStore $source = 'none' $key = $null if ($cfg.ApiKey) { $source = 'Set-MacadressConfiguration'; $key = $cfg.ApiKey } elseif ($env:MACADRESS_API_KEY) { $source = 'MACADRESS_API_KEY'; $key = $env:MACADRESS_API_KEY } $hint = $null if ($key) { $hint = if ($key.Length -le 8) { '***' } else { '{0}...{1}' -f $key.Substring(0, 4), $key.Substring($key.Length - 4) } } [pscustomobject]@{ PSTypeName = 'Macadress.Configuration' BaseUri = $cfg.BaseUri TimeoutSeconds = $cfg.TimeoutSeconds ApiKeySet = [bool] $key ApiKeySource = $source ApiKeyHint = $hint } } |