2017-04-04 13 views
1

Azure Powershell SDK을 사용하지만 여전히 create Custom SSL Domains for CDNs in Azure via API Management으로 보일 수 없습니다. 우리는 미래의 확장 성을 위해이 작업의 생성을 스크립팅 할 수 있어야하고 생성 할 수있는 100 개의 하위 도메인을 필요로합니다.Azure CDN - 리소스 관리 API를 통한 사용자 정의 도메인 SSL

enter image description here

사람은 SDK has no support 이후 REST API를 통해이 플래그를 전환하는 방법을 알고 있나요? 우리는 New-AzureRmCdnCustomDomain commandlet을 사용하고 있습니다. 사용자 정의 도메인 HTTPS를 가능하게하는

답변

2

나머지 API는 사용자 정의 도메인의 HTTPS 전달을 활성화 정의 HTTPS를

사용 docs.microsoft.com

에 설명되어 있습니다. 당신은 푸른 REST API를 사용하기 전에

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/customDomains/{customDomainName}/enableCustomHttps?api-version=2016-10-02 

당신은 an access token을 얻을 필요가 :

액세스를 생성 토큰을 사용하여 PowerShell을 : 응답은 액세스 토큰을 포함

$Token = Invoke-RestMethod -Uri https://login.microsoftonline.com/<TenantID>/oauth2/token?api-version=1.0 -Method Post -Body @{ 
    "grant_type" = "client_credentials" 
    "resource" = "https://management.core.windows.net/" 
    "client_id" = "<application id>" 
    "client_secret" = "<password you selected for authentication>" 
} 

을 , 토큰이 유효한 기간 및 wha에 대한 정보 t 리소스에 대해 토큰을 사용할 수 있습니다. 이전 HTTP 호출 에서 수신 한 액세스 토큰은 모든 요청에 ​​대해 Resource Manager API에 전달되어야합니다. "Bearer YOUR_ACCESS_TOKEN"값의 "Authorization"이라는 헤더 값으로 전달하십시오. "무기명"과 귀하의 액세스 토큰 사이의 공간을 확인하십시오.

Azure AD에서 앱 등록을 생성하면 클라이언트 ID가 검색되고 클라이언트 등록 정보는 생성 된 앱 등록의 키 섹션에서 생성됩니다.

$subscriptionId = "..." 
$resourceGroupName = "..." 
$profileName = "..." 
$endpointName = "..." 
$customDomainName = ".." 

$Token = Invoke-RestMethod -Uri https://login.microsoftonline.com/<TenantID>/oauth2/token?api-version=1.0 -Method Post -Body @{ 
    "grant_type" = "client_credentials" 
    "resource" = "https://management.core.windows.net/" 
    "client_id" = "<application id>" 
    "client_secret" = "<password you selected for authentication>" 
} 

$header = @{ 
    "Authorization"= "Bearer $($Token.access_token)" 
} 

Invoke-RestMethod -Method Post -Headers $header -Uri "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/customDomains/$customDomainName/enableCustomHttps?api-version=2016-10-02" 

이 스크립트를 자동화 할 필요가없는 경우, 당신은 GUI (앱 등록을위한 필요 없음)이 수정 된 샘플을 사용을 사용하여 수동으로 로그인 할 수 있습니다 (Source에 따라이이 같은 솔루션으로 결합 할 수 있습니다). Install-Module AzureRM을 사용하여 설치할 수있는 AzureRM -module이 필요합니다.

Function Login-AzureRESTApi { 

    Import-Module AzureRM.Profile 

    # Load ADAL Azure AD Authentication Library Assemblies 
    $modulepath = Split-Path (Get-Module -Name AzureRM.Profile).Path 
    $adal = "$modulepath\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" 
    $adalforms = "$modulepath\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" 
    $null = [System.Reflection.Assembly]::LoadFrom($adal) 
    $null = [System.Reflection.Assembly]::LoadFrom($adalforms) 

    # Login to Azure 
    $Env = Login-AzureRmAccount 

    # Select Subscription 
    $Subscription = (Get-AzureRmSubscription | Out-GridView -Title "Choose a subscription ..." -PassThru) 
    $adTenant = $Subscription.TenantId 
    $global:SubscriptionID = $Subscription.SubscriptionId 

    # Client ID for Azure PowerShell 
    $clientId = "1950a258-227b-4e31-a9cf-717495945fc2" 

    # Set redirect URI for Azure PowerShell 
    $redirectUri = "urn:ietf:wg:oauth:2.0:oob" 

    # Set Resource URI to Azure Service Management API | @marckean 
    $resourceAppIdURIASM = "https://management.core.windows.net/" 
    $resourceAppIdURIARM = "https://management.azure.com/" 

    # Set Authority to Azure AD Tenant 
    $authority = "https://login.windows.net/$adTenant" 

    # Create Authentication Context tied to Azure AD Tenant 
    $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority 

    # Acquire token 
    $global:authResultASM = $authContext.AcquireToken($resourceAppIdURIASM, $clientId, $redirectUri, "Auto") 
    $global:authResultARM = $authContext.AcquireToken($resourceAppIdURIARM, $clientId, $redirectUri, "Auto") 

} 

$resourceGroupName = "..." 
$profileName = "..." 
$endpointName = "..." 
$customDomainName = ".." 

Login-AzureRESTApi 

#Reuse selected subscription from login 
$Subscription = $global:subscriptionId 

$header = @{ 
    "Authorization"= $global:authResultARM.CreateAuthorizationHeader() 
} 

Invoke-RestMethod -Method Post -Headers $header -Uri "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/customDomains/$customDomainName/enableCustomHttps?api-version=2016-10-02"