Cannot list image publishers from Azure java SDK(无法从 Azure java SDK 列出图像发布者)
问题描述
我正在使用 Azure ARM API,并尝试通过 Azure Java SDK 按位置列出所有发布者,方法是执行以下代码:
import com.microsoft.azure.management.compute.ComputeManagementClient;导入 com.microsoft.azure.management.compute.ComputeManagementService;导入 com.microsoft.azure.management.compute.models.VirtualMachineImageListPublishersParameters;导入 com.microsoft.azure.management.compute.models.VirtualMachineImageResourceList;@测试公共无效 testListPublishers() {ComputeManagementClient 客户端 = ComputeManagementService.create(createConfiguration());VirtualMachineImageListPublishersParameters params = new VirtualMachineImageListPublishersParameters();params.setLocation("westus");VirtualMachineImageResourceList 响应 = client.getVirtualMachineImagesOperations().listPublishers(params);ArrayList<VirtualMachineImageResource>资源 = response.getResources();System.out.println("找到的发布者:" + resources.size());}
这会产生以下请求:
GET/subscriptions/{some-subscription}/providers/Microsoft.Compute/locations/westus/publishers?api-version=2015-06-15
但是,无论我在发布者参数中放置的位置如何,我总是会得到并清空列表.我能够列出具有相同客户端的其他资源,因此创建客户端不是问题.
你对我可能做错了什么有什么建议吗?也许有我没有的权限?
谢谢!
根据我的经验,这个问题是由于 Azure AD 上注册的应用程序没有 Reader 角色引起的.我重现了这个问题,并通过为 AzureAD 应用分配读者角色来解决它.
有两种分配读者角色的方法.
- 使用带有 arm 模式的 Azure-CLI,命令
azure ad role assignment create --objectId
;-o 阅读器 -c/subscriptions/<subscriptionId>/
<块引用>
如果不知道 AzureAD 应用的 objectId,可以命令 azure ad sp show --search
通过搜索名称添加用户:
将 Reader 角色分配给 aad 应用后,您可以根据需要列出图片发布者.
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.
这篇关于无法从 Azure java SDK 列出图像发布者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法从 Azure java SDK 列出图像发布者
基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01