chris
chris

Reputation: 2858

Upload public certificate to Azure Function App using a CLI

I need to make requests to an API which has a certificate issued by a custom certificate authority. Currently I am uploading the public certificate for each slot in each Function App through the portal. Is it possible to automate the uploading of this certificate using the Azure CLI or PowerShell? I've seen documentation on how to upload private certificates to Azure App Services, but I haven't found anything on how to upload public certificates.

Upvotes: 1

Views: 1485

Answers (1)

Jim Xu
Jim Xu

Reputation: 23141

If you want to upload public certificate to Azure function app, we can use the Azure Rest API

For example (I use the PowerShell to call the api)

Connect-AzAccount

#get function app
$appName="testpy05"
$groupName="testpy"
$app =Get-AzWebApp -ResourceGroupName $groupName -Name $appName

#get public certificate content
$cerpath="E:\Cert\test.cer"
$cerFileBytes = get-content $cerpath -Encoding Byte
$cerblob=[System.Convert]::ToBase64String($cerFileBytes)

$properties=@{
 blob =$cerblob;
 publicCertificateLocation="CurrentUserMy"
}

New-AzResource -ResourceName "$($appName)/testcer" -ResourceType "Microsoft.Web/sites/publicCertificates" `
         -Properties $properties -ResourceGroupName $groupName 

enter image description here

Upvotes: 2

Related Questions