我尝试获取 APIM 客户端,我发现通过 apiManagement.Service.HostnameConfigurations,我可以获得一些有关自定义域内内容的信息、有关证书的信息,但没有方法上传新的或换一个新的。我只能修改实际信息,例如到期日期、指纹等。
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
var apiManagementClient = new ApiManagementClient(credentials) { SubscriptionId = subscriptionId };
var certificateClient = new CertificateClient(new Uri(KeyVaultUrl), new DefaultAzureCredential());
var certificate = await certificateClient.GetCertificateAsync(certificateName);
var apiManagementService = await apiManagementClient.ApiManagementService.GetAsync(
resourceGroupName,
serviceName);
var certificateList = apiManagementClient.Certificate.ListByService(resourceGroupName, serviceName);
var certificateExpiryDate = certificateList.FirstOrDefault(l=>l.Name.Equals(certificateName)).ExpirationDate;
var certificateThumbprint = certificateList.FirstOrDefault(l => l.Name.Equals(certificateName)).Thumbprint;
var certificateInformation = new CertificateInformation
{
Expiry = certificateExpiryDate,
Subject = "",
Thumbprint = certificateName,
};
var customDomain = apiManagementService.HostnameConfigurations.FirstOrDefault(v => v.CertificateSource.Equals("KeyVault"));
customDomain.Certificate = certificateInformation;
您可以通过 UpdateWithHttpMessagesAsync 操作更新 APIM 服务主机名配置。在
HostnameConfigurations
属性中传递您的自定义主机名信息。
Type
属性指定您想要自定义域的 APIM 中的哪个端点。
CertificateSource
属性指定证书的来源:
KeyVaultId
,可能还有 IdentityClientId
EncodedCertificate
和 CertificatePassword