Merge pull request #350 from Icinga:feature/add_skip_mkdir_on_scp_sync

Feature: Adds switch to skip mkdir on scp repo sync

Adds switch `-SkipSCPMkdir` to `Sync-IcingaRepository`, allowing to skip directory creation.
This commit is contained in:
Lord Hepipud 2021-08-20 18:27:19 +02:00 committed by GitHub
commit 21f2f26c1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 23 deletions

View file

@ -13,6 +13,7 @@ Like with [adding existing repositories](01-Add-Existing-Repositories.md), each
| RemotePath | String | The path pointing to the location Icinga for Windows tries to lookup all your files. You can either replicate the `Path` variable for network shares for example, or use a web url which is made available based on `Path` to fetch and download files from. If left empty, it will default to the `Path` variable content | | RemotePath | String | The path pointing to the location Icinga for Windows tries to lookup all your files. You can either replicate the `Path` variable for network shares for example, or use a web url which is made available based on `Path` to fetch and download files from. If left empty, it will default to the `Path` variable content |
| Source | String | The source from where the repository will be synced from. This can either be pointing directly to the `ifw.repo.json` or the root directory, as long as the file is fetch able from this point. A source can be a web, local or network share | | Source | String | The source from where the repository will be synced from. This can either be pointing directly to the `ifw.repo.json` or the root directory, as long as the file is fetch able from this point. A source can be a web, local or network share |
| UseSCP | Switch | If you set `Path` to a Linux path as mentioned in the first example, you will have to enable this switch to use SCP to copy files from the source to the Linux system. Requires `scp` and `ssh` being installed on the system | | UseSCP | Switch | If you set `Path` to a Linux path as mentioned in the first example, you will have to enable this switch to use SCP to copy files from the source to the Linux system. Requires `scp` and `ssh` being installed on the system |
| SkipSCPMkdir | Switch | Allows you to skip the `mkdir` operation while using `-UseSCP` and relies on the folder already existing |
| Force | Switch | This will force the creation of the repository, even if the name of the repository is already assigned. Should be used with caution | | Force | Switch | This will force the creation of the repository, even if the name of the repository is already assigned. Should be used with caution |
| ForceTrust | Switch | By default repositories are validated with a hash, based on all files present inside the repository. If a repository is not providing a hash, it will be disabled after the sync for security reasons. In case the hash does not match with all files synced afterwards, the repository files will be deleted and the sync aborted. You can use this flag to ignore both states and always add the repository, regardless if the hash matches or the hash is not given | | ForceTrust | Switch | By default repositories are validated with a hash, based on all files present inside the repository. If a repository is not providing a hash, it will be disabled after the sync for security reasons. In case the hash does not match with all files synced afterwards, the repository files will be deleted and the sync aborted. You can use this flag to ignore both states and always add the repository, regardless if the hash matches or the hash is not given |

View file

@ -7,7 +7,8 @@ function Sync-IcingaRepository()
[string]$Source = $null, [string]$Source = $null,
[switch]$UseSCP = $FALSE, [switch]$UseSCP = $FALSE,
[switch]$Force = $FALSE, [switch]$Force = $FALSE,
[switch]$ForceTrust = $FALSE [switch]$ForceTrust = $FALSE,
[switch]$SkipSCPMkdir = $FALSE
); );
if ([string]::IsNullOrEmpty($Name)) { if ([string]::IsNullOrEmpty($Name)) {
@ -205,6 +206,8 @@ function Sync-IcingaRepository()
return; return;
} }
} else { # Linux target } else { # Linux target
if ($SkipSCPMkdir -eq $FALSE) {
Write-IcingaConsoleNotice 'Creating directory over SSH for host and user "{0}" and path "{1}"' -Objects $SSHAuth, $Path; Write-IcingaConsoleNotice 'Creating directory over SSH for host and user "{0}" and path "{1}"' -Objects $SSHAuth, $Path;
$Result = Start-IcingaProcess -Executable 'ssh' -Arguments ([string]::Format('{0} mkdir -p "{1}"', $SSHAuth, $Path)); $Result = Start-IcingaProcess -Executable 'ssh' -Arguments ([string]::Format('{0} mkdir -p "{1}"', $SSHAuth, $Path));
@ -214,6 +217,7 @@ function Sync-IcingaRepository()
$Success = Remove-Item -Path $TmpDir -Recurse -Force; $Success = Remove-Item -Path $TmpDir -Recurse -Force;
return; return;
} }
}
Write-IcingaConsoleNotice 'Removing old repository files from "{0}"' -Objects $Path; Write-IcingaConsoleNotice 'Removing old repository files from "{0}"' -Objects $Path;