无法从Azure Java SDK列出图像发布者 [英] Cannot list image publishers from Azure java SDK
问题描述
我正在使用Azure ARM API,并且通过执行以下代码,试图通过Azure Java SDK通过位置列出所有发布者:
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());
}
这将导致以下请求:
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?
谢谢!
推荐答案
根据我的经验,该问题是由在Azure AD上注册的应用程序没有读取器角色引起的.我转载了该问题,并通过将读者角色分配给AzureAD应用程序解决了该问题.
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.
- 使用带手臂模式的Azure-CLI和命令
azure ad role assignment create --objectId <objectId of the aad app> -o Reader -c /subscriptions/<subscriptionId>/
如果您不知道AzureAD应用程序的objectId,则可以命令
azure ad sp show --search <the aad app name>
进行查看.如果没有用于Azure AD的Service Principal (SP)
,则可以命令azure ad sp create <clientId>
来创建它.
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.
- 当应用程序在Azure新门户上显示时,通过
All settings -> RESOURCE MANAGEMENT -> Users
添加角色和用户,请参见下面的图片.
- Add the role and user via
All settings -> RESOURCE MANAGEMENT -> Users
when the application shown on Azure new portal, please see the pics below.
选择一个角色Reader
:
通过搜索名称添加用户:
Add a user by searching name:
将读者角色分配给aad应用后,您可以根据需要列出图像发布者.
After assign the Reader role to the aad app, you can list the image publishers as your wish.
这篇关于无法从Azure Java SDK列出图像发布者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!