Private/Get-WorkspacePath.ps1
|
<#
.SYNOPSIS Gets the stored workspace path .DESCRIPTION Retrieves the workspace path from module settings .OUTPUTS String containing the workspace path #> function Get-WorkspacePath { [CmdletBinding()] param() try { # Check module variable first if ($script:NLBaselineWorkspacePath) { # Validate that workspace path does not contain sandbox or test directories if ($script:NLBaselineWorkspacePath -match '\\sandbox\\|\\test-|\\sandbox$|\\test$') { Write-Warning "Invalid workspace path detected (contains sandbox/test): $script:NLBaselineWorkspacePath" Write-Warning "Sandbox paths are not allowed. Clearing invalid path." # Clear the invalid path $script:NLBaselineWorkspacePath = $null # Also clear from settings file $moduleDataPath = Join-Path -Path $env:LOCALAPPDATA -ChildPath "NLBaseline" $settingsPath = Join-Path -Path $moduleDataPath -ChildPath "settings.json" if (Test-Path -Path $settingsPath) { $settings = Get-Content -Path $settingsPath -Raw | ConvertFrom-Json $settings.WorkspacePath = $null $settings | ConvertTo-Json | Set-Content -Path $settingsPath -Force } return $null } return $script:NLBaselineWorkspacePath } # Check module settings file $moduleDataPath = Join-Path -Path $env:LOCALAPPDATA -ChildPath "NLBaseline" if (-not (Test-Path -Path $moduleDataPath)) { New-Item -ItemType Directory -Path $moduleDataPath -Force | Out-Null } $settingsPath = Join-Path -Path $moduleDataPath -ChildPath "settings.json" if (Test-Path -Path $settingsPath) { $settings = Get-Content -Path $settingsPath -Raw | ConvertFrom-Json if ($settings.WorkspacePath) { # Validate that workspace path does not contain sandbox or test directories $workspacePath = $settings.WorkspacePath if ($workspacePath -match '\\sandbox\\|\\test-|\\sandbox$|\\test$') { Write-Warning "Invalid workspace path detected (contains sandbox/test): $workspacePath" Write-Warning "Sandbox paths are not allowed. Please initialize a proper workspace using Initialize-NLBaseline." # Clear the invalid path from settings $settings.WorkspacePath = $null $settings | ConvertTo-Json | Set-Content -Path $settingsPath -Force $script:NLBaselineWorkspacePath = $null return $null } $script:NLBaselineWorkspacePath = $workspacePath return $workspacePath } } return $null } catch { Write-Verbose "Failed to get workspace path: $_" return $null } } |