Skip to content

Commit e3c9396

Browse files
committed
Fix module import on non PS folders
1 parent aa76406 commit e3c9396

9 files changed

+22410
-17
lines changed

cache/framework_cache.psm1

Lines changed: 22400 additions & 8 deletions
Large diffs are not rendered by default.

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1515

1616
* [#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
1717
* [#317](https://github.com/Icinga/icinga-powershell-framework/pull/317) Fixes certain file names being too long, causing errors on deploying branches
18+
* [#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`
1819

1920
### Enhancements
2021

icinga-powershell-framework.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Use-Icinga()
1818
);
1919

2020
if ($null -ne $Global:Icinga -And $Global:Icinga.ContainsKey('RebuildCache') -And $Global:Icinga.RebuildCache) {
21-
Import-Module 'icinga-powershell-framework' -Global -Force;
21+
Import-Module (Join-Path -Path (Get-IcingaForWindowsRootPath) -ChildPath 'icinga-powershell-framework') -Global -Force;
2222
}
2323

2424
Disable-IcingaProgressPreference;

lib/core/framework/Install-IcingaFrameworkComponent.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ function Install-IcingaFrameworkComponent()
111111
Use-Icinga;
112112

113113
# Unload the module if it was loaded before
114-
Remove-Module $RepositoryName -Force -ErrorAction SilentlyContinue;
114+
Remove-Module $PluginDirectory -Force -ErrorAction SilentlyContinue;
115115
# Now import the module
116-
Import-Module $RepositoryName;
116+
Import-Module $PluginDirectory;
117117

118118
Write-IcingaConsoleNotice ([string]::Format('Icinga {0} update has been completed. Please start a new PowerShell to apply it', $ComponentName));
119119

lib/core/framework/Invoke-IcingaNamespaceCmdlets.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ function Invoke-IcingaNamespaceCmdlets()
1414

1515
foreach ($Cmdlet in $CommandList) {
1616
try {
17-
$CmmandName = $Cmdlet.Name;
17+
$CommandName = $Cmdlet.Name;
1818
Import-Module $Cmdlet.Module.Path -WarningAction SilentlyContinue -ErrorAction Stop;
1919

20-
$Content = (& $CmmandName);
20+
$Content = (& $CommandName);
2121
Add-IcingaHashtableItem `
2222
-Hashtable $CommandConfig `
2323
-Key $Cmdlet.Name `

lib/core/framework/Publish-IcingaPluginConfiguration.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function Publish-IcingaPluginConfiguration()
5858
} catch {
5959
[string]$Message = $_.Exception.Message;
6060
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;
61-
return;
61+
return;
6262
}
6363

6464
$CheckCommands = Get-Command -ListImported -Name 'Invoke-IcingaCheck*' -ErrorAction SilentlyContinue;

lib/core/repository/Install-IcingaComponent.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function Install-IcingaComponent()
196196
}
197197
}
198198

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

lib/core/tools/New-IcingaCheckCommand.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function New-IcingaCheckCommand()
108108
Import-Module $ScriptFile -Global;
109109

110110
if ([string]::IsNullOrEmpty($DefaultEditor) -eq $FALSE -And ($null -eq (Get-Command $DefaultEditor -ErrorAction SilentlyContinue)) -And ((Test-Path $DefaultEditor) -eq $FALSE)) {
111-
Write-IcingaConsoleWarning 'No default editor for .psm1 files found. Specify a default editor to automaticly open the newly generated check plugin.';
111+
Write-IcingaConsoleWarning 'No default editor for .psm1 files found. Specify a default editor to automatically open the newly generated check plugin.';
112112
return;
113113
}
114114

lib/icinga/exception/Exit-IcingaPluginNotInstalled.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Exit-IcingaPluginNotInstalled()
3131
ForEach-Object {
3232
foreach ($cmd in $_.ExportedCommands.Values) {
3333
if ($Command.ToLower() -eq $cmd.Name.ToLower()) {
34-
return $cmd.Source;
34+
return $cmd.Path;
3535
}
3636
}
3737
}

0 commit comments

Comments
 (0)