简体   繁体   English

Azure:使用StorageManagementClient获取经典存储帐户密钥

[英]Azure : Get classic storage account key using StorageManagementClient

I am trying to automatically retrieve the key of a classic Storage Account using StorageManagementClient. 我正在尝试使用StorageManagementClient自动检索经典存储帐户的密钥。

For new ones, this worked fine client.storage_accounts.list_keys(resource_group_name, storage_account_name) but for classic ones I end up with the following error : 对于新的,这很好用client.storage_accounts.list_keys(resource_group_name, storage_account_name)但是对于经典的,我会client.storage_accounts.list_keys(resource_group_name, storage_account_name)以下错误:

msrestazure.azure_exceptions.CloudError: Azure Error: ResourceNotFound
Message: The Resource 'Microsoft.Storage/storageAccounts/<storage_account_name>' under resource group '<resource_group_name>' was not found.

I did not find a way to also include classic resources in the documentation (see https://github.com/Azure/azure-sdk-for-python/tree/master/azure-mgmt-storage/azure/mgmt/storage ). 我没有找到在文档中也包含经典资源的方法(请参阅https://github.com/Azure/azure-sdk-for-python/tree/master/azure-mgmt-storage/azure/mgmt/storage ) 。

Do I simply have to use another API / client ? 我是否只需要使用另一个API /客户端?

You can't with this package, you need to use the ASM (Azure Service Management) package called azure-servicemanagement-legacy : https://pypi.org/project/azure-servicemanagement-legacy/ 您无法使用此软件包,需要使用称为azure-servicemanagement-legacy的ASM(Azure服务管理)软件包: https : //pypi.org/project/azure-servicemanagement-legacy/

See this unittest from this testfile: https://github.com/Azure/azure-sdk-for-python/blob/master/azure-servicemanagement-legacy/tests/test_legacy_mgmt_storage.py 从以下测试文件中查看此单元测试: https : //github.com/Azure/azure-sdk-for-python/blob/master/azure-servicemanagement-legacy/tests/test_legacy_mgmt_storage.py

def test_get_storage_account_keys(self):
    # Arrange
    self._create_storage_account(self.storage_account_name)

    # Act
    result = self.sms.get_storage_account_keys(self.storage_account_name)

    # Assert
    self.assertIsNotNone(result)
    self.assertIsNotNone(result.url)
    self.assertIsNotNone(result.service_name)
    self.assertIsNotNone(result.storage_service_keys.primary)
    self.assertIsNotNone(result.storage_service_keys.secondary)
    self.assertIsNone(result.storage_service_properties)

Edit : You might want to try a ARM resource call using azure-mgmt-resource (see https://stackoverflow.com/a/45814624/4074838 for details) to this URL: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys?api-version=2015-06-01 编辑 :您可能想尝试使用azure-mgmt-resource (有关详细信息,请参阅https://stackoverflow.com/a/45814624/4074838 )到此URL的ARM资源调用: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys?api-version=2015-06-01 : https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys?api-version=2015-06-01

You can create a ResourceManagementClient client client , and call client.resources.get_by_id(subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys, '2015-06-01') As described in the answer I mention however, there is no guarantee this call will continue to work in the future (if it's even still working now) 您可以创建ResourceManagementClient客户client客户client ,然后调用client.resources.get_by_id(subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys, '2015-06-01')但是,正如我提到的答案中所描述的那样,不能保证此调用将来会继续有效(如果现在仍在起作用)

Ref: https://docs.microsoft.com/en-us/python/api/azure.mgmt.resource.resources.v2017_05_10.operations.resourcesoperations?view=azure-python#get-by-id 参考: https : //docs.microsoft.com/zh-cn/python/api/azure.mgmt.resource.resources.v2017_05_10.operations.resourcesoperations? view = azure-python#get-by- id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python 获取 Azure 的所有存储帐户名称及其访问密钥 - How to get all storage account name and their access key of Azure using Python 如何使用 python 中的存储帐户密钥对 azure 存储 api 请求进行身份验证? - How to authenticate an azure storage api request using a storage account key in python? 使用python将CSV文件上载到Microsoft Azure存储帐户 - Upload CSV file into Microsoft Azure storage account using python 如何使用Azure存储帐户SAS令牌列出所有Blob? - How to List all Blobs using Azure Storage Account SAS Token? 使用API​​共享密钥在azure Blob Storage中获取blob - Get blob in azure Blob Storage with API shared key Python:如何使用共享访问密钥连接到Azure云存储? - Python: How to connect to Azure cloud storage using shared access key? Azure 存储帐户 blob stream 和 Python - Azure Storage Account blob stream with Python 如何使用Python将Azure中的文件从一个存储帐户复制到另一个存储帐户? - How to copy a file in Azure from a one storage account to another using Python? 列出 json 文件,按年/月/日分区,来自 Azure 帐户存储使用 PySpark - List json files, partitioned by year/month/day, from Azure account storage using PySpark 如何使用Azure Python SDK向存储帐户中的内置角色添加权限? - How to add permission to builtin role in storage account using Azure Python SDK?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM