From 188f3caed5b886049e54b15972f51d561013d1f8 Mon Sep 17 00:00:00 2001 From: LordHepipud Date: Fri, 14 Jul 2023 20:10:07 +0200 Subject: [PATCH] Adds progress bar to repository interaction instead of text output --- doc/100-General/10-Changelog.md | 1 + lib/core/repository/New-IcingaRepository.psm1 | 2 +- lib/core/repository/New-IcingaRepositoryFile.psm1 | 9 ++++++++- lib/core/repository/Sync-IcingaRepository.psm1 | 10 ++++++++-- lib/core/repository/Update-IcingaRepository.psm1 | 4 ++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 6a1f80c4..a42bf170 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -27,6 +27,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#635](https://github.com/Icinga/icinga-powershell-framework/pull/635) Adds support for `Write-IcingaAgentApiConfig` function to configure the Icinga Agent TLS cipher list setting by new argument `-CipherList` * [#640](https://github.com/Icinga/icinga-powershell-framework/issues/640) Adds support to set the flag `-NoSSLValidation` for Cmdlets `icinga` and `Install-Icinga`, to ignore errors on self-signed certificates within the environment * [#643](https://github.com/Icinga/icinga-powershell-framework/pull/643) Adds support for `-RebuildCache` flag on `icinga` cmd to rebuild component cache as well +* [#644](https://github.com/Icinga/icinga-powershell-framework/pull/644) Adds progress bar output to repository interaction (sync, update, new) instead of plain text output ## 1.10.1 (2022-12-20) diff --git a/lib/core/repository/New-IcingaRepository.psm1 b/lib/core/repository/New-IcingaRepository.psm1 index 74e23cb2..46681402 100644 --- a/lib/core/repository/New-IcingaRepository.psm1 +++ b/lib/core/repository/New-IcingaRepository.psm1 @@ -35,7 +35,7 @@ function New-IcingaRepository() return; } - $IcingaRepository = New-IcingaRepositoryFile -Path $Path -RemotePath $RemotePath; + $IcingaRepository = New-IcingaRepositoryFile -Path $Path -RemotePath $RemotePath -Name $Name; [array]$ConfigCount = $IcingaRepository.Packages.PSObject.Properties.Count; diff --git a/lib/core/repository/New-IcingaRepositoryFile.psm1 b/lib/core/repository/New-IcingaRepositoryFile.psm1 index f5f1763a..2d6a013e 100644 --- a/lib/core/repository/New-IcingaRepositoryFile.psm1 +++ b/lib/core/repository/New-IcingaRepositoryFile.psm1 @@ -2,7 +2,8 @@ function New-IcingaRepositoryFile() { param ( [string]$Path = $null, - [string]$RemotePath = $null + [string]$RemotePath = $null, + [string]$Name = '' ); $RepoFile = 'ifw.repo.json'; @@ -23,11 +24,15 @@ function New-IcingaRepositoryFile() $RepositoryFolder = Get-ChildItem -Path $Path -Recurse -Include '*.msi', '*.zip'; + New-IcingaProgressStatus -Name 'Updating Repository' -Message ([string]::Format('Update Icinga for Windows repository ({0}). Processed files', $Name)) -MaxValue $RepositoryFolder.Count -Details; + foreach ($entry in $RepositoryFolder) { $RepoFilePath = $entry.FullName.Replace($Path, ''); $FileHash = Get-FileHash -Path $entry.FullName -Algorithm SHA256; $ComponentName = ''; + Write-IcingaProgressStatus -Name 'Updating Repository'; + $IcingaForWindowsPackage = New-Object -TypeName PSObject; $IcingaForWindowsPackage | Add-Member -MemberType NoteProperty -Name 'Hash' -Value $FileHash.Hash; $IcingaForWindowsPackage | Add-Member -MemberType NoteProperty -Name 'Location' -Value $RepoFilePath; @@ -85,6 +90,8 @@ function New-IcingaRepositoryFile() $IcingaRepository.Info.RepoHash = Get-IcingaRepositoryHash -Path $Path; } + Complete-IcingaProgressStatus -Name 'Updating Repository'; + Write-IcingaFileSecure -File $RepoPath -Value (ConvertTo-Json -InputObject $IcingaRepository -Depth 100); return $IcingaRepository; diff --git a/lib/core/repository/Sync-IcingaRepository.psm1 b/lib/core/repository/Sync-IcingaRepository.psm1 index 59bf695d..29958119 100644 --- a/lib/core/repository/Sync-IcingaRepository.psm1 +++ b/lib/core/repository/Sync-IcingaRepository.psm1 @@ -116,10 +116,14 @@ function Sync-IcingaRepository() foreach ($component in $JsonRepo.Packages.PSObject.Properties.Name) { $IfWPackage = $JsonRepo.Packages.$component + New-IcingaProgressStatus -Name 'Sync Repository' -Message ([string]::Format('Syncing Icinga for Windows repository {0} ({1}). Downloaded {2} packages', $Name, $JsonRepo.Info.RemoteSource, $component)) -MaxValue $IfWPackage.Count -Details; + foreach ($package in $IfWPackage) { $DownloadLink = $package.Location; $TargetLocation = $TmpDir; + Write-IcingaProgressStatus -Name 'Sync Repository'; + if ($package.RelativePath -eq $TRUE) { $DownloadLink = Join-WebPath -Path $JsonRepo.Info.RemoteSource -ChildPath $package.Location; $TargetLocation = Join-Path -Path $TmpDir -ChildPath $package.Location; @@ -146,13 +150,15 @@ function Sync-IcingaRepository() } try { - Write-IcingaConsoleNotice 'Syncing repository component "{0}" as file "{1}" into temp directory' -Objects $component, $package.Location; + Write-IcingaConsoleDebug 'Syncing repository component "{0}" as file "{1}" into temp directory' -Objects $component, $package.Location; Invoke-IcingaWebRequest -UseBasicParsing -Uri $DownloadLink -OutFile $TargetLocation | Out-Null; } catch { Write-IcingaConsoleError 'Failed to download repository component "{0}". Exception: "{1}"' -Objects $DownloadLink, $_.Exception.Message; continue; } } + + Complete-IcingaProgressStatus -Name 'Sync Repository'; } } @@ -187,7 +193,7 @@ function Sync-IcingaRepository() } if ($HasNonRelative) { - [void](New-IcingaRepositoryFile -Path $TmpDir -RemotePath $RemotePath); + [void](New-IcingaRepositoryFile -Path $TmpDir -RemotePath $RemotePath -Name $Name); $RepoContent = Get-Content -Path $RepoFile -Raw; $JsonRepo = ConvertFrom-Json -InputObject $RepoContent; Start-Sleep -Seconds 2; diff --git a/lib/core/repository/Update-IcingaRepository.psm1 b/lib/core/repository/Update-IcingaRepository.psm1 index 22836abc..945a86f5 100644 --- a/lib/core/repository/Update-IcingaRepository.psm1 +++ b/lib/core/repository/Update-IcingaRepository.psm1 @@ -67,7 +67,7 @@ function Update-IcingaRepository() $SetRemotePath = $RemotePath; } - $IcingaRepository = New-IcingaRepositoryFile -Path $Path -RemotePath $SetRemotePath; + $IcingaRepository = New-IcingaRepositoryFile -Path $Path -RemotePath $SetRemotePath -Name $Name; if ($CreateNew) { return $IcingaRepository; @@ -97,7 +97,7 @@ function Update-IcingaRepository() $SetRemotePath = $RemotePath; } - Write-IcingaConsoleNotice 'Syncing repository "{0}"' -Objects $definedRepo.Name; + Write-IcingaConsoleDebug 'Syncing repository "{0}"' -Objects $definedRepo.Name; if ([string]::IsNullOrEmpty($definedRepo.Value.CloneSource) -eq $FALSE) { Sync-IcingaRepository `