2017-03-24 8 views
0

Azure Fluent Management APIを使用して展開プロセスを自動化しています。今まで私は最小限の問題しか持っていませんでした。既存のSSL証明書をAzure Webアプリケーションにプログラムで適用する方法

すでにSSL証明書がAzureにアップロードされており、手動でAzureポータルからWebサイトにバインドできます。しかし、私はプログラムでこれを行うための仕組みを見つけることができません。

私が見つけやすいのは、以下の通りです。hereです。

webApp.Update() 
    .DefineSslBinding() 
    .ForHostname(domainName) 
    .WithPfxCertificateToUpload(pfxFile, password) 
    .WithSniBasedSsl() 
    .Attach(); 

ただし、これは明らかに既存の証明書を使用せずに新しい証明書をアップロードすることです。 ありForHostName()コールの後に他の二つのオプションがあります

WithExistingAppServiceCertificateOrder(certificateOrder) 

WithNewStandardSslCertificateOrder(certificateOrderName) 

は、しかし、私の理解では、これらはアズール/マイクロソフトを通じて証明書を購入に関連していることです。

また、REST API documentationには何も表示されません。

既存の証明書をWebアプリケーションとコードで関連付けるにはどうすればよいですか?

答えて

0

私が知る限り、Azure Fluent Management APIのバージョンは1.0.0-beta50なので、既存の証明書をホスト名に追加するメソッドを含んでいない可能性があります。

これを達成するためにREST APIを使用することをお勧めします。

以下のURLにリクエストを送信することをお勧めします。

Url: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{snapshotName}?api-version={api-version} 

Method: PUT 

Parameter: 
subscriptionId The identifier of your subscription where the snapshot is being created. 
resourceGroup The name of the resource group that will contain the snapshot. 
WebappName The name of the WebappName. 
api-version The version of the API to use. 

Request content: 
{ 
    "properties": { 
    "HostNameSslStates": [ 
     { 
     "SslState": "the SSL state", 
     "ToUpdate": "True", 
     "Thumbprint": "The Thumbprint of the certificate, you could find it in the portal", 
     "Name": "yourwebsitename" 
     } 
    ] 
}, 
    "kind": "app", 
    "location": "yourlocation", 
    "tags": { 
    "hidden-related:/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/Microsoft.Web/serverfarms/{yourserviceplan}": "empty" 
    } 
} 

詳細は、C#のコード以下を参照してください可能性:

Json.txt:

{ 
    "properties": { 
    "HostNameSslStates": [ 
     { 
     "SslState": "1", 
     "ToUpdate": "True", 
     "Thumbprint": "BE58B05C5CADE03628D0D58B369D0DA6F535B0FA", 
     "Name": "test.azureclubs.com" 
     } 
    ] 
}, 
    "kind": "app", 
    "location": "East Asia", 
    "tags": { 
    "hidden-related:/subscriptions/xxxxxxxxxxxxxxxx/resourcegroups/xxxxxxxxxxxxx/providers/Microsoft.Web/serverfarms/BrandoTestServicePlan": "empty" 
    } 
} 

コード:

string body = File.ReadAllText(@"D:\json.txt"); 

      // Display the file contents to the console. Variable text is a string. 

      string tenantId = "xxxxxxxxxxxxxxxxxxxxxxxxx"; 
      string clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
      string clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxx"; 
      string subscriptionid = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; 
      string resourcegroup = "BrandoSecondTest"; 

      string appname = "BrandoTestApp"; 
      string version = "2015-08-01"; 

      string authContextURL = "https://login.windows.net/" + tenantId; 
      var authenticationContext = new AuthenticationContext(authContextURL); 
      var credential = new ClientCredential(clientId, clientSecret); 
      var result = authenticationContext.AcquireTokenAsync(resource: "https://management.azure.com/", clientCredential: credential).Result; 

      if (result == null) 
      { 
       throw new InvalidOperationException("Failed to obtain the JWT token"); 
      } 

      string token = result.AccessToken; 

      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Web/sites/{2}?api-version={3}", subscriptionid, resourcegroup, appname, version)); 

      request.Method = "PUT"; 
      request.Headers["Authorization"] = "Bearer " + token; 


      request.ContentType = "application/json"; 
      try 
      { 
       using (var streamWriter = new StreamWriter(request.GetRequestStream())) 
       { 
        streamWriter.Write(body); 
       } 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex.Message); 
      } 
      // Get the response 
      var httpResponse = (HttpWebResponse)request.GetResponse(); 
      using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) 
      { 
       Console.WriteLine(streamReader.ReadToEnd()); 
      } 
+0

回避策を探していただきありがとうございます。 オリジナルの投稿から機能を追加したのか、それとも非明白な場所に隠れてしまったのかはっきりしていません。 – illusio

0

明らかにこれは私が「与えられた重要ではなかったですただ9ヶ月後にanswerが見つかりました。

いずれにせよ、以下の回答は、提供されたリンクからコピーされています。

await azure 
     .WebApps 
     .Inner 
     .CreateOrUpdateHostNameBindingWithHttpMessagesAsync(
      resourceGroupName, 
      webAppName, 
      domain, 
      new HostNameBindingInner(
       azureResourceType: AzureResourceType.Website, 
       hostNameType: HostNameType.Verified, 
       customHostNameDnsRecordType: CustomHostNameDnsRecordType.CName, 
       sslState: SslState.SniEnabled, 
       thumbprint: thumbprint)); 
関連する問題