2014-11-03 2 views
3

Azure 웹 사이트를 자동으로 만들고 PowerShell 스크립트를 작성하여 로컬 파일 시스템의 내용을 배포해야합니다. Azure PowerShell SDK는 파일을 웹 사이트에 복사하는 방법을 제공하지 않기 때문에 FTP를 배포 방법으로 사용하고자합니다.PowerShell 및 FTP로 Azure 웹 사이트 만들기

올바른 FTP 끝점과 자격 증명을 얻으려면 Azure Management Rest API (Get a Site’s Publish Profile)를 호출해야합니다.

그러나 다른 Azure 관리 API 인이 API는 인증서가 필요합니다.

$s = Get-AzureSubscription -Current 
$thumbprint = $s.Certificate.Thumbprint 

불행하게도 현재 SDK $s.Certificate는 항상 null의 경우에,이 속성이 존재하지 않는 것 같습니다 : 나는 인증서를 얻는 방법을 설명하는 다음 튜토리얼 Building Real-World Cloud Apps with Windows Azure을 발견했다. 인증서 지문을 수동으로 설정하면 모든 것이 예상대로 작동합니다.

올바른 가입 증명서를받는 방법에 대한 아이디어가 있습니까? Azure 웹 사이트에 로컬 파일을 배포하는 쉬운 방법이 있습니까?

+1

다른 대안은 SCM (Kudu) 사이트를 통해 파일을 배포하는 것입니다. 사용 가능한 REST API (https://github.com/projectkudu/kudu/wiki/REST-API)를 참조하십시오. 구체적으로는 VFS 또는 Zip입니다. 여전히 문제가 있다면 알려주십시오. –

+0

@SuwatCh 감사합니다. Kudu는 매우 흥미로운 대안 인 것 같습니다! –

+0

@SuwatCh kudu를 사용하여 종료되었습니다. 여기 [내 요점] (https://gist.github.com/davideicardi/a8247230515177901e57) –

답변

1

지금 당신이

$thumbprint = $s.DefaultAccount 

대신

#$thumbprint = $s.Certificate.Thumbprint 

의 사용하여 인증서 지문에 액세스 할 수 있는지 보인다에서 DefaultAccount이 인증서 지문과 정확히 같은 값을 것 같다.

Function get-AzureWebSitePublishXml 
{ 
    Param(
     [Parameter(Mandatory = $true)] 
     [String]$WebsiteName 
    ) 

    # Get the current subscription 
    $s = Get-AzureSubscription -Current 
    if (!$s) {throw "Cannot get Windows Azure subscription."} 

    #$thumbprint = $s.Certificate.Thumbprint #this code doesn't work anymore 
    $thumbprint = $s.DefaultAccount 
    if (!$thumbprint) { throw "Cannot get subscription cert thumbprint."} 

    # Get the certificate of the current subscription from your local cert store 
    $cert = Get-ChildItem Cert:\CurrentUser\My\$thumbprint 
    if (!$cert) {throw "Cannot find subscription cert in Cert: drive."} 

    $website = Get-AzureWebsite -Name $WebsiteName 
    if (!$website) {throw "Cannot get Windows Azure website: $WebsiteName."} 

    # Compose the REST API URI from which you will get the publish settings info 
    $uri = "https://management.core.windows.net:8443/{0}/services/WebSpaces/{1}/sites/{2}/publishxml" -f ` 
     $s.SubscriptionId, $website.WebSpace, $Website.Name 

    # Get the publish settings info from the REST API 
    $publishSettings = Invoke-RestMethod -Uri $uri -Certificate $cert -Headers @{"x-ms-version" = "2013-06-01"} 
    if (!$publishSettings) {throw "Cannot get Windows Azure website publishSettings."} 

    return $publishSettings 
} 

참고 : 그냥 여기 참조

는 특정 웹 사이트에 대한 게시 프로파일을 얻기 위해 내 전체 스크립트 당신이 가져 오기 - AzurePublishSettingsFile를 사용하여 푸른에 연결 한 경우에만 작동합니다

사람이 수 DefaultAccount 속성을 사용하는 것이 안전한지 확인하십시오. 당신이 당신의 위치, like this을 업로드 Kudu API를 사용하는 경우

UPDATE

, 당신은 어떤 인증서 또는 공개 프로필이 필요하지 않습니다. Get-AzureWebsite을 사용하여 사용자 이름과 암호를 읽고 호스트 이름은 yourwebsitename.scm.azurewebsites.net입니다 (scm 세그먼트에주의하십시오). Kudu를 사용하는 것이 훨씬 더 빠르고 안정적이기 때문에 제안합니다.