Skip to content

Commit 14ee09c

Browse files
authored
Merge pull request #373 from Icinga:fix/repository_name_with_dot
Fix: Repository names with dots fail to load Fixes repository names with dots (`.`) by replacing them with `-`, as otherwise the config parser will fail finding the config object
2 parents 7ca347a + 0b4db2b commit 14ee09c

13 files changed

+60
-1
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2222
* [#368](https://github.com/Icinga/icinga-powershell-framework/issues/368) Fixes repository lookup on local path for ifw.repo.json, in the json file was added to the file path during repository add
2323
* [#369](https://github.com/Icinga/icinga-powershell-framework/issues/369) Fixes experimental feature warning for API-Check Forwarder feature, which is fully supported since v1.6.0 and replaces it with proper information and link to docs
2424
* [#371](https://github.com/Icinga/icinga-powershell-framework/issues/371) Fixes wrong indention on Icinga parent host address at IMC configuration summary overview
25+
* [#373](https://github.com/Icinga/icinga-powershell-framework/issues/373) Fixes repository names with dots (`.`) by replacing them with `-`, as otherwise the config parser will fail finding the config object
2526

2627
### Enhancements
2728

lib/config/Get-IcingaPowerShellConfig.psm1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,31 @@ function Get-IcingaPowerShellConfig()
3636
}
3737

3838
return $ConfigObject;
39+
40+
<#
41+
# Alternate config parser. Might come handy in the future, requires to redesign
42+
# Set-IcingaPowerShellConfig including all calls for full coverage
43+
$Config = Read-IcingaPowerShellConfig;
44+
$PathArray = $Path.Split('.');
45+
$ConfigObject = $Config;
46+
[int]$Index = 0;
47+
$entry = $PathArray[$Index];
48+
49+
while ($Index -lt $PathArray.Count) {
50+
if (-Not (Test-IcingaPowerShellConfigItem -ConfigObject $ConfigObject -ConfigKey $entry) -And $Index -lt $PathArray.Count) {
51+
$Index += 1;
52+
$entry = [string]::Format('{0}.{1}', $entry, $PathArray[$Index]);
53+
54+
continue;
55+
} elseif (-Not (Test-IcingaPowerShellConfigItem -ConfigObject $ConfigObject -ConfigKey $entry) -And $Index -ge $PathArray.Count) {
56+
return $null;
57+
}
58+
59+
$ConfigObject = $ConfigObject.$entry;
60+
$Index += 1;
61+
$entry = $PathArray[$Index];
62+
}
63+
64+
return $ConfigObject;
65+
#>
3966
}

lib/config/Test-IcingaPowerShellConfigItem.psm1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,15 @@ function Test-IcingaPowerShellConfigItem()
2626
$ConfigKey
2727
);
2828

29-
return ([bool]($ConfigObject.PSObject.Properties.Name -eq $ConfigKey) -eq $TRUE);
29+
if ($null -eq $ConfigObject -Or [string]::IsNullOrEmpty($ConfigKey)) {
30+
return $FALSE;
31+
}
32+
33+
foreach ($entry in $ConfigObject.PSObject.Properties) {
34+
if ($entry.Name.ToLower() -eq $ConfigKey.ToLower()) {
35+
return $TRUE;
36+
}
37+
}
38+
39+
return $FALSE;
3040
}

lib/core/repository/Add-IcingaRepository.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ function Add-IcingaRepository()
1111
return;
1212
}
1313

14+
$Name = $Name.Replace('.', '-');
15+
1416
if ([string]::IsNullOrEmpty($RemotePath)) {
1517
Write-IcingaConsoleError 'You have to provide a remote path for the repository';
1618
return;

lib/core/repository/Disable-IcingaRepository.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function Disable-IcingaRepository()
99
return;
1010
}
1111

12+
$Name = $Name.Replace('.', '-');
13+
1214
$CurrentRepositories = Get-IcingaPowerShellConfig -Path ([string]::Format('Framework.Repository.Repositories.{0}', $Name));
1315

1416
if ($null -eq $CurrentRepositories) {

lib/core/repository/Enable-IcingaRepository.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function Enable-IcingaRepository()
99
return;
1010
}
1111

12+
$Name = $Name.Replace('.', '-');
13+
1214
$CurrentRepositories = Get-IcingaPowerShellConfig -Path ([string]::Format('Framework.Repository.Repositories.{0}', $Name));
1315

1416
if ($null -eq $CurrentRepositories) {

lib/core/repository/New-IcingaRepository.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function New-IcingaRepository()
1212
return;
1313
}
1414

15+
$Name = $Name.Replace('.', '-');
16+
1517
if ([string]::IsNullOrEmpty($Path) -Or (Test-Path $Path) -eq $FALSE) {
1618
Write-IcingaConsoleError 'The provided path "{0}" does not exist' -Objects $Path;
1719
return;

lib/core/repository/Pop-IcingaRepository.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function Pop-IcingaRepository()
99
return;
1010
}
1111

12+
$Name = $Name.Replace('.', '-');
13+
1214
$CurrentRepositories = Get-IcingaPowerShellConfig -Path 'Framework.Repository.Repositories';
1315

1416
if ($null -eq $CurrentRepositories) {

lib/core/repository/Push-IcingaRepository.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function Push-IcingaRepository()
1212
return;
1313
}
1414

15+
$Name = $Name.Replace('.', '-');
16+
1517
$CurrentRepositories = Get-IcingaPowerShellConfig -Path 'Framework.Repository.Repositories';
1618

1719
if ($null -eq $CurrentRepositories) {

lib/core/repository/Read-IcingaRepositoryFile.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ function Read-IcingaRepositoryFile()
1010
return $null;
1111
}
1212

13+
$Name = $Name.Replace('.', '-');
14+
1315
$Repository = Get-IcingaPowerShellConfig -Path ([string]::Format('Framework.Repository.Repositories.{0}', $Name));
1416

1517
if ($null -eq $Repository) {

0 commit comments

Comments
 (0)