2016-08-02 11 views

答えて

0

は、Javaを使用して、ストレージアカウントのアクセスキーを取得するには、AzureのレストAPIを使用することができます。 java sdkが利用可能で、ストレージアカウントを簡単に管理できます。

アクセスキーを取得するには、ストレージアカウントがあるリソースグループ名とストレージアカウント名を使用する必要があります。これらの情報を使用してストレージアカウントを取得すると、「キー」というメソッドがアクセスキーを返します。

List<StorageAccountKey> storageAccountKeys = storageAccount.keys(); 

Hereは完全な文書のサンプルです。

よろしく

+0

ありがとうThibaut。このサンプルは、Azureが提供する標準Java SDKを使用していないようです。 – Prit

0

@Prit、あなたはアカウントキーを取得するには、JavaのためのAzureストレージサービス管理SDKを使用する必要があり、以下の手順を参照してください。

  1. 自己署名証明書を作成し、Azureの古典的なポータルのタブにSETTINGSMANAGEMENT CERTIFICATESそれをアップロードし、blogを参照してください。

I. Java keytoolを使用して証明書を作成します。以下のコマンドを参照してください。

  • のkeytool -genkeypair -aliasはmydomain -keyalg RSA -keystore WindowsAzureKeyStore.jks -keysize 2048 -storepass "test123"。

  • のkeytool -v -export -file D:\ WindowsAzureSMAPI.cer -keystore WindowsAzureKeyStore.jks -aliasはmydomain

II。 .cerファイルを次のようにアップロードします。 enter image description here

これらの依存関係をmavenプロジェクトのpom.xmlファイルに追加する必要があります。

<!-- https://mvnrepository.com/artifact/com.microsoft.azure/azure-svc-mgmt --> 
<dependency> 
    <groupId>com.microsoft.azure</groupId> 
    <artifactId>azure-svc-mgmt</artifactId> 
    <version>0.9.3</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/com.microsoft.azure/azure-svc-mgmt-storage --> 
<dependency> 
    <groupId>com.microsoft.azure</groupId> 
    <artifactId>azure-svc-mgmt-storage</artifactId> 
    <version>0.9.3</version> 
</dependency> 

ここに私のアカウントキーを取得するコードです。

import org.xml.sax.SAXException; 

import com.microsoft.windowsazure.Configuration; 
import com.microsoft.windowsazure.core.utils.KeyStoreType; 
import com.microsoft.windowsazure.exception.ServiceException; 
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration; 
import com.microsoft.windowsazure.management.storage.StorageManagementClient; 
import com.microsoft.windowsazure.management.storage.StorageManagementService; 
import com.microsoft.windowsazure.management.storage.models.StorageAccountGetKeysResponse; 

public class AccountKeys { 

    public static void main(String[] args) throws IOException, URISyntaxException, ServiceException, ParserConfigurationException, SAXException { 

     String uri = "https://management.core.windows.net/"; 
     String subscriptionId = "<subscription-id>"; 
     String keyStorePath = "<path>/WindowsAzureKeyStore.jks"; 
     String keyStorePassword = "test123"; 
     String storageName 

     Configuration config =  ManagementConfiguration.configure(
        new URI(uri), 
        subscriptionId, 
        keyStorePath, // the file path to the JKS 
        keyStorePassword, // the password for the JKS 
        KeyStoreType.jks // flags that I'm using a JKS keystore 
       ); 
     StorageManagementClient client = StorageManagementService.create(config); 
     StorageAccountGetKeysResponse response = client.getStorageAccountsOperations().getKeys(storageName); 
     String pk = response.getPrimaryKey(); 
     String sk = response.getSecondaryKey(); 
     System.out.println(pk); 
     System.out.println(sk); 
    } 
} 

参考として、関連するREST APIはhereです。

+0

Peterに感謝します。 Azureは証明書ではなくARMを使用することを推奨しているので、証明書を使用しないで何らかの方法が必要です。 – Prit

関連する問題