This commit is contained in:
Freddy Kristiansen 2021-08-20 14:09:03 +02:00
Родитель 56150977d3
Коммит 7fdd97181e
51 изменённых файлов: 1048 добавлений и 623 удалений

Просмотреть файл

@ -30,7 +30,7 @@ function Get-BcContainerApiCompanyId {
[switch] $silent
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @("accept_eula")
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @("")
try {
if (!($CompanyName)) {

Просмотреть файл

@ -36,6 +36,7 @@ try {
Write-Host "Committing files"
& git commit -m $commitMessage --quiet
Set-Location $oldLocation
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_

Просмотреть файл

@ -34,6 +34,8 @@ function New-LetsEncryptCertificate {
[Parameter(Mandatory=$false)]
[string] $dnsAlias = "dnsAlias"
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$stateDir = Join-Path $hostHelperFolder "acmeState"
Write-Host "Importing ACME-PS module (need 1.1.0-beta or higher)"
@ -50,4 +52,12 @@ function New-LetsEncryptCertificate {
Renew-LetsEncryptCertificate -publicDnsName $publicDnsName -certificatePfxFilename $certificatePfxFilename -certificatePfxPassword $certificatePfxPassword
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function New-LetsEncryptCertificate

Просмотреть файл

@ -27,6 +27,9 @@ function Renew-LetsEncryptCertificate {
[string] $dnsAlias = "dnsAlias"
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Write-Host "Importing ACME-PS module (need 1.1.0-beta or higher)"
Import-Module ACME-PS
@ -88,4 +91,12 @@ function Renew-LetsEncryptCertificate {
Write-Host "Exporting certificate to $certificatePfxFilename"
Export-ACMECertificate $state -Order $order -CertificateKey $certKey -Path $certificatePfxFilename -Password $certificatePfxPassword
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Renew-LetsEncryptCertificate

Просмотреть файл

@ -34,6 +34,9 @@ function Replace-BcServerContainer {
[hashtable] $bcAuthContext
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$SetupBcContainerScript = "C:\DEMO\Setup*Container.ps1"
$setupDesktopScript = "C:\DEMO\SetupDesktop.ps1"
$settingsScript = "C:\DEMO\settings.ps1"
@ -122,5 +125,13 @@ function Replace-BcServerContainer {
. $SetupBcContainerScript
. $setupDesktopScript
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Replace-NavServerContainer -Value Replace-BcServerContainer
Export-ModuleMember -Function Replace-BcServerContainer -Alias Replace-NavServerContainer

Просмотреть файл

@ -24,10 +24,8 @@ function Extract-FilesFromBcContainerImage {
[switch] $force
)
# $artifactUrl = Get-BcContainerArtifactUrl -containerName $imageName
# if ($artifactUrl) {
# throw "Extract-FilesFromBcContainerImage doesn't support images based on artifacts."
# }
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$ErrorActionPreference = 'Continue'
@ -47,5 +45,13 @@ function Extract-FilesFromBcContainerImage {
$ErrorActionPreference = 'Stop'
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Extract-FilesFromNavContainerImage -Value Extract-FilesFromBcContainerImage
Export-ModuleMember -Function Extract-FilesFromBcContainerImage -Alias Extract-FilesFromNavContainerImage

Просмотреть файл

@ -24,6 +24,9 @@ function Extract-FilesFromStoppedBcContainer {
[switch] $force
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$artifactUrl = Get-BcContainerArtifactUrl -containerName $containerName
if ($artifactUrl) {
throw "Extract-FilesFromStoppedBcContainer doesn't support containers based on artifacts."
@ -205,5 +208,13 @@ function Extract-FilesFromStoppedBcContainer {
Start-BcContainer -containerName $containerName
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Extract-FilesFromStoppedNavContainer -Value Extract-FilesFromStoppedBcContainer
Export-ModuleMember -Function Extract-FilesFromStoppedBcContainer -Alias Extract-FilesFromStoppedNavContainer

Просмотреть файл

@ -25,6 +25,9 @@ function Flush-ContainerHelperCache {
[int] $keepDays = 0
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$caches = $cache.ToLowerInvariant().Split(',')
$folders = @()
@ -149,4 +152,12 @@ function Flush-ContainerHelperCache {
Write-Host "Completed"
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Flush-ContainerHelperCache

Просмотреть файл

@ -11,6 +11,9 @@ function Get-AlLanguageExtensionFromArtifacts {
[string] $artifactUrl
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$paths = Download-Artifacts $artifactUrl -includePlatform
$vsixFile = Get-Item -Path (Join-Path $paths[1] "ModernDev\program files\Microsoft Dynamics NAV\*\AL Development Environment\*.vsix")
if ($vsixFile) {
@ -20,4 +23,12 @@ function Get-AlLanguageExtensionFromArtifacts {
throw "Unable to locate AL Language Extension from artifacts $($artifactUrl.Split('?')[0])"
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Get-AlLanguageExtensionFromArtifacts

Просмотреть файл

@ -13,6 +13,9 @@ function Get-BestGenericImageName {
[switch] $filesOnly
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if ($hostOsVersion -eq $null) {
$os = (Get-CimInstance Win32_OperatingSystem)
if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) {
@ -251,4 +254,12 @@ function Get-BestGenericImageName {
$genericImageName
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Get-BestGenericImageName

Просмотреть файл

@ -15,6 +15,9 @@ function Get-BestBcContainerImageName {
[string] $imageName
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if (!(
$imagename.EndsWith('-ltsc2016') -or
$imagename.EndsWith('-1709') -or
@ -56,5 +59,13 @@ function Get-BestBcContainerImageName {
$imageName
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-BestNavContainerImageName -Value Get-BestBcContainerImageName
Export-ModuleMember -Function Get-BestBcContainerImageName -Alias Get-BestNavContainerImageName

Просмотреть файл

@ -9,6 +9,9 @@
Download-File -SourceUrl (Get-LatestAlLanguageExtensionUrl) -DestinationFile "c:\temp\al.vsix"
#>
function Get-LatestAlLanguageExtensionUrl {
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$listing = Invoke-WebRequest -Method POST -UseBasicParsing `
-Uri https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery?api-version=3.0-preview.1 `
-Body '{"filters":[{"criteria":[{"filterType":8,"value":"Microsoft.VisualStudio.Code"},{"filterType":12,"value":"4096"},{"filterType":7,"value":"ms-dynamics-smb.al"}],"pageNumber":1,"pageSize":50,"sortBy":0,"sortOrder":0}],"assetTypes":[],"flags":914}' `
@ -27,4 +30,12 @@ function Get-LatestAlLanguageExtensionUrl {
throw "Unable to locate latest AL Language Extension from the VS Code Marketplace"
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Get-LatestAlLanguageExtensionUrl

Просмотреть файл

@ -22,6 +22,9 @@ function Import-BcContainerLicense {
[switch] $restart
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$containerLicenseFile = Join-Path $ExtensionsFolder "$containerName\my\license$([System.IO.Path]::GetExtension($licenseFile))"
if ($licensefile.StartsWith("https://", "OrdinalIgnoreCase") -or $licensefile.StartsWith("http://", "OrdinalIgnoreCase")) {
Write-Host "Downloading license file '$licensefile' to container"
@ -62,5 +65,13 @@ function Import-BcContainerLicense {
} -ArgumentList (Get-BcContainerPath -ContainerName $containerName -Path $containerLicenseFile), $restart
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Import-NavContainerLicense -Value Import-BcContainerLicense
Export-ModuleMember -Function Import-BcContainerLicense -Alias Import-NavContainerLicense

Просмотреть файл

@ -479,6 +479,7 @@ try {
}
Write-Host "Docker Client Version is $dockerClientVersion"
AddTelemetryProperty -telemetryScope $telemetryScope -key "DockerClientVersion" -value $dockerClientVersion
AddTelemetryProperty -telemetryScope $telemetryScope -key "DockerClientVersion" -value 55
$myClientVersion = [System.Version]"0.0.0"
if (!(([System.Version]::TryParse($dockerClientVersion, [ref]$myClientVersion)) -and ($myClientVersion -ge ([System.Version]"18.03.0")))) {

Просмотреть файл

@ -49,6 +49,9 @@ function New-BcImage {
$allImages
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if ($memory -eq "") {
$memory = "8G"
}
@ -580,5 +583,13 @@ LABEL legal="http://go.microsoft.com/fwlink/?LinkId=837447" \
$buildMutex.ReleaseMutex()
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name New-NavImage -Value New-BcImage
Export-ModuleMember -Function New-BcImage -Alias New-NavImage

Просмотреть файл

@ -15,99 +15,108 @@ function Remove-BcContainer {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)
Process {
$hostname = ""
if (Test-BcContainer -containerName $containerName) {
try {
$id = Get-BcContainerId -containerName $containerName
if ($id) {
$inspect = docker inspect $id | ConvertFrom-Json
$hostname = $inspect.config.Hostname
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$hostname = ""
if (Test-BcContainer -containerName $containerName) {
try {
$id = Get-BcContainerId -containerName $containerName
if ($id) {
$inspect = docker inspect $id | ConvertFrom-Json
$hostname = $inspect.config.Hostname
}
catch {
$hostname = ""
}
Remove-BcContainerSession $containerName
$containerId = Get-BcContainerId -containerName $containerName
Write-Host "Removing container $containerName"
docker rm $containerId -f | Out-Null
}
if ($containerName) {
if ($hostname -eq "") {
$hostname = $containerName
catch {
$hostname = ""
}
Remove-BcContainerSession $containerName
$containerId = Get-BcContainerId -containerName $containerName
Write-Host "Removing container $containerName"
docker rm $containerId -f | Out-Null
}
if ($containerName) {
if ($hostname -eq "") {
$hostname = $containerName
}
$dotidx = $hostname.indexOf('.')
if ($dotidx -eq -1) { $dotidx = $hostname.Length }
$tenantHostname = $hostname.insert($dotidx,"-*")
$containerFolder = Join-Path $ExtensionsFolder $containerName
$updateHostsScript = Join-Path $containerFolder "my\updatehosts.ps1"
$updateHosts = Test-Path -Path $updateHostsScript -PathType Leaf
if ($updateHosts) {
. (Join-Path $PSScriptRoot "updatehosts.ps1") -hostsFile "c:\windows\system32\drivers\etc\hosts" -theHostname $hostname -theIpAddress ""
. (Join-Path $PSScriptRoot "updatehosts.ps1") -hostsFile "c:\windows\system32\drivers\etc\hosts" -theHostname $tenantHostname -theIpAddress ""
}
$thumbprintFile = Join-Path $containerFolder "thumbprint.txt"
if (Test-Path -Path $thumbprintFile) {
$thumbprint = Get-Content -Path $thumbprintFile
$cert = Get-ChildItem "cert:\localMachine\Root" | Where-Object { $_.Thumbprint -eq $thumbprint }
if ($cert) {
$cert | Remove-Item
Write-Host "Certificate with thumbprint $thumbprint removed successfully"
}
$dotidx = $hostname.indexOf('.')
if ($dotidx -eq -1) { $dotidx = $hostname.Length }
$tenantHostname = $hostname.insert($dotidx,"-*")
$containerFolder = Join-Path $ExtensionsFolder $containerName
$updateHostsScript = Join-Path $containerFolder "my\updatehosts.ps1"
$updateHosts = Test-Path -Path $updateHostsScript -PathType Leaf
if ($updateHosts) {
. (Join-Path $PSScriptRoot "updatehosts.ps1") -hostsFile "c:\windows\system32\drivers\etc\hosts" -theHostname $hostname -theIpAddress ""
. (Join-Path $PSScriptRoot "updatehosts.ps1") -hostsFile "c:\windows\system32\drivers\etc\hosts" -theHostname $tenantHostname -theIpAddress ""
else {
Write-Host "Certificate with thumbprint $thumbprint not found in store"
}
$thumbprintFile = Join-Path $containerFolder "thumbprint.txt"
if (Test-Path -Path $thumbprintFile) {
$thumbprint = Get-Content -Path $thumbprintFile
$cert = Get-ChildItem "cert:\localMachine\Root" | Where-Object { $_.Thumbprint -eq $thumbprint }
if ($cert) {
$cert | Remove-Item
Write-Host "Certificate with thumbprint $thumbprint removed successfully"
}
Remove-DesktopShortcut -Name "$containerName Web Client"
Remove-DesktopShortcut -Name "$containerName Test Tool"
Remove-DesktopShortcut -Name "$containerName Windows Client"
Remove-DesktopShortcut -Name "$containerName WinClient Debugger"
Remove-DesktopShortcut -Name "$containerName CSIDE"
Remove-DesktopShortcut -Name "$containerName Command Prompt"
Remove-DesktopShortcut -Name "$containerName PowerShell Prompt"
if (Test-Path $containerFolder) {
$wait = 10
$attempts = 0
$filesLeft = $true
Write-Host "Removing $containerFolder"
while ($filesLeft) {
$files = @()
Get-ChildItem $containerfolder -Recurse -File | % {
$file = $_.FullName
try {
Remove-Item $file -Force -ErrorAction stop
}
catch {
$files += $file
}
}
if ($files.count -eq 0) {
$filesLeft = $false
}
else {
Write-Host "Certificate with thumbprint $thumbprint not found in store"
$attempts++
if ($attempts -gt 10) {
throw "Could not remove $containerFolder"
}
Write-Host "Error removing $containerFolder (attempts: $attempts)"
Write-Host "The following files could not be removed:"
$files | % {
Write-Host "- $_"
}
Write-Host "Please close any apps, prompts or files using these files"
Write-Host "Retrying in $wait seconds"
Start-Sleep -Seconds $wait
}
}
Remove-DesktopShortcut -Name "$containerName Web Client"
Remove-DesktopShortcut -Name "$containerName Test Tool"
Remove-DesktopShortcut -Name "$containerName Windows Client"
Remove-DesktopShortcut -Name "$containerName WinClient Debugger"
Remove-DesktopShortcut -Name "$containerName CSIDE"
Remove-DesktopShortcut -Name "$containerName Command Prompt"
Remove-DesktopShortcut -Name "$containerName PowerShell Prompt"
if (Test-Path $containerFolder) {
$wait = 10
$attempts = 0
$filesLeft = $true
Write-Host "Removing $containerFolder"
while ($filesLeft) {
$files = @()
Get-ChildItem $containerfolder -Recurse -File | % {
$file = $_.FullName
try {
Remove-Item $file -Force -ErrorAction stop
}
catch {
$files += $file
}
}
if ($files.count -eq 0) {
$filesLeft = $false
}
else {
$attempts++
if ($attempts -gt 10) {
throw "Could not remove $containerFolder"
}
Write-Host "Error removing $containerFolder (attempts: $attempts)"
Write-Host "The following files could not be removed:"
$files | % {
Write-Host "- $_"
}
Write-Host "Please close any apps, prompts or files using these files"
Write-Host "Retrying in $wait seconds"
Start-Sleep -Seconds $wait
}
}
Remove-Item -Path $containerFolder -Force -Recurse -ErrorAction SilentlyContinue
}
Remove-Item -Path $containerFolder -Force -Recurse -ErrorAction SilentlyContinue
}
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Remove-NavContainer -Value Remove-BcContainer
Export-ModuleMember -Function Remove-BcContainer -Alias Remove-NavContainer

Просмотреть файл

@ -23,6 +23,9 @@ function Restart-BcContainer {
[int] $timeout = 1800
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if ($renewBindings) {
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock {
Set-Content -Path "c:\run\PublicDnsName.txt" -Value ""
@ -36,5 +39,13 @@ function Restart-BcContainer {
Wait-BcContainerReady -containerName $containerName -timeout $timeout
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Restart-NavContainer -Value Restart-BcContainer
Export-ModuleMember -Function Restart-BcContainer -Alias Restart-NavContainer

Просмотреть файл

@ -31,6 +31,9 @@ function Set-BcContainerKeyVaultAadAppAndCertificate {
[switch] $doNotRestartServiceTier
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$ExtensionsFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions"
$containerPfxFile = Join-Path $ExtensionsFolder "$containerName\my\certificate.pfx"
if ($pfxFile -like "https://*" -or $pfxFile -like "http://*") {
@ -71,4 +74,12 @@ function Set-BcContainerKeyVaultAadAppAndCertificate {
}
} -argumentList $containerPfxFile, $pfxPassword, $clientId, $enablePublisherValidation, $doNotRestartServiceTier
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Set-BcContainerKeyVaultAadAppAndCertificate

Просмотреть файл

@ -56,142 +56,150 @@ function Setup-TraefikContainerForBcContainers {
[string[]] $additionalParameters = @()
)
Process {
$traefikForBcBasePath = "c:\programdata\bccontainerhelper\traefikforbc"
$traefikDockerImage = "traefik:v1.7-windowsservercore-1809"
$traefiktomltemplate = (Join-Path $traefikForBcBasePath "config\template_traefik.toml")
if ("$traefikToml" -eq "") {
if ($PSCmdlet.ParameterSetName -eq "OwnCertificate") {
if ($forceHttpWithTraefik) {
$traefikToml = (Join-Path $PSScriptRoot "traefik\template_traefik_own.toml")
}
else {
$traefikToml = (Join-Path $PSScriptRoot "traefik\template_traefik_https_own.toml")
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$traefikForBcBasePath = "c:\programdata\bccontainerhelper\traefikforbc"
$traefikDockerImage = "traefik:v1.7-windowsservercore-1809"
$traefiktomltemplate = (Join-Path $traefikForBcBasePath "config\template_traefik.toml")
if ("$traefikToml" -eq "") {
if ($PSCmdlet.ParameterSetName -eq "OwnCertificate") {
if ($forceHttpWithTraefik) {
$traefikToml = (Join-Path $PSScriptRoot "traefik\template_traefik_own.toml")
}
else {
if ($forceHttpWithTraefik) {
$traefikToml = (Join-Path $PSScriptRoot "traefik\template_traefik.toml")
}
else {
$traefikToml = (Join-Path $PSScriptRoot "traefik\template_traefik_https.toml")
}
$traefikToml = (Join-Path $PSScriptRoot "traefik\template_traefik_https_own.toml")
}
}
$CrtFilePath = (Join-Path $traefikForBcBasePath "config\certificate.crt")
$CrtKeyFilePath = (Join-Path $traefikForBcBasePath "config\certificate.key")
if ($Recreate){
Write-Host "Removing running Instances of the Traefik container"
docker images --filter "label=org.label-schema.name=Traefik" --format "{{.ID}}" | ForEach-Object { docker ps --filter ancestor=$_ --format "{{.ID}}" } | ForEach-Object { docker rm $_ -f }
Write-Host "Removing old Traefik configuration"
if (Test-Path -Path $traefikForBcBasePath){
remove-item -Path $traefikForBcBasePath -Recurse -force
}
}
if (Test-Path -Path (Join-Path $traefikForBcBasePath "traefik.txt") -PathType Leaf) {
Write-Host "Traefik container already initialized."
return
}
if ($traefikToml -is [string]) {
if ($traefikToml.ToLower().StartsWith("http://") -or $traefikToml.ToLower().StartsWith("https://")) {
$traefikTomlFile = (Join-Path $PSScriptRoot "traefik\template_traefik_custom.toml")
(New-Object System.Net.WebClient).DownloadFile($traefikToml, $traefikTomlFile)
} else {
if (!(Test-Path $traefikToml)) {
throw "File $traefikToml does not exist"
} else {
$traefikTomlFile = $traefikToml
}
}
} else {
throw "Illegal value in traefikToml"
}
Write-Host "Creating folder structure at $traefikForBcBasePath"
New-Item $traefikForBcBasePath -ItemType Directory
New-Item (Join-Path $traefikForBcBasePath "traefik.txt") -ItemType File
New-Item (Join-Path $traefikForBcBasePath "my") -ItemType Directory
New-Item (Join-Path $traefikForBcBasePath "config") -ItemType Directory
New-Item (Join-Path $traefikForBcBasePath "config\acme.json") -ItemType File
Copy-Item $traefikTomlFile -Destination $traefiktomltemplate
if ($forceHttpWithTraefik) {
Copy-Item (Join-Path $PSScriptRoot "traefik\CheckHealth.ps1") -Destination (Join-Path $traefikForBcBasePath "my\CheckHealth.ps1")
} else {
Copy-Item (Join-Path $PSScriptRoot "traefik\CheckHealth_https.ps1") -Destination (Join-Path $traefikForBcBasePath "my\CheckHealth.ps1")
}
if($CrtFile) {
if ($CrtFile -is [string]) {
if ($CrtFile.ToLower().StartsWith("http://") -or $CrtFile.ToLower().StartsWith("https://")) {
(New-Object System.Net.WebClient).DownloadFile($CrtFile, $CrtFilePath)
} else {
if (!(Test-Path $CrtFile)) {
throw "File $CrtFile does not exist"
} else {
Copy-Item $CrtFile -Destination $CrtFilePath
}
}
} else {
throw "Illegal value in CrtFile"
}
}
if($CrtKeyFile) {
if ($CrtKeyFile -is [string]) {
if ($CrtKeyFile.ToLower().StartsWith("http://") -or $CrtKeyFile.ToLower().StartsWith("https://")) {
(New-Object System.Net.WebClient).DownloadFile($CrtKeyFile, $CrtKeyFilePath)
} else {
if (!(Test-Path $CrtKeyFile)) {
throw "File $CrtKeyFile does not exist"
} else {
Copy-Item $CrtKeyFile -Destination $CrtKeyFilePath
}
}
} else {
throw "Illegal value in CertKeyFile"
}
}
Write-Host "Create traefik config file"
$template = Get-Content $traefiktomltemplate -Raw
if ($IP -eq "") {
$IP = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object PrefixOrigin -eq "Dhcp" | Select-Object -First 1).IPAddress
}
$expanded = Invoke-Expression "@`"`r`n$template`r`n`"@"
$expanded | Out-File (Join-Path $traefikForBcBasePath "config\traefik.toml") -Encoding ASCII
if ($overrideDefaultBinding) {
Write-Host "Change standard port as Traefik will handle that. Content previously avaiable on port 80 will be available on 8180"
Set-WebBinding -Name 'Default Web Site' -BindingInformation "*:80:" -PropertyName Port -Value 8180
New-NetFirewallRule -DisplayName "Allow 8180" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8180
}
$pullRequired = "$(docker images -q $traefikDockerImage)" -eq ""
if ($pullRequired) {
Write-Host "Pulling traefik"
docker pull $traefikDockerImage
}
else {
Write-Host "Traefik image already up to date"
if ($forceHttpWithTraefik) {
$traefikToml = (Join-Path $PSScriptRoot "traefik\template_traefik.toml")
}
else {
$traefikToml = (Join-Path $PSScriptRoot "traefik\template_traefik_https.toml")
}
}
$parameters = @("-p 443:443", "-p 80:80", "--restart always", "-v ""$(Join-Path $traefikForBcBasePath "config"):c:/etc/traefik""", "-v \\.\pipe\docker_engine:\\.\pipe\docker_engine")
if (!$doNotPublishAdminPort) {
$parameters += @("-p 8080:8080")
}
if ($isolation) {
$parameters += "--isolation $isolation"
}
$parameters += $additionalParameters
Write-Host "Running traefik"
DockerDo -command run -imageName "$traefikDockerImage --docker.endpoint=npipe:////./pipe/docker_engine" -detach -parameters $parameters
}
$CrtFilePath = (Join-Path $traefikForBcBasePath "config\certificate.crt")
$CrtKeyFilePath = (Join-Path $traefikForBcBasePath "config\certificate.key")
if ($Recreate){
Write-Host "Removing running Instances of the Traefik container"
docker images --filter "label=org.label-schema.name=Traefik" --format "{{.ID}}" | ForEach-Object { docker ps --filter ancestor=$_ --format "{{.ID}}" } | ForEach-Object { docker rm $_ -f }
Write-Host "Removing old Traefik configuration"
if (Test-Path -Path $traefikForBcBasePath){
remove-item -Path $traefikForBcBasePath -Recurse -force
}
}
if (Test-Path -Path (Join-Path $traefikForBcBasePath "traefik.txt") -PathType Leaf) {
Write-Host "Traefik container already initialized."
return
}
if ($traefikToml -is [string]) {
if ($traefikToml.ToLower().StartsWith("http://") -or $traefikToml.ToLower().StartsWith("https://")) {
$traefikTomlFile = (Join-Path $PSScriptRoot "traefik\template_traefik_custom.toml")
(New-Object System.Net.WebClient).DownloadFile($traefikToml, $traefikTomlFile)
} else {
if (!(Test-Path $traefikToml)) {
throw "File $traefikToml does not exist"
} else {
$traefikTomlFile = $traefikToml
}
}
} else {
throw "Illegal value in traefikToml"
}
Write-Host "Creating folder structure at $traefikForBcBasePath"
New-Item $traefikForBcBasePath -ItemType Directory
New-Item (Join-Path $traefikForBcBasePath "traefik.txt") -ItemType File
New-Item (Join-Path $traefikForBcBasePath "my") -ItemType Directory
New-Item (Join-Path $traefikForBcBasePath "config") -ItemType Directory
New-Item (Join-Path $traefikForBcBasePath "config\acme.json") -ItemType File
Copy-Item $traefikTomlFile -Destination $traefiktomltemplate
if ($forceHttpWithTraefik) {
Copy-Item (Join-Path $PSScriptRoot "traefik\CheckHealth.ps1") -Destination (Join-Path $traefikForBcBasePath "my\CheckHealth.ps1")
} else {
Copy-Item (Join-Path $PSScriptRoot "traefik\CheckHealth_https.ps1") -Destination (Join-Path $traefikForBcBasePath "my\CheckHealth.ps1")
}
if($CrtFile) {
if ($CrtFile -is [string]) {
if ($CrtFile.ToLower().StartsWith("http://") -or $CrtFile.ToLower().StartsWith("https://")) {
(New-Object System.Net.WebClient).DownloadFile($CrtFile, $CrtFilePath)
} else {
if (!(Test-Path $CrtFile)) {
throw "File $CrtFile does not exist"
} else {
Copy-Item $CrtFile -Destination $CrtFilePath
}
}
} else {
throw "Illegal value in CrtFile"
}
}
if($CrtKeyFile) {
if ($CrtKeyFile -is [string]) {
if ($CrtKeyFile.ToLower().StartsWith("http://") -or $CrtKeyFile.ToLower().StartsWith("https://")) {
(New-Object System.Net.WebClient).DownloadFile($CrtKeyFile, $CrtKeyFilePath)
} else {
if (!(Test-Path $CrtKeyFile)) {
throw "File $CrtKeyFile does not exist"
} else {
Copy-Item $CrtKeyFile -Destination $CrtKeyFilePath
}
}
} else {
throw "Illegal value in CertKeyFile"
}
}
Write-Host "Create traefik config file"
$template = Get-Content $traefiktomltemplate -Raw
if ($IP -eq "") {
$IP = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object PrefixOrigin -eq "Dhcp" | Select-Object -First 1).IPAddress
}
$expanded = Invoke-Expression "@`"`r`n$template`r`n`"@"
$expanded | Out-File (Join-Path $traefikForBcBasePath "config\traefik.toml") -Encoding ASCII
if ($overrideDefaultBinding) {
Write-Host "Change standard port as Traefik will handle that. Content previously avaiable on port 80 will be available on 8180"
Set-WebBinding -Name 'Default Web Site' -BindingInformation "*:80:" -PropertyName Port -Value 8180
New-NetFirewallRule -DisplayName "Allow 8180" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8180
}
$pullRequired = "$(docker images -q $traefikDockerImage)" -eq ""
if ($pullRequired) {
Write-Host "Pulling traefik"
docker pull $traefikDockerImage
}
else {
Write-Host "Traefik image already up to date"
}
$parameters = @("-p 443:443", "-p 80:80", "--restart always", "-v ""$(Join-Path $traefikForBcBasePath "config"):c:/etc/traefik""", "-v \\.\pipe\docker_engine:\\.\pipe\docker_engine")
if (!$doNotPublishAdminPort) {
$parameters += @("-p 8080:8080")
}
if ($isolation) {
$parameters += "--isolation $isolation"
}
$parameters += $additionalParameters
Write-Host "Running traefik"
DockerDo -command run -imageName "$traefikDockerImage --docker.endpoint=npipe:////./pipe/docker_engine" -detach -parameters $parameters
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Setup-TraefikContainerForNavContainers -Value Setup-TraefikContainerForBcContainers
Export-ModuleMember -Function Setup-TraefikContainerForBcContainers -Alias Setup-TraefikContainerForNavContainers

Просмотреть файл

@ -16,16 +16,25 @@ function Get-BcContainerArtifactUrl {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)
Process {
$inspect = docker inspect $containerName | ConvertFrom-Json
$artifactUrlEnv = $inspect.config.Env | Where-Object { $_ -like "artifactUrl=*" }
if ($artifactUrlEnv) {
return $artifactUrlEnv.SubString("artifactUrl=".Length)
}
else {
return ""
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerName | ConvertFrom-Json
$artifactUrlEnv = $inspect.config.Env | Where-Object { $_ -like "artifactUrl=*" }
if ($artifactUrlEnv) {
return $artifactUrlEnv.SubString("artifactUrl=".Length)
}
else {
return ""
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerArtifactUrl -Value Get-BcContainerArtifactUrl
Export-ModuleMember -Function Get-BcContainerArtifactUrl -Alias Get-NavContainerArtifactUrl

Просмотреть файл

@ -17,13 +17,23 @@ function Get-BcContainerCountry {
[string] $containerOrImageName
)
Process {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.country)"
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.country)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerCountry -Value Get-BcContainerCountry
Export-ModuleMember -Function Get-BcContainerCountry -Alias Get-NavContainerCountry

Просмотреть файл

@ -45,66 +45,75 @@ function Get-BcContainerDebugInfo {
[switch] $CopyToClipboard
)
Process {
$debugInfo = @{}
$inspect = docker inspect $containerName | ConvertFrom-Json
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerName is not a NAV/BC container"
}
$debugInfo.Add('container.labels', $inspect.Config.Labels)
if (!$ExcludeEnvVars) {
$envs = $inspect.Config.Env.GetEnumerator() | ForEach-Object {
if ($includeSensitiveInformation) {
$_
} elseif ($_.ToLowerInvariant().Contains("password=") -or
$_.ToLowerInvariant().Startswith("navdvdurl=") -or
$_.ToLowerInvariant().Startswith("countryurl=") -or
$_.ToLowerInvariant().Startswith("licensefile=") -or
$_.ToLowerInvariant().Startswith("bakfile=") -or
$_.ToLowerInvariant().Startswith("folders=") -or
$_.ToLowerInvariant().Startswith("vsixurl=")) {
($_.Split("=")[0] + "=<specified>")
} else {
$_
}
}
if ($envs) {
$debugInfo.Add('container.env', $envs)
}
}
$debugInfo = @{}
$inspect = docker inspect $containerName | ConvertFrom-Json
if (!$ExcludeDockerInfo) {
$dockerInfo = docker info
if ($dockerInfo) {
$debugInfo.Add('docker.info', $dockerInfo)
}
}
if (!$ExcludeDockerLogs) {
$logs = docker logs $containerName
if ($logs) {
$debugInfo.Add('container.logs', $logs)
}
}
if (!$ExcludePing) {
$ping = ping $containerName
if ($ping) {
$debugInfo.Add('container.ping', $ping)
}
}
$debugInfoJson = ConvertTo-Json $debugInfo
if ($CopyToClipboard) {
$debugInfoJson | Set-Clipboard
}
return $debugInfoJson
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerName is not a NAV/BC container"
}
$debugInfo.Add('container.labels', $inspect.Config.Labels)
if (!$ExcludeEnvVars) {
$envs = $inspect.Config.Env.GetEnumerator() | ForEach-Object {
if ($includeSensitiveInformation) {
$_
} elseif ($_.ToLowerInvariant().Contains("password=") -or
$_.ToLowerInvariant().Startswith("navdvdurl=") -or
$_.ToLowerInvariant().Startswith("countryurl=") -or
$_.ToLowerInvariant().Startswith("licensefile=") -or
$_.ToLowerInvariant().Startswith("bakfile=") -or
$_.ToLowerInvariant().Startswith("folders=") -or
$_.ToLowerInvariant().Startswith("vsixurl=")) {
($_.Split("=")[0] + "=<specified>")
} else {
$_
}
}
if ($envs) {
$debugInfo.Add('container.env', $envs)
}
}
if (!$ExcludeDockerInfo) {
$dockerInfo = docker info
if ($dockerInfo) {
$debugInfo.Add('docker.info', $dockerInfo)
}
}
if (!$ExcludeDockerLogs) {
$logs = docker logs $containerName
if ($logs) {
$debugInfo.Add('container.logs', $logs)
}
}
if (!$ExcludePing) {
$ping = ping $containerName
if ($ping) {
$debugInfo.Add('container.ping', $ping)
}
}
$debugInfoJson = ConvertTo-Json $debugInfo
if ($CopyToClipboard) {
$debugInfoJson | Set-Clipboard
}
return $debugInfoJson
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerDebugInfo -Value Get-BcContainerDebugInfo
Export-ModuleMember -Function Get-BcContainerDebugInfo -Alias Get-NavContainerDebugInfo

Просмотреть файл

@ -18,13 +18,21 @@ function Get-BcContainerEula {
[string] $containerOrImageName
)
Process {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.Eula)"
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.Eula)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerEula -Value Get-BcContainerEula
Export-ModuleMember -Function Get-BcContainerEula -Alias Get-NavContainerEula

Просмотреть файл

@ -23,21 +23,30 @@ function Get-BcContainerEventLog {
[switch] $doNotOpen
)
Process {
Write-Host "Getting event log for $containername"
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$containerFolder = Join-Path $ExtensionsFolder $containerName
$myFolder = Join-Path $containerFolder "my"
$folder = Get-BcContainerPath -containerName $containerName -Path $myFolder
$name = $containerName + ' ' + [DateTime]::Now.ToString("yyyy-MM-dd HH.mm.ss") + ".evtx"
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param([string]$path, [string]$logname)
wevtutil epl $logname "$path"
} -ArgumentList (Join-Path $folder $name), $logname
Write-Host "Getting event log for $containername"
if (!$doNotOpen) {
[Diagnostics.Process]::Start((Join-Path -Path $myFolder $name)) | Out-Null
}
$containerFolder = Join-Path $ExtensionsFolder $containerName
$myFolder = Join-Path $containerFolder "my"
$folder = Get-BcContainerPath -containerName $containerName -Path $myFolder
$name = $containerName + ' ' + [DateTime]::Now.ToString("yyyy-MM-dd HH.mm.ss") + ".evtx"
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param([string]$path, [string]$logname)
wevtutil epl $logname "$path"
} -ArgumentList (Join-Path $folder $name), $logname
if (!$doNotOpen) {
[Diagnostics.Process]::Start((Join-Path -Path $myFolder $name)) | Out-Null
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerEventLog -Value Get-BcContainerEventLog
Export-ModuleMember -Function Get-BcContainerEventLog -Alias Get-NavContainerEventLog

Просмотреть файл

@ -17,13 +17,22 @@ function Get-BcContainerGenericTag {
[string] $containerOrImageName
)
Process {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('tag').Count -eq 0) {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.tag)"
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('tag').Count -eq 0) {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.tag)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerGenericTag -Value Get-BcContainerGenericTag
Export-ModuleMember -Function Get-BcContainerGenericTag -Alias Get-NavContainerGenericTag

Просмотреть файл

@ -15,25 +15,34 @@ function Get-BcContainerId {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)
Process {
$id = ""
docker ps --format "{{.ID}}:{{.Names}}" -a --no-trunc | ForEach-Object {
$ps = $_.split(':')
if ($containerName -eq $ps[1]) {
$id = $ps[0]
}
if ($ps[0].StartsWith($containerName)) {
if ($id) {
throw "Unambiguous container ID specified"
}
$id = $ps[0]
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$id = ""
docker ps --format "{{.ID}}:{{.Names}}" -a --no-trunc | ForEach-Object {
$ps = $_.split(':')
if ($containerName -eq $ps[1]) {
$id = $ps[0]
}
if (!($id)) {
throw "Container $containerName does not exist"
if ($ps[0].StartsWith($containerName)) {
if ($id) {
throw "Unambiguous container ID specified"
}
$id = $ps[0]
}
$id
}
if (!($id)) {
throw "Container $containerName does not exist"
}
$id
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerId -Value Get-BcContainerId
Export-ModuleMember -Function Get-BcContainerId -Alias Get-NavContainerId

Просмотреть файл

@ -17,6 +17,9 @@ function Get-BcContainerImageLabels {
[PSCredential] $registryCredential
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$webclient = New-Object System.Net.WebClient
@ -71,5 +74,13 @@ function Get-BcContainerImageLabels {
catch {
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerImageLabels -Value Get-BcContainerImageLabels
Export-ModuleMember -Function Get-BcContainerImageLabels -Alias Get-NavContainerImageLabels

Просмотреть файл

@ -16,10 +16,18 @@ function Get-BcContainerImageName {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)
Process {
$inspect = docker inspect $containerName | ConvertFrom-Json
return "$($inspect.Config.Image)"
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerName | ConvertFrom-Json
return "$($inspect.Config.Image)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerImageName -Value Get-BcContainerImageName
Export-ModuleMember -Function Get-BcContainerImageName -Alias Get-NavContainerImageName

Просмотреть файл

@ -19,6 +19,9 @@ function Get-BcContainerImageTags {
[int] $pageSize = -1
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$webclient = New-Object System.Net.WebClient
@ -74,5 +77,13 @@ function Get-BcContainerImageTags {
catch {
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerImageTags -Value Get-BcContainerImageTags
Export-ModuleMember -Function Get-BcContainerImageTags -Alias Get-NavContainerImageTags

Просмотреть файл

@ -18,34 +18,42 @@ function Get-BcContainerIpAddress {
[string] $networkName = ""
)
Process {
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$ip = Invoke-ScriptInBcContainer -containerName $containerName -scriptblock {
$ip = ""
$ips = Get-NetIPAddress | Where-Object { $_.AddressFamily -eq "IPv4" -and $_.IPAddress -ne "127.0.0.1" }
if ($ips) {
$ips | ForEach-Object {
if ("$ip" -eq "") {
$ip = $_.IPAddress
}
}
}
$ip
}
if ("$ip" -eq "") {
$inspect = docker inspect $containerName | ConvertFrom-Json
$networks = $inspect.NetworkSettings.Networks
$networks | get-member -MemberType NoteProperty | Select-Object Name | % {
$name = $_.Name
if (("$ip" -eq "") -and ("$networkName" -eq "" -or "$networkName" -eq "$name")) {
$network = $networks | Select-Object -ExpandProperty $name
$ip = $network.IPAddress
$ip = Invoke-ScriptInBcContainer -containerName $containerName -scriptblock {
$ip = ""
$ips = Get-NetIPAddress | Where-Object { $_.AddressFamily -eq "IPv4" -and $_.IPAddress -ne "127.0.0.1" }
if ($ips) {
$ips | ForEach-Object {
if ("$ip" -eq "") {
$ip = $_.IPAddress
}
}
}
return $ip
$ip
}
if ("$ip" -eq "") {
$inspect = docker inspect $containerName | ConvertFrom-Json
$networks = $inspect.NetworkSettings.Networks
$networks | get-member -MemberType NoteProperty | Select-Object Name | % {
$name = $_.Name
if (("$ip" -eq "") -and ("$networkName" -eq "" -or "$networkName" -eq "$name")) {
$network = $networks | Select-Object -ExpandProperty $name
$ip = $network.IPAddress
}
}
}
return $ip
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerIpAddress -Value Get-BcContainerIpAddress
Export-ModuleMember -Function Get-BcContainerIpAddress -Alias Get-NavContainerIpAddress

Просмотреть файл

@ -18,13 +18,22 @@ function Get-BcContainerLegal {
[string] $containerOrImageName
)
Process {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.legal)"
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.legal)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerLegal -Value Get-BcContainerLegal
Export-ModuleMember -Function Get-BcContainerLegal -Alias Get-NavContainerLegal

Просмотреть файл

@ -15,7 +15,18 @@ function Get-BcContainerName {
[string] $containerId
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
docker ps --format='{{.Names}}' -a --filter "id=$containerId"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerName -Value Get-BcContainerName
Export-ModuleMember -Function Get-BcContainerName -Alias Get-NavContainerName

Просмотреть файл

@ -17,13 +17,21 @@ function Get-BcContainerNavVersion {
[string] $containerOrImageName
)
Process {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.version)-$($inspect.Config.Labels.country)"
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.version)-$($inspect.Config.Labels.country)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerNavVersion -Value Get-BcContainerNavVersion
Export-ModuleMember -Function Get-BcContainerNavVersion -Alias Get-NavContainerNavVersion

Просмотреть файл

@ -17,10 +17,18 @@ function Get-BcContainerOsVersion {
[string] $containerOrImageName
)
Process {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
return "$($inspect.Config.Labels.osversion)"
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
return "$($inspect.Config.Labels.osversion)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerOsVersion -Value Get-BcContainerOsVersion
Export-ModuleMember -Function Get-BcContainerOsVersion -Alias Get-NavContainerOsVersion

Просмотреть файл

@ -21,34 +21,42 @@ function Get-BcContainerPath {
[switch] $throw
)
Process {
$containerPath = ""
if ($path.StartsWith(":")) {
$path =$path.Substring(1)
$exist = Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($path)
Test-Path $path
} -ArgumentList $path
if ($exist) {
$containerPath = $path
}
if ($throw -and "$containerPath" -eq "") {
throw "The path $path does not exist in the container $containerName"
}
} else {
$sharedFolders = Get-BcContainerSharedFolders -containerName $containerName
$sharedFolders.GetEnumerator() | ForEach-Object {
$Name = $_.Name.TrimEnd('\')
$Value = $_.Value.TrimEnd('\')
if ($path -eq $Name -or ($containerPath -eq "" -and $path.StartsWith($Name+"\", "OrdinalIgnoreCase"))) {
$containerPath = ($Value + $path.Substring($Name.Length))
}
}
if ($throw -and "$containerPath" -eq "") {
throw "The path $path is not shared with the container $containerName (nor is any of it's parent folders)"
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$containerPath = ""
if ($path.StartsWith(":")) {
$path =$path.Substring(1)
$exist = Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($path)
Test-Path $path
} -ArgumentList $path
if ($exist) {
$containerPath = $path
}
if ($throw -and "$containerPath" -eq "") {
throw "The path $path does not exist in the container $containerName"
}
} else {
$sharedFolders = Get-BcContainerSharedFolders -containerName $containerName
$sharedFolders.GetEnumerator() | ForEach-Object {
$Name = $_.Name.TrimEnd('\')
$Value = $_.Value.TrimEnd('\')
if ($path -eq $Name -or ($containerPath -eq "" -and $path.StartsWith($Name+"\", "OrdinalIgnoreCase"))) {
$containerPath = ($Value + $path.Substring($Name.Length))
}
}
return $containerPath
if ($throw -and "$containerPath" -eq "") {
throw "The path $path is not shared with the container $containerName (nor is any of it's parent folders)"
}
}
return $containerPath
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerPath -Value Get-BcContainerPath
Export-ModuleMember -Function Get-BcContainerPath -Alias Get-NavContainerPath

Просмотреть файл

@ -18,17 +18,25 @@ function Get-BcContainerPlatformVersion {
[string] $containerOrImageName
)
Process {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
if ($inspect.Config.Labels.psobject.Properties.Name -eq 'platform') {
return "$($inspect.Config.Labels.platform)"
} else {
return ""
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
if ($inspect.Config.Labels.psobject.Properties.Name -eq 'platform') {
return "$($inspect.Config.Labels.platform)"
} else {
return ""
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerPlatformVersion -Value Get-BcContainerPlatformVersion
Export-ModuleMember -Function Get-BcContainerPlatformVersion -Alias Get-NavContainerPlatformVersion

Просмотреть файл

@ -13,6 +13,8 @@ Function Get-BcContainerServerConfiguration {
[String] $ContainerName = $bcContainerHelperConfig.defaultContainerName
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$ResultObjectArray = @()
$config = Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock{
Get-NavServerInstance | Get-NAVServerConfiguration -AsXml
@ -35,5 +37,13 @@ Function Get-BcContainerServerConfiguration {
Write-Output $ResultObjectArray
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerServerConfiguration -Value Get-BcContainerServerConfiguration
Export-ModuleMember -Function Get-BcContainerServerConfiguration -Alias Get-NavContainerServerConfiguration

Просмотреть файл

@ -19,33 +19,42 @@ function Get-BcContainerSharedFolders {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)
Process {
$inspect = docker inspect $containerName | ConvertFrom-Json
$sharedFolders = @{}
if ($inspect.HostConfig.Binds) {
$inspect.HostConfig.Binds | ForEach-Object {
$idx = $_.IndexOf(':', $_.IndexOf(':') + 1)
$src = $_.Substring(0, $idx).TrimEnd('\')
$dst = $_.SubString($idx+1)
$idx = $dst.IndexOf(':', $_.IndexOf(':') + 1)
if ($idx -gt 0) {
$dst = $dst.SubString(0,$idx)
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerName | ConvertFrom-Json
$sharedFolders = @{}
if ($inspect.HostConfig.Binds) {
$inspect.HostConfig.Binds | ForEach-Object {
$idx = $_.IndexOf(':', $_.IndexOf(':') + 1)
$src = $_.Substring(0, $idx).TrimEnd('\')
$dst = $_.SubString($idx+1)
$idx = $dst.IndexOf(':', $_.IndexOf(':') + 1)
if ($idx -gt 0) {
$dst = $dst.SubString(0,$idx)
}
$sharedFolders += @{ $src = $dst }
}
}
if ($inspect.Mounts) {
$inspect.Mounts | ForEach-Object {
$src = $_.Source
$dst = $_.Destination
if (-not ($sharedFolders[$src])) {
$sharedFolders += @{ $src = $dst }
}
}
if ($inspect.Mounts) {
$inspect.Mounts | ForEach-Object {
$src = $_.Source
$dst = $_.Destination
if (-not ($sharedFolders[$src])) {
$sharedFolders += @{ $src = $dst }
}
}
}
return $sharedFolders
}
return $sharedFolders
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerSharedFolders -Value Get-BcContainerSharedFolders
Export-ModuleMember -Function Get-BcContainerSharedFolders -Alias Get-NavContainerSharedFolders

Просмотреть файл

@ -11,24 +11,32 @@ function Get-BcContainers {
[switch] $includeLabels
)
Process {
if ($includeLabels) {
$containers = @()
docker ps --filter "label=nav" -a --no-trunc --format 'name={{.Names}},id={{.ID}},image={{.Image}},createdat={{.CreatedAt}},runningfor={{.RunningFor}},size={{.Size}},status={{.Status}},{{.Labels}}' | % {
$labels = [PSCustomObject]@{}
$_.Split(',') | % {
$name = $_.Split('=')[0]
$value = $_.SubString($name.length+1)
$labels | Add-Member -NotePropertyName $name -NotePropertyValue $value
}
$containers += $labels
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if ($includeLabels) {
$containers = @()
docker ps --filter "label=nav" -a --no-trunc --format 'name={{.Names}},id={{.ID}},image={{.Image}},createdat={{.CreatedAt}},runningfor={{.RunningFor}},size={{.Size}},status={{.Status}},{{.Labels}}' | % {
$labels = [PSCustomObject]@{}
$_.Split(',') | % {
$name = $_.Split('=')[0]
$value = $_.SubString($name.length+1)
$labels | Add-Member -NotePropertyName $name -NotePropertyValue $value
}
$containers += $labels
}
else {
$containers = docker ps --filter "label=nav" -a --format '{{.Names}}'
}
$containers
}
else {
$containers = docker ps --filter "label=nav" -a --format '{{.Names}}'
}
$containers
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainers -Value Get-BcContainers
Export-ModuleMember -Function Get-BcContainers -Alias Get-NavContainers

Просмотреть файл

@ -15,29 +15,39 @@ function Test-BcContainer {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName,
[switch] $doNotIncludeStoppedContainers
)
Process {
if ($containerName) {
$id = ""
$a = "-a"
if ($doNotIncludeStoppedContainers) {
$a = ""
}
$id = docker ps $a -q --no-trunc --format "{{.ID}}/{{.Names}}" | Where-Object { $containerName -eq $_.split('/')[1] } | % { $_.split('/')[0] }
if (!($id)) {
$id = docker ps $a -q --no-trunc --filter "id=$containerName"
}
if ($id) {
$inspect = docker inspect $id | ConvertFrom-Json
($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -ne 0 -and $inspect.Config.Labels.maintainer -eq "Dynamics SMB")
} else {
$false
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if ($containerName) {
$id = ""
$a = "-a"
if ($doNotIncludeStoppedContainers) {
$a = ""
}
else {
$id = docker ps $a -q --no-trunc --format "{{.ID}}/{{.Names}}" | Where-Object { $containerName -eq $_.split('/')[1] } | % { $_.split('/')[0] }
if (!($id)) {
$id = docker ps $a -q --no-trunc --filter "id=$containerName"
}
if ($id) {
$inspect = docker inspect $id | ConvertFrom-Json
($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -ne 0 -and $inspect.Config.Labels.maintainer -eq "Dynamics SMB")
} else {
$false
}
}
else {
$false
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Test-NavContainer -Value Test-BcContainer
Export-ModuleMember -Function Test-BcContainer -Alias Test-NavContainer

Просмотреть файл

@ -21,38 +21,38 @@ function Copy-FileFromBcContainer {
[string] $localPath = $containerPath
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if (!(Test-BcContainer -containerName $containerName)) {
throw "Container $containerName does not exist"
}
Write-Host "Copy from container $containerName ($containerPath) to $localPath"
$id = Get-BcContainerId -containerName $containerName
# running hyperv containers doesn't support docker cp
$tempFile = Join-Path $hostHelperFolder ([GUID]::NewGuid().ToString())
try {
if (!(Test-BcContainer -containerName $containerName)) {
throw "Container $containerName does not exist"
if (Test-Path $localPath -PathType Container) {
throw "localPath ($localPath) already exists as a folder. Cannot copy file, LocalPath needs to specify a filename."
}
Write-Host "Copy from container $containerName ($containerPath) to $localPath"
$id = Get-BcContainerId -containerName $containerName
# running hyperv containers doesn't support docker cp
$tempFile = Join-Path $hostHelperFolder ([GUID]::NewGuid().ToString())
try {
if (Test-Path $localPath -PathType Container) {
throw "localPath ($localPath) already exists as a folder. Cannot copy file, LocalPath needs to specify a filename."
}
Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($containerPath, $tempFile)
Copy-Item -Path $containerPath -Destination $tempFile
} -argumentList $containerPath, (Get-BcContainerPath -containerName $containerName -Path $tempFile)
Move-Item -Path $tempFile -Destination $localPath -Force
} finally {
if (Test-Path $tempFile) {
Remove-Item $tempFile -ErrorAction Ignore
}
Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($containerPath, $tempFile)
Copy-Item -Path $containerPath -Destination $tempFile
} -argumentList $containerPath, (Get-BcContainerPath -containerName $containerName -Path $tempFile)
Move-Item -Path $tempFile -Destination $localPath -Force
} finally {
if (Test-Path $tempFile) {
Remove-Item $tempFile -ErrorAction Ignore
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Copy-FileFromNavContainer -Value Copy-FileFromBcContainer
Export-ModuleMember -Function Copy-FileFromBcContainer -Alias Copy-FileFromNavContainer

Просмотреть файл

@ -21,42 +21,42 @@ function Copy-FileToBcContainer {
[string] $containerPath = $localPath
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if (!(Test-BcContainer -containerName $containerName)) {
throw "Container $containerName does not exist"
}
Write-Host "Copy $localPath to container ${containerName} ($containerPath)"
$id = Get-BcContainerId -containerName $containerName
# running hyperv containers doesn't support docker cp
$tempFile = Join-Path $hostHelperFolder ([GUID]::NewGuid().ToString())
try {
if (!(Test-BcContainer -containerName $containerName)) {
throw "Container $containerName does not exist"
}
Write-Host "Copy $localPath to container ${containerName} ($containerPath)"
$id = Get-BcContainerId -containerName $containerName
# running hyperv containers doesn't support docker cp
$tempFile = Join-Path $hostHelperFolder ([GUID]::NewGuid().ToString())
try {
Copy-Item -Path $localPath -Destination $tempFile
Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($tempFile, $containerPath)
if (Test-Path $containerPath -PathType Container) {
throw "ContainerPath ($containerPath) already exists as a folder. Cannot copy file, ContainerPath needs to specify a filename."
}
$directory = [System.IO.Path]::GetDirectoryName($containerPath)
if (-not (Test-Path $directory -PathType Container)) {
New-Item -Path $directory -ItemType Directory | Out-Null
}
Move-Item -Path $tempFile -Destination $containerPath -Force
} -argumentList (Get-BcContainerPath -containerName $containerName -Path $tempFile), $containerPath
} finally {
if (Test-Path $tempFile) {
Remove-Item $tempFile -ErrorAction Ignore
Copy-Item -Path $localPath -Destination $tempFile
Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($tempFile, $containerPath)
if (Test-Path $containerPath -PathType Container) {
throw "ContainerPath ($containerPath) already exists as a folder. Cannot copy file, ContainerPath needs to specify a filename."
}
$directory = [System.IO.Path]::GetDirectoryName($containerPath)
if (-not (Test-Path $directory -PathType Container)) {
New-Item -Path $directory -ItemType Directory | Out-Null
}
Move-Item -Path $tempFile -Destination $containerPath -Force
} -argumentList (Get-BcContainerPath -containerName $containerName -Path $tempFile), $containerPath
} finally {
if (Test-Path $tempFile) {
Remove-Item $tempFile -ErrorAction Ignore
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Copy-FileToNavContainer -Value Copy-FileToBcContainer
Export-ModuleMember -Function Copy-FileToBcContainer -Alias Copy-FileToNavContainer

Просмотреть файл

@ -33,7 +33,7 @@ function Download-Artifacts {
[int] $timeout = 300
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @("artifactUrl")
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @("artifactUrl","includePlatform")
try {
if ($basePath -eq "") {

Просмотреть файл

@ -13,6 +13,9 @@ function Get-AzureFeedWildcardVersion {
[string] $appVersion
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$version = $appVersion.split('.')
$major = $version[0]
@ -32,5 +35,13 @@ function Get-AzureFeedWildcardVersion {
}
return ($major + '.' + $minor + '.' + $patch)
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Get-AzureFeedWildcardVersion

Просмотреть файл

@ -8,6 +8,9 @@ function Install-AzDevops {
Param(
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Try {
az upgrade
} catch {
@ -26,5 +29,13 @@ function Install-AzDevops {
if ($devopsFound -eq $False){
az extension add -n azure-devops
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Install-AzDevops

Просмотреть файл

@ -28,6 +28,10 @@ function Publish-BuildOutputToAzureFeed {
[Parameter(Mandatory = $true)]
[string] $pat
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Get-Childitem Path (Join-Path $path "\Apps\*.app") | % {
$basename = $_.Basename
@ -75,5 +79,13 @@ function Publish-BuildOutputToAzureFeed {
Remove-Item -Path $tempAppFolder -Recurse -Force -ErrorAction SilentlyContinue
}
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Publish-BuildOutputToAzureFeed

Просмотреть файл

@ -36,6 +36,9 @@ function Publish-BuildOutputToStorage {
[switch] $setLatest
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if ($StorageConnectionString -is [SecureString]) { $StorageConnectionString = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($StorageConnectionString)) }
if ($StorageConnectionString -isnot [string]) { throw "StorageConnectionString needs to be a SecureString or a String" }
$projectName = $projectName.ToLowerInvariant()
@ -64,5 +67,13 @@ function Publish-BuildOutputToStorage {
}
}
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Publish-BuildOutputToStorage

Просмотреть файл

@ -31,6 +31,10 @@ function Resolve-DependenciesFromAzureFeed {
[string] $outputFolder = (Join-Path $appsFolder '.alpackages'),
[int] $lvl = -1
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$spaces = ''
$lvl++
@ -138,5 +142,13 @@ function Resolve-DependenciesFromAzureFeed {
}
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Resolve-DependenciesFromAzureFeed

Просмотреть файл

@ -53,8 +53,13 @@ function AddTelemetryProperty {
)
if ($telemetryScope) {
Write-Host "Telemetry scope $($telemetryScope.Name), add property $key = $((FormatValue -value $value))"
$telemetryScope.properties.Add($key, (FormatValue -value $value))
# Write-Host "Telemetry scope $($telemetryScope.Name), add property $key = $((FormatValue -value $value))"
if ($telemetryScope.properties.ContainsKey($Key)) {
$telemetryScope.properties."$key" += "`n$(FormatValue -value $value)"
}
else {
$telemetryScope.properties.Add($key, (FormatValue -value $value))
}
}
}
@ -64,13 +69,19 @@ function InitTelemetryScope {
[string[]] $includeParameters = @(),
$parameterValues = $null
)
if ($telemetryClient) {
if ($bcContainerHelperConfig.TelemetryConnectionString) {
if ($telemetryClient.TelemetryConfiguration.ConnectionString -ne $bcContainerHelperConfig.TelemetryConnectionString) {
$telemetryClient.TelemetryConfiguration.ConnectionString = $bcContainerHelperConfig.TelemetryConnectionString
$telemetryClient.TelemetryConfiguration.DisableTelemetry = $false
Write-Host "Telemetry client initialized"
if ($telemetryClient.TelemetryConfiguration.DisableTelemetry -or $telemetryClient.TelemetryConfiguration.ConnectionString -ne $bcContainerHelperConfig.TelemetryConnectionString) {
if ($bcContainerHelperConfig.TelemetryConnectionString) {
try {
$telemetryClient.TelemetryConfiguration.ConnectionString = $bcContainerHelperConfig.TelemetryConnectionString
$telemetryClient.TelemetryConfiguration.DisableTelemetry = $false
Write-Host "Telemetry client initialized"
}
catch {
$telemetryClient.TelemetryConfiguration.DisableTelemetry = $true
}
}
}
if ($telemetryClient.IsEnabled()) {
Write-Host "Init telemetry scope $name"

Просмотреть файл

@ -47,89 +47,89 @@ function New-BcContainerBcUser {
[PSCredential] $databaseCredential
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { param([PSCredential]$Credential, [string]$Tenant, [string]$WindowsAccount, [string]$AuthenticationEMail, [bool]$ChangePasswordAtNextLogOn, [string]$PermissionSetId, $assignPremiumPlan, [PSCredential]$databaseCredential)
$TenantParam = @{}
if ($Tenant) {
$TenantParam.Add('Tenant', $Tenant)
}
$Parameters = @{}
if ($AuthenticationEMail) {
$Parameters.Add('AuthenticationEmail',$AuthenticationEmail)
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { param([PSCredential]$Credential, [string]$Tenant, [string]$WindowsAccount, [string]$AuthenticationEMail, [bool]$ChangePasswordAtNextLogOn, [string]$PermissionSetId, $assignPremiumPlan, [PSCredential]$databaseCredential)
$TenantParam = @{}
if ($Tenant) {
$TenantParam.Add('Tenant', $Tenant)
}
$Parameters = @{}
if ($AuthenticationEMail) {
$Parameters.Add('AuthenticationEmail',$AuthenticationEmail)
}
if ($assignPremiumPlan) {
if ($assignPremiumPlan) {
$customConfigFile = Join-Path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service").FullName "CustomSettings.config"
[xml]$customConfig = [System.IO.File]::ReadAllText($customConfigFile)
$multitenant = ($customConfig.SelectSingleNode("//appSettings/add[@key='Multitenant']").Value -eq "true")
$databaseName = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseName']").Value
$databaseServer = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseServer']").Value
$databaseInstance = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseInstance']").Value
$databaseServerInstance = $databaseServer
if ($databaseInstance) {
$databaseServerInstance += "\$databaseInstance"
$customConfigFile = Join-Path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service").FullName "CustomSettings.config"
[xml]$customConfig = [System.IO.File]::ReadAllText($customConfigFile)
$multitenant = ($customConfig.SelectSingleNode("//appSettings/add[@key='Multitenant']").Value -eq "true")
$databaseName = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseName']").Value
$databaseServer = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseServer']").Value
$databaseInstance = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseInstance']").Value
$databaseServerInstance = $databaseServer
if ($databaseInstance) {
$databaseServerInstance += "\$databaseInstance"
}
$sqlparams = @{
"ErrorAction" = "Ignore"
}
if ($databaseServerInstance -ne "localhost\SQLEXPRESS") {
if (!($databaseCredential)) {
throw "When using a foreign SQL Server, you need to specify databaseCredential in order to assign Premium Plan"
}
$sqlparams = @{
"ErrorAction" = "Ignore"
}
if ($databaseServerInstance -ne "localhost\SQLEXPRESS") {
if (!($databaseCredential)) {
throw "When using a foreign SQL Server, you need to specify databaseCredential in order to assign Premium Plan"
}
$sqlparams += @{
"ServerInstance" = $databaseServerInstance
"Username" = $databaseCredential.Username
"Password" = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($databaseCredential.Password))
}
$sqlparams += @{
"ServerInstance" = $databaseServerInstance
"Username" = $databaseCredential.Username
"Password" = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($databaseCredential.Password))
}
}
}
if($WindowsAccount) {
Write-Host "Creating User for WindowsAccount $WindowsAccount"
New-NAVServerUser -ServerInstance $ServerInstance @TenantParam -WindowsAccount $WindowsAccount @Parameters
Write-Host "Assigning Permission Set $PermissionSetId to $WindowsAccount"
New-NavServerUserPermissionSet -ServerInstance $ServerInstance @tenantParam -WindowsAccount $WindowsAccount -PermissionSetId $PermissionSetId
$user = Get-NAVServerUser -ServerInstance $ServerInstance @tenantParam | Where-Object { $_.UserName.EndsWith("\$WindowsAccount", [System.StringComparison]::InvariantCultureIgnoreCase) -or $_.UserName -eq $WindowsAccount }
if($WindowsAccount) {
Write-Host "Creating User for WindowsAccount $WindowsAccount"
New-NAVServerUser -ServerInstance $ServerInstance @TenantParam -WindowsAccount $WindowsAccount @Parameters
Write-Host "Assigning Permission Set $PermissionSetId to $WindowsAccount"
New-NavServerUserPermissionSet -ServerInstance $ServerInstance @tenantParam -WindowsAccount $WindowsAccount -PermissionSetId $PermissionSetId
$user = Get-NAVServerUser -ServerInstance $ServerInstance @tenantParam | Where-Object { $_.UserName.EndsWith("\$WindowsAccount", [System.StringComparison]::InvariantCultureIgnoreCase) -or $_.UserName -eq $WindowsAccount }
} else {
Write-Host "Creating User $($Credential.UserName)"
if ($ChangePasswordAtNextLogOn) {
New-NAVServerUser -ServerInstance $ServerInstance @TenantParam -Username $Credential.UserName -Password $Credential.Password -ChangePasswordAtNextLogon @Parameters
} else {
Write-Host "Creating User $($Credential.UserName)"
if ($ChangePasswordAtNextLogOn) {
New-NAVServerUser -ServerInstance $ServerInstance @TenantParam -Username $Credential.UserName -Password $Credential.Password -ChangePasswordAtNextLogon @Parameters
} else {
New-NAVServerUser -ServerInstance $ServerInstance @TenantParam -Username $Credential.UserName -Password $Credential.Password @Parameters
}
Write-Host "Assigning Permission Set $PermissionSetId to $($Credential.Username)"
New-NavServerUserPermissionSet -ServerInstance $ServerInstance @tenantParam -username $Credential.username -PermissionSetId $PermissionSetId
$user = Get-NAVServerUser -ServerInstance $ServerInstance @tenantParam | Where-Object { $_.UserName -eq $Credential.UserName }
New-NAVServerUser -ServerInstance $ServerInstance @TenantParam -Username $Credential.UserName -Password $Credential.Password @Parameters
}
Write-Host "Assigning Permission Set $PermissionSetId to $($Credential.Username)"
New-NavServerUserPermissionSet -ServerInstance $ServerInstance @tenantParam -username $Credential.username -PermissionSetId $PermissionSetId
$user = Get-NAVServerUser -ServerInstance $ServerInstance @tenantParam | Where-Object { $_.UserName -eq $Credential.UserName }
}
if ($assignPremiumPlan -and ($user)) {
$UserId = $user.UserSecurityId
Write-Host "Assigning Premium plan for $($user.Username)"
$dbName = $DatabaseName
if ($multitenant) {
$dbName = (Get-NavTenant -ServerInstance $ServerInstance -tenant $tenant).DatabaseName
}
if ($assignPremiumPlan -and ($user)) {
$UserId = $user.UserSecurityId
Write-Host "Assigning Premium plan for $($user.Username)"
$dbName = $DatabaseName
if ($multitenant) {
$dbName = (Get-NavTenant -ServerInstance $ServerInstance -tenant $tenant).DatabaseName
}
'User Plan$63ca2fa4-4f03-4f2b-a480-172fef340d3f','User Plan' | % {
Invoke-Sqlcmd @sqlParams -Query "USE [$DbName]
'User Plan$63ca2fa4-4f03-4f2b-a480-172fef340d3f','User Plan' | % {
Invoke-Sqlcmd @sqlParams -Query "USE [$DbName]
INSERT INTO [dbo].[$_] ([Plan ID],[User Security ID]) VALUES ('{8e9002c0-a1d8-4465-b952-817d2948e6e2}','$userId')"
}
}
} -argumentList $Credential, $Tenant, $WindowsAccount, $AuthenticationEMail, $ChangePasswordAtNextLogOn, $PermissionSetId, $assignPremiumPlan, $databaseCredential
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
}
} -argumentList $Credential, $Tenant, $WindowsAccount, $AuthenticationEMail, $ChangePasswordAtNextLogOn, $PermissionSetId, $assignPremiumPlan, $databaseCredential
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name New-NavContainerNavUser -Value New-BcContainerBcUser
Export-ModuleMember -Function New-BcContainerBcUser -Alias New-NavContainerNavUser

Просмотреть файл

@ -22,25 +22,25 @@ function New-BcContainerWindowsUser {
[string] $group = "administrators"
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { param([System.Management.Automation.PSCredential]$Credential, [string]$group)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { param([System.Management.Automation.PSCredential]$Credential, [string]$group)
Write-Host "Creating Windows user $($Credential.username)"
New-LocalUser -AccountNeverExpires -FullName $Credential.username -Name $Credential.username -Password $Credential.Password | Out-Null
Write-Host "Adding Windows user $($Credential.username) to $group"
Add-LocalGroupMember -Group $group -Member $Credential.username -ErrorAction Ignore
} `
-ArgumentList $Credential, $group
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
Write-Host "Creating Windows user $($Credential.username)"
New-LocalUser -AccountNeverExpires -FullName $Credential.username -Name $Credential.username -Password $Credential.Password | Out-Null
Write-Host "Adding Windows user $($Credential.username) to $group"
Add-LocalGroupMember -Group $group -Member $Credential.username -ErrorAction Ignore
} `
-ArgumentList $Credential, $group
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name New-NavContainerWindowsUser -Value New-BcContainerWindowsUser
Export-ModuleMember -Function New-BcContainerWindowsUser -Alias New-NavContainerWindowsUser