Azure SDK中的哪个Java API删除NetworkSecurityRule?

问题描述 投票:0回答:1

我无法从Azure SDK中找到Java API来删除NetworkSecurityRule资源。

REST API已记录在here中。

我使用此Maven依赖项:com.microsoft.azure:azure-mgmt-network:jar:1.31.0

在我的代码中,我拥有对NetworkManager实例的引用,并且我有NetworkSecurityRule个对象的集合。

有人知道怎么做吗?

谢谢,克里斯

java azure security networking azure-sdk
1个回答
0
投票

根据我的测试,我们可以使用以下代码。有关更多详细信息,请参阅docuemnt。1.创建一个服务主体,并为sp指定读者角色。

az login
az account set --subscription "<your subscription id>"
# it will assign  Contributor to the sp at subscription level
az ad sp create-for-rbac -n "mysample" --role  Contributor

enter image description here

  1. 代码
public static void main(String[] args){
 String clientId = "your sp appId";
       String secret = "your sp password";
       String domain = "your tenant domain";
       ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(clientId, domain, secret,
            AzureEnvironment.AZURE);
       Azure azure = AzureAzure.configure().withLogLevel(LogLevel.BASIC).authenticate(credentials)
            .withDefaultSubscription();

       NetworkSecurityGroup group = azure.networkSecurityGroups().getById(
            "your nsg resource id");

       for(String i : group.securityRules().keySet()){

            System.out.println(i);

       } 

       group.update().withoutRule.apply();
       group = azure.networkSecurityGroups().getById(
            "/subscriptions/e5b0fcfa-e859-43f3-8d84-5e5fe29f4c68/resourceGroups/testgroup/providers/Microsoft.Network/networkSecurityGroups/test0123");
       System.out.println(group.Name());
       for(String i : group.securityRules().keySet()){

            System.out.println(i);

       } 
}

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.