-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Missing Function Download-BcEnvironmentInstalledExtensionToFolder (#3703
) (#3705) Add Missing Function Download-BcEnvironmentInstalledExtensionToFolder @microsoft-github-policy-service agree --------- Co-authored-by: Tomáš Žabčík <[email protected]> Co-authored-by: Freddy Kristiansen <[email protected]>
- Loading branch information
1 parent
7816870
commit 88b0849
Showing
4 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
[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 |