From 88b0849e42db1424d671547555311f34b17f0289 Mon Sep 17 00:00:00 2001 From: Tomas Zabcik Date: Tue, 15 Oct 2024 10:07:35 +0200 Subject: [PATCH] Missing Function Download-BcEnvironmentInstalledExtensionToFolder (#3703) (#3705) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Missing Function Download-BcEnvironmentInstalledExtensionToFolder @microsoft-github-policy-service agree --------- Co-authored-by: Tomáš Žabčík Co-authored-by: Freddy Kristiansen --- BC.SaasHelper.ps1 | 1 + BcContainerHelper.psd1 | 2 +- ReleaseNotes.txt | 1 + ...cEnvironmentInstalledExtensionToFolder.ps1 | 92 +++++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 Saas/Download-BcEnvironmentInstalledExtensionToFolder.ps1 diff --git a/BC.SaasHelper.ps1 b/BC.SaasHelper.ps1 index 727999c8d..a57e9c5ab 100644 --- a/BC.SaasHelper.ps1 +++ b/BC.SaasHelper.ps1 @@ -22,3 +22,4 @@ . (Join-Path $PSScriptRoot "Saas\Set-BcEnvironmentApplicationInsightsKey.ps1") . (Join-Path $PSScriptRoot "Saas\Set-BcEnvironmentUpdateWindow.ps1") . (Join-Path $PSScriptRoot "Saas\Wait-BcEnvironmentReady.ps1") +. (Join-Path $PSScriptRoot "Saas\Download-BcEnvironmentInstalledExtensionToFolder.ps1") \ No newline at end of file diff --git a/BcContainerHelper.psd1 b/BcContainerHelper.psd1 index 4017a55ad..938d7a3ef 100644 --- a/BcContainerHelper.psd1 +++ b/BcContainerHelper.psd1 @@ -111,7 +111,7 @@ FunctionsToExport = 'Add-FontsToBcContainer', 'Add-GitToAlProjectFolder', 'Get-BcContainerSharedFolders', 'Get-BcContainerTenants', 'Get-BcEnvironmentAvailableRestorePeriods', 'Get-BcEnvironmentDatabaseExportHistory', - 'Get-BcEnvironmentInstalledExtensions', + 'Get-BcEnvironmentInstalledExtensions', 'Download-BcEnvironmentInstalledExtensionToFolder', 'Get-BcEnvironmentOperations', 'Get-BcEnvironmentPublishedApps', 'Get-BcEnvironments', 'Get-BcEnvironmentScheduledUpgrade', 'Get-BcEnvironmentUpdateWindow', 'Get-BcEnvironmentUsedStorage', diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 1524c58e6..8d88fedfd 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -8,6 +8,7 @@ Include AI Toolkit when copying symbols from container Issue 3714 Download-BcNuGetPackageToFolder - throws error when use "-select Exact" Issue 3621 New-AadAppsForBc shows "-includeEmailAadApp is deprecated. Use -includeOtherServicesAadApp instead." but includeOtherServicesAadApp us not setting email permissions Issue 3718 Business Central Web Client Fails to Load After Updating to Windows 24H2 +Issue #3703 Missing Function Download-BcEnvironmentInstalledExtensionToFolder 6.0.25 Fix issue where generateDependencyArtifact doesn't result in dependencies if useCompilerFolder is true or filesonly containers are used in Run-AlPipeline diff --git a/Saas/Download-BcEnvironmentInstalledExtensionToFolder.ps1 b/Saas/Download-BcEnvironmentInstalledExtensionToFolder.ps1 new file mode 100644 index 000000000..d5289e010 --- /dev/null +++ b/Saas/Download-BcEnvironmentInstalledExtensionToFolder.ps1 @@ -0,0 +1,92 @@ +<# + .Synopsis + Function for downloading Installed Extensions (symbols) from an online Business Central environment (both AppSource and PTEs) + .Description + Function for downloading Installed Extensions (symbols) from an online Business Central environment (both AppSource and PTEs) + .Parameter bcAuthContext + Authorization Context created by New-BcAuthContext. + .Parameter environment + Environment from which you want to return the published Apps. + .Parameter apiVersion + API version. Default is v2.0. + .Parameter folder + Folder in which the symbols of dependent apps will be placed. Default is $appProjectFolder\symbols. + .Parameter appPublisher + Publisher of the app you want to download + .Parameter appName + Name of the app you want to download + .Parameter appVersion + Version of the app you want to download + .Parameter appId + Id of the app you want to download + .EXAMPLE + $appSymbolsFolder = Join-Path $compilerFolder 'symbols' + $bcAuthContext = New-BcAuthContext -includeDeviceLogin -tenantID $tenant + $publishedApps = (Get-BcEnvironmentInstalledExtensions -bcAuthContext $bcAuthContext -environment $environment | ForEach-Object { @{ "Publisher" = $_.Publisher; "Name" = $_.displayName; "Id" = $_.Id; "Version" = [System.Version]::new($_.VersionMajor, $_.VersionMinor, $_.VersionBuild, $_.VersionRevision) } }) + foreach ($app in $publishedApps) { + Download-BcEnvironmentInstalledExtensionToFolder -bcAuthContext $bcAuthContext -environment $environment -appName $app.Name -appId $app.Id -appVersion $app.Version -appPublisher $app.Publisher -folder $appSymbolsFolder + } + Download-BcEnvironmentInstalledExtensionToFolder -bcAuthContext $bcAuthContext -environment $environment -appName "System" -appVersion "1.0.0.0" -appPublisher "Microsoft" -folder $appSymbolsFolder +#> +function Download-BcEnvironmentInstalledExtensionToFolder { + param ( + [Parameter(Mandatory = $true)] + [Hashtable] $bcAuthContext, + [string] $environment, + [string] $apiVersion = "v2.0", + [Parameter(Mandatory = $true)] + [alias('appSymbolsFolder')] + [string] $folder, + [Parameter(Mandatory = $true)] + [string] $appPublisher, + [Parameter(Mandatory = $true)] + [string] $appName, + [Parameter(Mandatory = $true)] + [string] $appVersion = '0.0.0.0', + [Parameter(Mandatory = $false)] + [string] $appId + ) + $telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @() + try { + $bcAuthContext = Renew-BcAuthContext -bcAuthContext $bcAuthContext + $bearerAuthValue = "Bearer $($bcAuthContext.AccessToken)" + $headers = @{ "Authorization" = $bearerAuthValue } + + #WARNING: The file name downloaded may not match the one on the server, as the server only returns the file's content. When requesting the file, I specify the name, publisher, version, and even the ID, but only the ID remains consistent. + $symbolsName = "$($appPublisher)_$($appName)_$($appVersion).app".Split([System.IO.Path]::GetInvalidFileNameChars()) -join '' + Write-Host "Downloading symbols: $symbolsName" + + $symbolsFile = (Join-Path $folder $symbolsName) + Write-Host "symbolsFile: $symbolsFile" + + $devServerUrl = "$($bcContainerHelperConfig.apiBaseUrl.TrimEnd('/'))/$apiVersion/$environment" + + if ($appId) { + $url = "$devServerUrl/dev/packages?appId=$($appId)&versionText=$($appVersion)" + } + else { + $url = "$devServerUrl/dev/packages?publisher=$($appPublisher)&appName=$($appName)&versionText=$($appVersion)" + } + + Write-Host "url: $url" + + try { + DownloadFileLow -sourceUrl $url -destinationFile $symbolsFile -Headers $headers + } + catch { + $throw = $true + if ($throw) { + Write-Host "ERROR $($_.Exception.Message)" + throw (GetExtendedErrorMessage $_) + } + } + } + catch { + TrackException -telemetryScope $telemetryScope -errorRecord $_ + throw + } + finally { + TrackTrace -telemetryScope $telemetryScope + } +} +Export-ModuleMember -Function Download-BcEnvironmentInstalledExtensionToFolder