Skip to content

Commit e9ba874

Browse files
committed
Remove legacy import from files
1 parent 6a82bf0 commit e9ba874

6 files changed

+15
-161
lines changed

doc/31-Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2424
* [#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
2525
* [#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
2626
* [#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
27+
* [#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
2728

2829
## 1.5.2 (2021-07-09)
2930

icinga-powershell-framework.psm1

+13-147
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ function Use-Icinga()
3232
$global:Icinga.Add('Minimal', $TRUE);
3333
}
3434

35-
# If we load the minimal Framework files, we have to ensure our enums are loaded
36-
Import-Module ([string]::Format('{0}\lib\icinga\exception\Icinga_IcingaExceptionEnums.psm1', $PSScriptRoot)) -Global;
37-
Import-Module ([string]::Format('{0}\lib\icinga\enums\Icinga_IcingaEnums.psm1', $PSScriptRoot)) -Global;
38-
Import-Module ([string]::Format('{0}\lib\core\logging\Icinga_EventLog_Enums.psm1', $PSScriptRoot)) -Global;
39-
4035
return;
4136
}
4237

@@ -46,12 +41,6 @@ function Use-Icinga()
4641
Use-IcingaPlugins;
4742
}
4843

49-
# This function will allow us to load this entire module including possible
50-
# actions, making it available within our shell environment
51-
# First load our custom modules
52-
Import-IcingaLib '\' -Init -Custom;
53-
Import-IcingaLib '\' -Init;
54-
5544
if ($LibOnly -eq $FALSE) {
5645
$global:IcingaThreads = [hashtable]::Synchronized(@{});
5746
$global:IcingaThreadContent = [hashtable]::Synchronized(@{});
@@ -107,150 +96,27 @@ function Get-IcingaFrameworkCodeCacheFile()
10796
return (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework_cache.psm1');
10897
}
10998

110-
function Write-IcingaFrameworkCodeCache()
111-
{
112-
Import-IcingaLib '\' -Init -CompileCache;
113-
}
114-
11599
function Import-IcingaLib()
116100
{
117-
param(
118-
[String]$Lib,
119-
# The Force Reload will remove the module in case it's loaded and reload it to track
120-
# possible development changes without having to create new PowerShell environments
121-
[Switch]$ForceReload,
122-
[switch]$Init,
123-
[switch]$Custom,
124-
[switch]$WriteManifests,
125-
[switch]$CompileCache
126-
);
127-
128-
# This is just to only allow a global loading of the module. Import-IcingaLib is ignored on every other
129-
# location. It is just there to give a basic idea within commands, of which functions are used
130-
if ($Init -eq $FALSE) {
131-
return;
132-
}
133-
134-
$CacheFile = Get-IcingaFrameworkCodeCacheFile;
135-
136-
if ($CompileCache -eq $FALSE) {
137-
Import-Module 'icinga-powershell-framework' -Global -Force;
138-
return;
139-
}
140-
141-
[array]$ImportModules = @();
142-
[array]$RemoveModules = @();
143-
144-
if ($Custom) {
145-
[string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'custom\';
146-
} else {
147-
[string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\';
148-
}
149-
[string]$module = Join-Path -Path $directory -ChildPath $Lib;
150-
[string]$moduleName = '';
151-
152-
$ListOfLoadedModules = Get-Module | Select-Object Name;
153-
154-
# Load modules from directory
155-
if ((Test-Path $module -PathType Container)) {
156-
157-
Get-ChildItem -Path $module -Recurse -Filter *.psm1 |
158-
ForEach-Object {
159-
[string]$modulePath = $_.FullName;
160-
$moduleName = $_.Name.Replace('.psm1', '');
161-
162-
if ($ListOfLoadedModules -like "*$moduleName*") {
163-
if ($ForceReload) {
164-
$RemoveModules += $moduleName;
165-
}
166-
$ImportModules += $modulePath;
167-
} else {
168-
$ImportModules += $modulePath;
169-
if ($WriteManifests) {
170-
Publish-IcingaModuleManifest -Module $moduleName;
171-
}
172-
}
173-
}
174-
} else {
175-
$module = $module.Replace('.psm1', ''); # Cut possible .psm1 ending
176-
$moduleName = $module.Split('\')[-1]; # Get the last element
177-
178-
if ($ForceReload) {
179-
if ($ListOfLoadedModules -Like "*$moduleName*") {
180-
$RemoveModules += $moduleName;
181-
}
182-
}
183-
184-
$ImportModules += ([string]::Format('{0}.psm1', $module));
185-
if ($WriteManifests) {
186-
Publish-IcingaModuleManifest -Module $moduleName;
187-
}
188-
}
189-
190-
if ($RemoveModules.Count -ne 0) {
191-
Remove-Module $RemoveModules;
192-
}
193-
194-
if ($ImportModules.Count -ne 0) {
195-
196-
if ($CompileCache) {
197-
$CacheContent = '';
198-
foreach ($module in $ImportModules) {
199-
$Content = Get-Content $module -Raw;
200-
$CacheContent += $Content + "`r`n";
201-
}
202-
203-
$CacheContent += $Content + "Export-ModuleMember -Function @( '*' )";
204-
Set-Content -Path $CacheFile -Value $CacheContent;
205-
} else {
206-
Import-Module $ImportModules -Global;
207-
}
208-
}
101+
# Do nothing, just leave it here as compatibility layer until we
102+
# cleaned every other repository
209103
}
210104

211-
function Publish-IcingaModuleManifest()
105+
function Write-IcingaFrameworkCodeCache()
212106
{
213-
param(
214-
[string]$Module
215-
);
216-
217-
[string]$ManifestDir = Join-Path -Path $PSScriptRoot -ChildPath 'manifests';
218-
[string]$ModuleFile = [string]::Format('{0}.psd1', $Module);
219-
[string]$PSDFile = Join-Path -Path $ManifestDir -ChildPath $ModuleFile;
107+
[string]$CacheFile = Get-IcingaFrameworkCodeCacheFile;
108+
[string]$directory = Join-Path -Path $PSScriptRoot -ChildPath 'lib\';
109+
[string]$CacheContent = '';
220110

221-
if (Test-Path $PSDFile) {
222-
return;
223-
}
224-
225-
New-ModuleManifest -Path $PSDFile -ModuleVersion 1.0 -Author $env:USERNAME -CompanyName 'Icinga GmbH' -Copyright '(c) 2019 Icinga GmbH. All rights reserved.' -PowerShellVersion 4.0;
226-
$Content = Get-Content $PSDFile;
227-
$NewContent = @();
228-
229-
foreach ($line in $Content) {
230-
if ([string]::IsNullOrEmpty($line)) {
231-
continue;
232-
}
233-
234-
if ($line[0] -eq '#') {
235-
continue;
236-
}
237-
238-
if ($line.Contains('#')) {
239-
$line = $line.Substring(0, $line.IndexOf('#'));
240-
}
241-
242-
$tmpLine = $line;
243-
while ($tmpLine.Contains(' ')) {
244-
$tmpLine = $tmpLine.Replace(' ', '');
245-
}
246-
if ([string]::IsNullOrEmpty($tmpLine)) {
247-
continue;
111+
# Load modules from directory
112+
Get-ChildItem -Path $directory -Recurse -Filter '*.psm1' |
113+
ForEach-Object {
114+
$CacheContent += (Get-Content -Path $_.FullName -Raw);
115+
$CacheContent += "`r`n";
248116
}
249117

250-
$NewContent += $line;
251-
}
252-
253-
Set-Content -Path $PSDFile -Value $NewContent;
118+
$CacheContent += "Export-ModuleMember -Function @( '*' )";
119+
Set-Content -Path $CacheFile -Value $CacheContent;
254120
}
255121

256122
function Publish-IcingaEventlogDocumentation()

lib/core/tools/ConvertFrom-TimeSpan.psm1

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-IcingaLib core\tools;
2-
31
function ConvertFrom-TimeSpan()
42
{
53
param (

lib/core/tools/ConvertTo-Seconds.psm1

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-IcingaLib core\tools;
2-
31
<#
42
.SYNOPSIS
53
Converts unit to seconds.

lib/core/tools/New-IcingaCheckCommand.psm1

+1-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ function New-IcingaCheckCommand()
77
'Critical',
88
'[switch]NoPerfData',
99
'[int]Verbose'
10-
),
11-
[array]$ImportLib = @()
10+
)
1211
);
1312

1413
if ([string]::IsNullOrEmpty($Name) -eq $TRUE) {
@@ -49,12 +48,6 @@ function New-IcingaCheckCommand()
4948

5049
New-Item -Path $ModuleFolder -ItemType Directory | Out-Null;
5150

52-
Add-Content -Path $ScriptFile -Value 'Import-IcingaLib icinga\plugin;';
53-
54-
foreach ($Library in $ImportLib) {
55-
Add-Content -Path $ScriptFile -Value "Import-IcingaLib $Library;";
56-
}
57-
5851
Add-Content -Path $ScriptFile -Value '';
5952
Add-Content -Path $ScriptFile -Value "function $CommandName()";
6053
Add-Content -Path $ScriptFile -Value "{";

lib/help/help/Get-IcingaHelpThresholds.psm1

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-IcingaLib icinga\plugin;
2-
31
function Get-IcingaHelpThresholds()
42
{
53
param (

0 commit comments

Comments
 (0)