Reputation: 1293
I am trying to set up a custom domain in api management using a bash script. I know it can be done using powershell
# Upload the custom ssl certificate to be applied to Proxy endpoint / Api Gateway endpoint
$proxyCertUploadResult = Import-AzApiManagementHostnameCertificate -Name $apimServiceName -
ResourceGroupName $resourceGroupName -HostnameType "Proxy" -PfxPath $proxyCertificatePath -
PfxPassword $proxyCertificatePassword
# Upload the custom ssl certificate to be applied to Portal endpoint
$portalCertUploadResult = Import-AzApiManagementHostnameCertificate -Name $apimServiceName -
ResourceGroupName $resourceGroupName -HostnameType "Portal" -PfxPath $portalCertificatePath -
PfxPassword $portalCertificatePassword
# Create the HostnameConfiguration object for Portal endpoint
$PortalHostnameConf = New-AzApiManagementHostnameConfiguration -Hostname $proxyHostname -
CertificateThumbprint $proxyCertUploadResult.Thumbprint
# Create the HostnameConfiguration object for Proxy endpoint
$ProxyHostnameConf = New-AzApiManagementHostnameConfiguration -Hostname $portalHostname -
CertificateThumbprint $portalCertUploadResult.Thumbprint
# Apply the configuration to API Management
Set-AzApiManagementHostnames -Name $apimServiceName -ResourceGroupName $resourceGroupName `
-PortalHostnameConfiguration $PortalHostnameConf -ProxyHostnameConfiguration $ProxyHostnameConf
Is it possible to do a similar thing using bash?
Upvotes: 1
Views: 1960
Reputation: 149
If some one is looking for complete script here it is. Just change the parameter as per your need. If you are using wildcard certificate then the keyvault id will be same for both gateway and for the developer portal.
[CmdletBinding()]
param (
[String]
$ResourceGroupName,
[String]
$GatewayHostname,
[String]
$ApimServiceName,
[String]
$GatewayCertificateKeyVaultId,
[String]
$PortalHostname,
[String]
$PortalCertificateKeyVaultId
)
$config ='[{\"hostName\":\"'+$GatewayHostname+'\",\"type\":\"Proxy\",\"keyVaultId\":\"'+$GatewayCertificateKeyVaultId+'\",\"defaultSslBinding\":true,\"negotiateClientCertificate\":false},{\"hostName\":\"'+$PortalHostname+'\",\"type\":\"DeveloperPortal\",\"keyVaultId\":\"'+$PortalCertificateKeyVaultId+'\"}]'
Write-Host $config
az apim update --resource-group $ResourceGroupName --name $ApimServiceName --set hostnameConfigurations=$config
Upvotes: 0
Reputation: 56
You can use this approach:
az apim update --resource-group $rgName --name $apiMgmtName `
--add hostnameConfigurations type=Proxy host_name=$hostName `
encodedCertificate=$certData certificatePassword=$certPassword `
negotiateClientCertificate=false
Upvotes: 1
Reputation: 23151
If you want to configure custom domain for Azure API management with Azure CLI, we can use the command az apim update --set hostnameConfigurations={setting}
.
The hostnameConfigurations setting should be like
[{
"hostName": "bbb.beesphotos.net",
"type": "Portal",
"certificate": null,
"certificatePassword": "<pfx file passsword>",
"encodedCertificate": "Base64 Encoded certificate content"
}, {
"hostName": "huryapim.azure-api.net",
"type": "Proxy",
"certificate": null,
"defaultSslBinding": true,
"negotiateClientCertificate": false
}
]
Upvotes: 4