Fix module import on non PS folders

This commit is contained in:
Lord Hepipud 2021-08-17 09:22:05 +02:00
parent aa764061da
commit e3c9396c59
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 * [#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 * [#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 ### Enhancements

View file

@ -18,7 +18,7 @@ function Use-Icinga()
); );
if ($null -ne $Global:Icinga -And $Global:Icinga.ContainsKey('RebuildCache') -And $Global:Icinga.RebuildCache) { 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; Disable-IcingaProgressPreference;

View file

@ -111,9 +111,9 @@ function Install-IcingaFrameworkComponent()
Use-Icinga; Use-Icinga;
# Unload the module if it was loaded before # Unload the module if it was loaded before
Remove-Module $RepositoryName -Force -ErrorAction SilentlyContinue; Remove-Module $PluginDirectory -Force -ErrorAction SilentlyContinue;
# Now import the module # 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)); 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) { foreach ($Cmdlet in $CommandList) {
try { try {
$CmmandName = $Cmdlet.Name; $CommandName = $Cmdlet.Name;
Import-Module $Cmdlet.Module.Path -WarningAction SilentlyContinue -ErrorAction Stop; Import-Module $Cmdlet.Module.Path -WarningAction SilentlyContinue -ErrorAction Stop;
$Content = (& $CmmandName); $Content = (& $CommandName);
Add-IcingaHashtableItem ` Add-IcingaHashtableItem `
-Hashtable $CommandConfig ` -Hashtable $CommandConfig `
-Key $Cmdlet.Name ` -Key $Cmdlet.Name `

View file

@ -58,7 +58,7 @@ function Publish-IcingaPluginConfiguration()
} catch { } catch {
[string]$Message = $_.Exception.Message; [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; 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; $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; 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 { } else {
<# <#

View file

@ -108,7 +108,7 @@ function New-IcingaCheckCommand()
Import-Module $ScriptFile -Global; Import-Module $ScriptFile -Global;
if ([string]::IsNullOrEmpty($DefaultEditor) -eq $FALSE -And ($null -eq (Get-Command $DefaultEditor -ErrorAction SilentlyContinue)) -And ((Test-Path $DefaultEditor) -eq $FALSE)) { 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; return;
} }

View file

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