mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #525 from Icinga:feature/vscode_cache_overwrite
Features: Adds developer mode to prevent cache overwrite Adds new developer mode for `icinga` command and improved cache handling, to ensure within `-DeveloperMode` and inside a VS Code environment, the framework cache file is never overwritten, while still all functions are loaded and imported.
This commit is contained in:
commit
384ab1cf89
5 changed files with 77 additions and 8 deletions
10
cache/framework_cache.psm1
vendored
10
cache/framework_cache.psm1
vendored
|
|
@ -8,7 +8,17 @@
|
||||||
Manually enabling the feature is no longer required.
|
Manually enabling the feature is no longer required.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
# Ensures that VS Code is not generating the cache file
|
||||||
|
if ($null -ne $env:TERM_PROGRAM) {
|
||||||
|
Write-IcingaFrameworkCodeCache -DeveloperMode;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Write-IcingaFrameworkCodeCache;
|
Write-IcingaFrameworkCodeCache;
|
||||||
|
|
||||||
Import-Module icinga-powershell-framework -Global -Force;
|
Import-Module icinga-powershell-framework -Global -Force;
|
||||||
Import-Module icinga-powershell-framework -Force;
|
Import-Module icinga-powershell-framework -Force;
|
||||||
|
|
||||||
|
if ($null -ne $env:TERM_PROGRAM -Or $Global:Icinga.Protected.DeveloperMode) {
|
||||||
|
Copy-IcingaFrameworkCacheTemplate;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
* [#40](https://github.com/Icinga/icinga-powershell-framework/issues/40) Adds support to set service recovery for the Icinga Agent and Icinga for Windows service, to restart them in case of a crash or error
|
* [#40](https://github.com/Icinga/icinga-powershell-framework/issues/40) Adds support to set service recovery for the Icinga Agent and Icinga for Windows service, to restart them in case of a crash or error
|
||||||
|
* [#525](https://github.com/Icinga/icinga-powershell-framework/pull/525) Adds new developer mode for `icinga` command and improved cache handling, to ensure within `-DeveloperMode` and inside a VS Code environment, the framework cache file is never overwritten, while still all functions are loaded and imported.
|
||||||
|
|
||||||
## 1.9.1 (2022-05-13)
|
## 1.9.1 (2022-05-13)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,10 @@ function Import-IcingaLib()
|
||||||
|
|
||||||
function Write-IcingaFrameworkCodeCache()
|
function Write-IcingaFrameworkCodeCache()
|
||||||
{
|
{
|
||||||
|
param (
|
||||||
|
[switch]$DeveloperMode = $FALSE
|
||||||
|
);
|
||||||
|
|
||||||
[string]$CacheFile = Get-IcingaFrameworkCodeCacheFile;
|
[string]$CacheFile = Get-IcingaFrameworkCodeCacheFile;
|
||||||
[string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\';
|
[string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\';
|
||||||
[string]$CacheContent = '';
|
[string]$CacheContent = '';
|
||||||
|
|
@ -109,9 +113,27 @@ function Write-IcingaFrameworkCodeCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
$CacheContent += "Export-ModuleMember -Function @( '*' ) -Alias @( '*' ) -Variable @( '*' )";
|
$CacheContent += "Export-ModuleMember -Function @( '*' ) -Alias @( '*' ) -Variable @( '*' )";
|
||||||
|
|
||||||
|
if ($DeveloperMode -Or $Global:Icinga.Protected.DeveloperMode) {
|
||||||
|
[ScriptBlock]$CodeCache = [ScriptBlock]::Create($CacheContent);
|
||||||
|
. $CodeCache;
|
||||||
|
|
||||||
|
Copy-IcingaFrameworkCacheTemplate;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Set-Content -Path $CacheFile -Value $CacheContent;
|
Set-Content -Path $CacheFile -Value $CacheContent;
|
||||||
|
|
||||||
Remove-IcingaFrameworkDependencyFile;
|
Remove-IcingaFrameworkDependencyFile;
|
||||||
|
|
||||||
|
if ($Global:Icinga.Protected.DeveloperMode) {
|
||||||
|
Copy-IcingaFrameworkCacheTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Copy-IcingaFrameworkCacheTemplate()
|
||||||
|
{
|
||||||
|
Copy-Item -Path (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath '\templates\framework_cache.psm1.template') -Destination (Get-IcingaFrameworkCodeCacheFile) -Force;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Publish-IcingaEventLogDocumentation()
|
function Publish-IcingaEventLogDocumentation()
|
||||||
|
|
@ -202,6 +224,7 @@ function Invoke-IcingaCommand()
|
||||||
[switch]$Manage = $FALSE, # Only for backwards compatibility, has no use at all
|
[switch]$Manage = $FALSE, # Only for backwards compatibility, has no use at all
|
||||||
[switch]$Shell = $FALSE,
|
[switch]$Shell = $FALSE,
|
||||||
[switch]$RebuildCache = $FALSE,
|
[switch]$RebuildCache = $FALSE,
|
||||||
|
[switch]$DeveloperMode = $FALSE,
|
||||||
[array]$ArgumentList = @()
|
[array]$ArgumentList = @()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -226,8 +249,12 @@ function Invoke-IcingaCommand()
|
||||||
Write-IcingaConsoleHeader -HeaderLines $Headers;
|
Write-IcingaConsoleHeader -HeaderLines $Headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($RebuildCache) {
|
if ($DeveloperMode) {
|
||||||
Write-IcingaFrameworkCodeCache;
|
$Global:Icinga.Protected.DeveloperMode = $TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($RebuildCache -Or $DeveloperMode) {
|
||||||
|
Write-IcingaFrameworkCodeCache -DeveloperMode:$DeveloperMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($null -ne $psISE) {
|
if ($null -ne $psISE) {
|
||||||
|
|
@ -247,10 +274,16 @@ function Invoke-IcingaCommand()
|
||||||
$Version = $args[2];
|
$Version = $args[2];
|
||||||
$Shell = $args[3];
|
$Shell = $args[3];
|
||||||
$IcingaShellArgs = $args[4];
|
$IcingaShellArgs = $args[4];
|
||||||
|
$DeveloperMode = $args[5];
|
||||||
|
|
||||||
# Load our Icinga Framework
|
# Load our Icinga Framework
|
||||||
Use-Icinga;
|
Use-Icinga;
|
||||||
|
|
||||||
|
if ($DeveloperMode) {
|
||||||
|
$Global:Icinga.Protected.DeveloperMode = $TRUE;
|
||||||
|
Copy-IcingaFrameworkCacheTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
$Host.UI.RawUI.WindowTitle = ([string]::Format('Icinga for Windows {0}', $Version));
|
$Host.UI.RawUI.WindowTitle = ([string]::Format('Icinga for Windows {0}', $Version));
|
||||||
|
|
||||||
# Set the location to the Icinga Framework module folder
|
# Set the location to the Icinga Framework module folder
|
||||||
|
|
@ -274,7 +307,7 @@ function Invoke-IcingaCommand()
|
||||||
return "> "
|
return "> "
|
||||||
}
|
}
|
||||||
|
|
||||||
} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version, ([bool]$Shell), $ArgumentList;
|
} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version, ([bool]$Shell), $ArgumentList, $DeveloperMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Start-IcingaShellAsUser()
|
function Start-IcingaShellAsUser()
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ function New-IcingaEnvironmentVariable()
|
||||||
if ($Global:Icinga.ContainsKey('Protected') -eq $FALSE) {
|
if ($Global:Icinga.ContainsKey('Protected') -eq $FALSE) {
|
||||||
$Global:Icinga.Add('Protected', @{ });
|
$Global:Icinga.Add('Protected', @{ });
|
||||||
|
|
||||||
|
$Global:Icinga.Protected.Add('DeveloperMode', $FALSE);
|
||||||
$Global:Icinga.Protected.Add('DebugMode', $FALSE);
|
$Global:Icinga.Protected.Add('DebugMode', $FALSE);
|
||||||
$Global:Icinga.Protected.Add('JEAContext', $FALSE);
|
$Global:Icinga.Protected.Add('JEAContext', $FALSE);
|
||||||
$Global:Icinga.Protected.Add('RunAsDaemon', $FALSE);
|
$Global:Icinga.Protected.Add('RunAsDaemon', $FALSE);
|
||||||
|
|
|
||||||
24
templates/framework_cache.psm1.template
Normal file
24
templates/framework_cache.psm1.template
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<#
|
||||||
|
### Note ###
|
||||||
|
|
||||||
|
This file is shipping plain with Icinga for Windows for each version.
|
||||||
|
Once the module is loaded, this content will entirely be replaced with
|
||||||
|
all modules and components shipped by the Icinga PowerShell Framework.
|
||||||
|
|
||||||
|
Manually enabling the feature is no longer required.
|
||||||
|
#>
|
||||||
|
|
||||||
|
# Ensures that VS Code is not generating the cache file
|
||||||
|
if ($null -ne $env:TERM_PROGRAM) {
|
||||||
|
Write-IcingaFrameworkCodeCache -DeveloperMode;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-IcingaFrameworkCodeCache;
|
||||||
|
|
||||||
|
Import-Module icinga-powershell-framework -Global -Force;
|
||||||
|
Import-Module icinga-powershell-framework -Force;
|
||||||
|
|
||||||
|
if ($null -ne $env:TERM_PROGRAM -Or $Global:Icinga.Protected.DeveloperMode) {
|
||||||
|
Copy-IcingaFrameworkCacheTemplate;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue