无法列出来自 Azure java SDK 的图像发布者
Cannot list image publishers from Azure java SDK
我正在使用 Azure ARM API,我正在尝试通过 Azure Java SDK 按位置列出所有发布者,方法是执行以下代码:
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
但是,无论我在发布者参数中放置的位置如何,我总是得到一个空列表。
我能够列出具有相同客户端的其他资源,因此创建客户端不是问题。
您对我可能做错的地方有什么建议吗?也许有我没有的权限?
谢谢!
根据我的经验,问题是由在 Azure AD 上注册的应用程序没有 Reader 角色引起的。我重现了这个问题,并通过为 AzureAD 应用分配 Reader 角色解决了这个问题。
有两种分配 Reader 角色的方法。
- 在手臂模式下使用 Azure-CLI,并使用命令
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 no Service Principal (SP)
for Azure AD, you can command azure ad sp create <clientId>
to create it.
- 当应用程序显示在 Azure 新门户上时,通过
All settings -> RESOURCE MANAGEMENT -> Users
添加角色和用户,请参见下图。
Select 一个角色 Reader
:
通过搜索姓名添加用户:
将Reader角色分配给aad应用后,您可以根据需要列出图像发布者。
我正在使用 Azure ARM API,我正在尝试通过 Azure Java SDK 按位置列出所有发布者,方法是执行以下代码:
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
但是,无论我在发布者参数中放置的位置如何,我总是得到一个空列表。 我能够列出具有相同客户端的其他资源,因此创建客户端不是问题。
您对我可能做错的地方有什么建议吗?也许有我没有的权限?
谢谢!
根据我的经验,问题是由在 Azure AD 上注册的应用程序没有 Reader 角色引起的。我重现了这个问题,并通过为 AzureAD 应用分配 Reader 角色解决了这个问题。
有两种分配 Reader 角色的方法。
- 在手臂模式下使用 Azure-CLI,并使用命令
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.
- 当应用程序显示在 Azure 新门户上时,通过
All settings -> RESOURCE MANAGEMENT -> Users
添加角色和用户,请参见下图。
Select 一个角色 Reader
:
通过搜索姓名添加用户:
将Reader角色分配给aad应用后,您可以根据需要列出图像发布者。