Merge pull request #326 from Icinga:fix/import_on_non_ps_folders

Fix: Module import on non PowerShell folders

Fixes import for module files, by using the full path to the module now instead of the name only, as files could be placed inside a folder which is not listed inside the `$ENV:PSModulePath`
This commit is contained in:
Lord Hepipud 2021-08-17 09:31:15 +02:00 committed by GitHub
commit 75567c2fe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 22412 additions and 19 deletions

File diff suppressed because it is too large Load diff

View file

@ -15,6 +15,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#311](https://github.com/Icinga/icinga-powershell-framework/issues/311) Fixes an issue with negative inputs on some scenarios which will cause an exception for checks instead of continuing executing them properly
* [#317](https://github.com/Icinga/icinga-powershell-framework/pull/317) Fixes certain file names being too long, causing errors on deploying branches
* [#326](https://github.com/Icinga/icinga-powershell-framework/pull/326) Fixes import for module files, by using the full path to the module now instead of the name only, as files could be placed inside a folder which is not listed inside the `$ENV:PSModulePath`
### Enhancements

View file

@ -18,7 +18,7 @@ function Use-Icinga()
);
if ($null -ne $Global:Icinga -And $Global:Icinga.ContainsKey('RebuildCache') -And $Global:Icinga.RebuildCache) {
Import-Module 'icinga-powershell-framework' -Global -Force;
Import-Module (Join-Path -Path (Get-IcingaForWindowsRootPath) -ChildPath 'icinga-powershell-framework') -Global -Force;
}
Disable-IcingaProgressPreference;

View file

@ -111,9 +111,9 @@ function Install-IcingaFrameworkComponent()
Use-Icinga;
# Unload the module if it was loaded before
Remove-Module $RepositoryName -Force -ErrorAction SilentlyContinue;
Remove-Module $PluginDirectory -Force -ErrorAction SilentlyContinue;
# Now import the module
Import-Module $RepositoryName;
Import-Module $PluginDirectory;
Write-IcingaConsoleNotice ([string]::Format('Icinga {0} update has been completed. Please start a new PowerShell to apply it', $ComponentName));

View file

@ -14,10 +14,10 @@ function Invoke-IcingaNamespaceCmdlets()
foreach ($Cmdlet in $CommandList) {
try {
$CmmandName = $Cmdlet.Name;
$CommandName = $Cmdlet.Name;
Import-Module $Cmdlet.Module.Path -WarningAction SilentlyContinue -ErrorAction Stop;
$Content = (& $CmmandName);
$Content = (& $CommandName);
Add-IcingaHashtableItem `
-Hashtable $CommandConfig `
-Key $Cmdlet.Name `

View file

@ -58,7 +58,7 @@ function Publish-IcingaPluginConfiguration()
} catch {
[string]$Message = $_.Exception.Message;
Write-IcingaConsoleError 'Failed to import the module on path "{0}". Please verify that this is a valid PowerShell module root folder. Exception: {1}{2}' -Objects $ComponentPath, (New-IcingaNewLine), $Message;
return;
return;
}
$CheckCommands = Get-Command -ListImported -Name 'Invoke-IcingaCheck*' -ErrorAction SilentlyContinue;

View file

@ -196,7 +196,7 @@ function Install-IcingaComponent()
}
}
Import-Module -Name $PackageName -Force;
Import-Module -Name $ComponentFolder -Force;
Write-IcingaConsoleNotice 'Installation of component "{0}" with version "{1}" was successful. Open a new PowerShell to apply the changes' -Objects $Name.ToLower(), $ManifestFile.ModuleVersion;
} else {
<#

View file

@ -108,7 +108,7 @@ function New-IcingaCheckCommand()
Import-Module $ScriptFile -Global;
if ([string]::IsNullOrEmpty($DefaultEditor) -eq $FALSE -And ($null -eq (Get-Command $DefaultEditor -ErrorAction SilentlyContinue)) -And ((Test-Path $DefaultEditor) -eq $FALSE)) {
Write-IcingaConsoleWarning 'No default editor for .psm1 files found. Specify a default editor to automaticly open the newly generated check plugin.';
Write-IcingaConsoleWarning 'No default editor for .psm1 files found. Specify a default editor to automatically open the newly generated check plugin.';
return;
}

View file

@ -31,7 +31,7 @@ function Exit-IcingaPluginNotInstalled()
ForEach-Object {
foreach ($cmd in $_.ExportedCommands.Values) {
if ($Command.ToLower() -eq $cmd.Name.ToLower()) {
return $cmd.Source;
return $cmd.Path;
}
}
}