Module/BusinessCentral/Sign-BCSAppFile.ps1

<#
.SYNOPSIS
    Sign a app file using Code Signing secrets in azure
.DESCRIPTION
    Sign a app file using Code Signing secrets in azure
 
.PARAMETER containerName
  A docker container
.PARAMETER sourceAppFile
  Path to app file that will be signed
.PARAMETER tenantId
  Azure Key Vault tenant ID
.PARAMETER subscriptionId
  Azure Key Vault Subscription ID
.PARAMETER vaultName
  Name of the Vault where the CodeSign information is stored
.PARAMETER resourceGroupName
  Azure Key Vault Resource Group Name
 
.NOTES
  Author: Mathias Stjernfelt
  Website: http://www.brightcom.se
 
.EXAMPLE
    Sign-BCSAppFile -containerName myContainerName -sourceAppFile myAppFilePath -tenantId myAzureTenantID -subscriptionId myAzureSubscriptionID -vaultName myKeyVaultName -resourceGroupName myResourceGroupName
#>


function Sign-BCSAppFile {
  Param (
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
    [string]$containerName,
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
    [string]$sourceAppFile,
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
    [string]$tenantId,
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
    [string]$subscriptionId,
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
    [string]$vaultName,
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
    [string]$resourceGroupName

  )
  begin {}

  process {
    Connect-AzAccount -Subscription $subscriptionId -Tenant $tenantId

    $keyVault = Get-AzKeyVault -VaultName $vaultName -ResourceGroupName $resourceGroupName

    $codeSignPfxFile = Get-AzKeyVaultSecret -VaultName $keyVault.VaultName -Name "CodeSignPfxFile" -AsPlainText
    $codeSignPfxPassword = Get-AzKeyVaultSecret -VaultName $keyVault.VaultName -Name "CodeSignPfxPassword"

    $fileName = Split-Path $sourceAppFile -Leaf
    $signAppFile = "C:\ProgramData\BcContainerHelper\Extensions\$containerName\my\$fileName"

    Copy-Item -Path $sourceAppFile -Destination $signAppFile -Force

    Sign-BCContainerApp -containerName $containerName -appFile $signAppFile -pfxFile $codeSignPfxFile -pfxPassword $codeSignPfxPassword.SecretValue

    Copy-Item -Path $signAppFile -Destination $sourceAppFile
  }
  end {
  }
}

Export-ModuleMember -Function Sign-BCSAppFile