From e9ba8747f8ad1a4fa0f2e59c432657c590e011c5 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Sat, 7 Aug 2021 11:04:05 +0200 Subject: [PATCH] Remove legacy import from files --- doc/31-Changelog.md | 1 + icinga-powershell-framework.psm1 | 160 ++------------------ lib/core/tools/ConvertFrom-TimeSpan.psm1 | 2 - lib/core/tools/ConvertTo-Seconds.psm1 | 2 - lib/core/tools/New-IcingaCheckCommand.psm1 | 9 +- lib/help/help/Get-IcingaHelpThresholds.psm1 | 2 - 6 files changed, 15 insertions(+), 161 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 114d8dfe..e0c78d6e 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -24,6 +24,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#314](https://github.com/Icinga/icinga-powershell-framework/pull/314) Adds support to configure on which address TCP sockets are created on, defaults to `loopback` interface * [#316](https://github.com/Icinga/icinga-powershell-framework/pull/316) The reconfigure menu was previously present inside the Icinga Agent sub-menu and is now moved to the main installation menu for the Management Console * [#318](https://github.com/Icinga/icinga-powershell-framework/pull/318) We always enforce the Icinga Framework Code caching now and ship a plain file to build the cache on first loading +* [#322](https://github.com/Icinga/icinga-powershell-framework/pull/322) Remove legacy import feature from Framework and replace it with a dummy function, as no longer required by Icinga for Windows ## 1.5.2 (2021-07-09) diff --git a/icinga-powershell-framework.psm1 b/icinga-powershell-framework.psm1 index 92f94dcc..16ebf6d0 100644 --- a/icinga-powershell-framework.psm1 +++ b/icinga-powershell-framework.psm1 @@ -32,11 +32,6 @@ function Use-Icinga() $global:Icinga.Add('Minimal', $TRUE); } - # If we load the minimal Framework files, we have to ensure our enums are loaded - Import-Module ([string]::Format('{0}\lib\icinga\exception\Icinga_IcingaExceptionEnums.psm1', $PSScriptRoot)) -Global; - Import-Module ([string]::Format('{0}\lib\icinga\enums\Icinga_IcingaEnums.psm1', $PSScriptRoot)) -Global; - Import-Module ([string]::Format('{0}\lib\core\logging\Icinga_EventLog_Enums.psm1', $PSScriptRoot)) -Global; - return; } @@ -46,12 +41,6 @@ function Use-Icinga() Use-IcingaPlugins; } - # This function will allow us to load this entire module including possible - # actions, making it available within our shell environment - # First load our custom modules - Import-IcingaLib '\' -Init -Custom; - Import-IcingaLib '\' -Init; - if ($LibOnly -eq $FALSE) { $global:IcingaThreads = [hashtable]::Synchronized(@{}); $global:IcingaThreadContent = [hashtable]::Synchronized(@{}); @@ -107,150 +96,27 @@ function Get-IcingaFrameworkCodeCacheFile() return (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework_cache.psm1'); } -function Write-IcingaFrameworkCodeCache() -{ - Import-IcingaLib '\' -Init -CompileCache; -} - function Import-IcingaLib() { - param( - [String]$Lib, - # The Force Reload will remove the module in case it's loaded and reload it to track - # possible development changes without having to create new PowerShell environments - [Switch]$ForceReload, - [switch]$Init, - [switch]$Custom, - [switch]$WriteManifests, - [switch]$CompileCache - ); - - # This is just to only allow a global loading of the module. Import-IcingaLib is ignored on every other - # location. It is just there to give a basic idea within commands, of which functions are used - if ($Init -eq $FALSE) { - return; - } - - $CacheFile = Get-IcingaFrameworkCodeCacheFile; - - if ($CompileCache -eq $FALSE) { - Import-Module 'icinga-powershell-framework' -Global -Force; - return; - } - - [array]$ImportModules = @(); - [array]$RemoveModules = @(); - - if ($Custom) { - [string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'custom\'; - } else { - [string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\'; - } - [string]$module = Join-Path -Path $directory -ChildPath $Lib; - [string]$moduleName = ''; - - $ListOfLoadedModules = Get-Module | Select-Object Name; - - # Load modules from directory - if ((Test-Path $module -PathType Container)) { - - Get-ChildItem -Path $module -Recurse -Filter *.psm1 | - ForEach-Object { - [string]$modulePath = $_.FullName; - $moduleName = $_.Name.Replace('.psm1', ''); - - if ($ListOfLoadedModules -like "*$moduleName*") { - if ($ForceReload) { - $RemoveModules += $moduleName; - } - $ImportModules += $modulePath; - } else { - $ImportModules += $modulePath; - if ($WriteManifests) { - Publish-IcingaModuleManifest -Module $moduleName; - } - } - } - } else { - $module = $module.Replace('.psm1', ''); # Cut possible .psm1 ending - $moduleName = $module.Split('\')[-1]; # Get the last element - - if ($ForceReload) { - if ($ListOfLoadedModules -Like "*$moduleName*") { - $RemoveModules += $moduleName; - } - } - - $ImportModules += ([string]::Format('{0}.psm1', $module)); - if ($WriteManifests) { - Publish-IcingaModuleManifest -Module $moduleName; - } - } - - if ($RemoveModules.Count -ne 0) { - Remove-Module $RemoveModules; - } - - if ($ImportModules.Count -ne 0) { - - if ($CompileCache) { - $CacheContent = ''; - foreach ($module in $ImportModules) { - $Content = Get-Content $module -Raw; - $CacheContent += $Content + "`r`n"; - } - - $CacheContent += $Content + "Export-ModuleMember -Function @( '*' )"; - Set-Content -Path $CacheFile -Value $CacheContent; - } else { - Import-Module $ImportModules -Global; - } - } + # Do nothing, just leave it here as compatibility layer until we + # cleaned every other repository } -function Publish-IcingaModuleManifest() +function Write-IcingaFrameworkCodeCache() { - param( - [string]$Module - ); - - [string]$ManifestDir = Join-Path -Path $PSScriptRoot -ChildPath 'manifests'; - [string]$ModuleFile = [string]::Format('{0}.psd1', $Module); - [string]$PSDFile = Join-Path -Path $ManifestDir -ChildPath $ModuleFile; + [string]$CacheFile = Get-IcingaFrameworkCodeCacheFile; + [string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\'; + [string]$CacheContent = ''; - if (Test-Path $PSDFile) { - return; - } - - New-ModuleManifest -Path $PSDFile -ModuleVersion 1.0 -Author $env:USERNAME -CompanyName 'Icinga GmbH' -Copyright '(c) 2019 Icinga GmbH. All rights reserved.' -PowerShellVersion 4.0; - $Content = Get-Content $PSDFile; - $NewContent = @(); - - foreach ($line in $Content) { - if ([string]::IsNullOrEmpty($line)) { - continue; - } - - if ($line[0] -eq '#') { - continue; - } - - if ($line.Contains('#')) { - $line = $line.Substring(0, $line.IndexOf('#')); - } - - $tmpLine = $line; - while ($tmpLine.Contains(' ')) { - $tmpLine = $tmpLine.Replace(' ', ''); - } - if ([string]::IsNullOrEmpty($tmpLine)) { - continue; + # Load modules from directory + Get-ChildItem -Path $directory -Recurse -Filter '*.psm1' | + ForEach-Object { + $CacheContent += (Get-Content -Path $_.FullName -Raw); + $CacheContent += "`r`n"; } - $NewContent += $line; - } - - Set-Content -Path $PSDFile -Value $NewContent; + $CacheContent += "Export-ModuleMember -Function @( '*' )"; + Set-Content -Path $CacheFile -Value $CacheContent; } function Publish-IcingaEventlogDocumentation() diff --git a/lib/core/tools/ConvertFrom-TimeSpan.psm1 b/lib/core/tools/ConvertFrom-TimeSpan.psm1 index fd52b9c8..1fed3f58 100644 --- a/lib/core/tools/ConvertFrom-TimeSpan.psm1 +++ b/lib/core/tools/ConvertFrom-TimeSpan.psm1 @@ -1,5 +1,3 @@ -Import-IcingaLib core\tools; - function ConvertFrom-TimeSpan() { param ( diff --git a/lib/core/tools/ConvertTo-Seconds.psm1 b/lib/core/tools/ConvertTo-Seconds.psm1 index 195f951c..29a8ac6c 100644 --- a/lib/core/tools/ConvertTo-Seconds.psm1 +++ b/lib/core/tools/ConvertTo-Seconds.psm1 @@ -1,5 +1,3 @@ -Import-IcingaLib core\tools; - <# .SYNOPSIS Converts unit to seconds. diff --git a/lib/core/tools/New-IcingaCheckCommand.psm1 b/lib/core/tools/New-IcingaCheckCommand.psm1 index 042c5b71..3edebaad 100644 --- a/lib/core/tools/New-IcingaCheckCommand.psm1 +++ b/lib/core/tools/New-IcingaCheckCommand.psm1 @@ -7,8 +7,7 @@ function New-IcingaCheckCommand() 'Critical', '[switch]NoPerfData', '[int]Verbose' - ), - [array]$ImportLib = @() + ) ); if ([string]::IsNullOrEmpty($Name) -eq $TRUE) { @@ -49,12 +48,6 @@ function New-IcingaCheckCommand() New-Item -Path $ModuleFolder -ItemType Directory | Out-Null; - Add-Content -Path $ScriptFile -Value 'Import-IcingaLib icinga\plugin;'; - - foreach ($Library in $ImportLib) { - Add-Content -Path $ScriptFile -Value "Import-IcingaLib $Library;"; - } - Add-Content -Path $ScriptFile -Value ''; Add-Content -Path $ScriptFile -Value "function $CommandName()"; Add-Content -Path $ScriptFile -Value "{"; diff --git a/lib/help/help/Get-IcingaHelpThresholds.psm1 b/lib/help/help/Get-IcingaHelpThresholds.psm1 index b6d4b139..9ef1aaeb 100644 --- a/lib/help/help/Get-IcingaHelpThresholds.psm1 +++ b/lib/help/help/Get-IcingaHelpThresholds.psm1 @@ -1,5 +1,3 @@ -Import-IcingaLib icinga\plugin; - function Get-IcingaHelpThresholds() { param (