Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Function Download-BcEnvironmentInstalledExtensionToFolder (#3703) #3705

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BC.SaasHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion BcContainerHelper.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 92 additions & 0 deletions Saas/Download-BcEnvironmentInstalledExtensionToFolder.ps1
Original file line number Diff line number Diff line change
@@ -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',
freddydk marked this conversation as resolved.
Show resolved Hide resolved
[Parameter(Mandatory = $false)]
[string] $appId
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
zabcik marked this conversation as resolved.
Show resolved Hide resolved
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