問(wèn)題描述
我正在使用 Azure ARM API,并嘗試通過(guò) Azure Java SDK 按位置列出所有發(fā)布者,方法是執(zhí)行以下代碼:
import com.microsoft.azure.management.compute.ComputeManagementClient;導(dǎo)入 com.microsoft.azure.management.compute.ComputeManagementService;導(dǎo)入 com.microsoft.azure.management.compute.models.VirtualMachineImageListPublishersParameters;導(dǎo)入 com.microsoft.azure.management.compute.models.VirtualMachineImageResourceList;@測(cè)試公共無(wú)效 testListPublishers() {ComputeManagementClient 客戶(hù)端 = ComputeManagementService.create(createConfiguration());VirtualMachineImageListPublishersParameters params = new VirtualMachineImageListPublishersParameters();params.setLocation("westus");VirtualMachineImageResourceList 響應(yīng) = client.getVirtualMachineImagesOperations().listPublishers(params);ArrayList<VirtualMachineImageResource>資源 = response.getResources();System.out.println("找到的發(fā)布者:" + resources.size());}
這會(huì)產(chǎn)生以下請(qǐng)求:
GET/subscriptions/{some-subscription}/providers/Microsoft.Compute/locations/westus/publishers?api-version=2015-06-15
但是,無(wú)論我在發(fā)布者參數(shù)中放置的位置如何,我總是會(huì)得到并清空列表.我能夠列出具有相同客戶(hù)端的其他資源,因此創(chuàng)建客戶(hù)端不是問(wèn)題.
你對(duì)我可能做錯(cuò)了什么有什么建議嗎?也許有我沒(méi)有的權(quán)限?
謝謝!
根據(jù)我的經(jīng)驗(yàn),這個(gè)問(wèn)題是由于 Azure AD 上注冊(cè)的應(yīng)用程序沒(méi)有 Reader 角色引起的.我重現(xiàn)了這個(gè)問(wèn)題,并通過(guò)為 AzureAD 應(yīng)用分配讀者角色來(lái)解決它.
有兩種分配讀者角色的方法.
- 使用帶有 arm 模式的 Azure-CLI,命令
azure ad role assignment create --objectId
;-o 閱讀器 -c/subscriptions/<subscriptionId>/
<塊引用>
如果不知道 AzureAD 應(yīng)用的 objectId,可以命令 azure ad sp show --search
通過(guò)搜索名稱(chēng)添加用戶(hù):
將 Reader 角色分配給 aad 應(yīng)用后,您可以根據(jù)需要列出圖片發(fā)布者.
I'm using the Azure ARM API and I'm trying to list all publishers by location through the Azure Java SDK, by executing the following code:
import com.microsoft.azure.management.compute.ComputeManagementClient;
import com.microsoft.azure.management.compute.ComputeManagementService;
import com.microsoft.azure.management.compute.models.VirtualMachineImageListPublishersParameters;
import com.microsoft.azure.management.compute.models.VirtualMachineImageResourceList;
@Test
public void testListPublishers() {
ComputeManagementClient client = ComputeManagementService.create(createConfiguration());
VirtualMachineImageListPublishersParameters params = new VirtualMachineImageListPublishersParameters();
params.setLocation("westus");
VirtualMachineImageResourceList response = client.getVirtualMachineImagesOperations().listPublishers(params);
ArrayList<VirtualMachineImageResource> resources = response.getResources();
System.out.println("Found publishers: " + resources.size());
}
This results in the following request:
GET /subscriptions/{some-subscription}/providers/Microsoft.Compute/locations/westus/publishers?api-version=2015-06-15
However, I always get and empty list, no matter the location I put in the publisher parameters. I am able to list other resources with the same client, so it is not an issue in creating the client.
Do you have any suggestions of what I might be doing wrong? Perhaps there is a permission that I don't have?
Thanks!
Per my experience, the issue was caused by the application registed on Azure AD has no Reader role. I reproduced the issue, and resolved it via assign a Reader role to the AzureAD app.
There are two way for assigning a Reader role.
- Using Azure-CLI with arm mode, and command
azure ad role assignment create --objectId <objectId of the aad app> -o Reader -c /subscriptions/<subscriptionId>/
If you don't know the objectId of the AzureAD app, you can command
azure ad sp show --search <the aad app name>
to review it. If you have noService Principal (SP)
for Azure AD, you can commandazure ad sp create <clientId>
to create it.
- Add the role and user via
All settings -> RESOURCE MANAGEMENT -> Users
when the application shown on Azure new portal, please see the pics below.
Select a role Reader
:
Add a user by searching name:
After assign the Reader role to the aad app, you can list the image publishers as your wish.
這篇關(guān)于無(wú)法從 Azure java SDK 列出圖像發(fā)布者的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!