Adds feature to force adding of repo

This commit is contained in:
Lord Hepipud 2021-08-17 12:08:27 +02:00
parent b6b8563f0c
commit f70fc51ee3
2 changed files with 12 additions and 3 deletions

View file

@ -16,6 +16,7 @@ The best way to demonstrate on how to add new repositories, you can use the defa
| --- |--- | --- | | --- |--- | --- |
| Name | String | The unique name of the repository. This name can only exist once on your system | | Name | String | The unique name of the repository. This name can only exist once on your system |
| RemotePath | String | The path pointing to the location on where the repository is located at. It can either point to the root directory of the folder containing the `ifw.repo.json` or directly to this file. Accepts web, local or network share path. | | RemotePath | String | The path pointing to the location on where the repository is located at. It can either point to the root directory of the folder containing the `ifw.repo.json` or directly to this file. Accepts web, local or network share path. |
| Force | Switch | Will remove an existing repository with the same name and override it with the new configuration |
### Icinga for Windows Stable ### Icinga for Windows Stable

View file

@ -2,7 +2,8 @@ function Add-IcingaRepository()
{ {
param ( param (
[string]$Name = $null, [string]$Name = $null,
[string]$RemotePath = $null [string]$RemotePath = $null,
[switch]$Force = $FALSE
); );
if ([string]::IsNullOrEmpty($Name)) { if ([string]::IsNullOrEmpty($Name)) {
@ -21,9 +22,16 @@ function Add-IcingaRepository()
$CurrentRepositories = New-Object -TypeName PSObject; $CurrentRepositories = New-Object -TypeName PSObject;
} }
if (Test-IcingaPowerShellConfigItem -ConfigObject $CurrentRepositories -ConfigKey $Name) { $RepoExists = Test-IcingaPowerShellConfigItem -ConfigObject $CurrentRepositories -ConfigKey $Name;
Write-IcingaConsoleError 'A repository with the given name "{0}" does already exist.' -Objects $Name;
if ($RepoExists -And $Force -eq $FALSE) {
Write-IcingaConsoleError 'A repository with the given name "{0}" does already exist. Use "-Force" to overwrite the current repository' -Objects $Name;
return; return;
} elseif ($RepoExists -And $Force) {
Write-IcingaConsoleNotice 'Repository "{0}" is already registered. Forcing removal and re-adding it.' -Objects $Name;
Remove-IcingaRepository -Name $Name;
$CurrentRepositories = Get-IcingaPowerShellConfig -Path 'Framework.Repository.Repositories';
} }
[array]$RepoCount = $CurrentRepositories.PSObject.Properties.Count; [array]$RepoCount = $CurrentRepositories.PSObject.Properties.Count;