mirror of https://github.com/apache/jclouds.git
Network Security Group API
This commit is contained in:
parent
f2b5c15566
commit
8d8cd1728d
|
@ -29,6 +29,8 @@ import org.jclouds.azurecompute.arm.features.VirtualMachineApi;
|
||||||
import org.jclouds.azurecompute.arm.features.VirtualNetworkApi;
|
import org.jclouds.azurecompute.arm.features.VirtualNetworkApi;
|
||||||
import org.jclouds.azurecompute.arm.features.VMSizeApi;
|
import org.jclouds.azurecompute.arm.features.VMSizeApi;
|
||||||
import org.jclouds.azurecompute.arm.util.DeploymentTemplateBuilder;
|
import org.jclouds.azurecompute.arm.util.DeploymentTemplateBuilder;
|
||||||
|
import org.jclouds.azurecompute.arm.features.NetworkSecurityGroupApi;
|
||||||
|
import org.jclouds.azurecompute.arm.features.NetworkSecurityRuleApi;
|
||||||
import org.jclouds.rest.annotations.Delegate;
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
@ -137,7 +139,23 @@ public interface AzureComputeApi extends Closeable {
|
||||||
@Delegate
|
@Delegate
|
||||||
DeploymentApi getDeploymentApi(@PathParam("resourcegroup") String resourceGroup);
|
DeploymentApi getDeploymentApi(@PathParam("resourcegroup") String resourceGroup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The NetworkSecurityGroup API includes operations for managing network security groups within your subscription.
|
||||||
|
*
|
||||||
|
* @see <a href="https://msdn.microsoft.com/en-us/library/azure/mt163615.aspx">docs</a>
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
NetworkSecurityGroupApi getNetworkSecurityGroupApi(@PathParam("resourcegroup") String resourcegroup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The NetworkSecurityRule API includes operations for managing network security rules within a network security group.
|
||||||
|
*
|
||||||
|
* @see <a href="https://msdn.microsoft.com/en-us/library/azure/mt163580.aspx">docs</a>
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
NetworkSecurityRuleApi getNetworkSecurityRuleApi(@PathParam("resourcegroup") String resourcegroup,
|
||||||
|
@PathParam("networksecuritygroup") String networksecuritygroup);
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
DeploymentTemplateBuilder.Factory deploymentTemplateFactory();
|
DeploymentTemplateBuilder.Factory deploymentTemplateFactory();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.domain;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.json.SerializedNames;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class NetworkSecurityGroup {
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String location();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Map<String, String> tags();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract NetworkSecurityGroupProperties properties();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String etag();
|
||||||
|
|
||||||
|
@SerializedNames({"name", "location", "tags", "properties", "etag"})
|
||||||
|
public static NetworkSecurityGroup create(final String name,
|
||||||
|
final String location,
|
||||||
|
final Map<String, String> tags,
|
||||||
|
final NetworkSecurityGroupProperties properties,
|
||||||
|
final String etag) {
|
||||||
|
return new AutoValue_NetworkSecurityGroup(name, location,
|
||||||
|
(tags == null) ? null : ImmutableMap.copyOf(tags),
|
||||||
|
properties, etag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.domain;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.json.SerializedNames;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class NetworkSecurityGroupProperties {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<NetworkSecurityRule> securityRules();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<NetworkSecurityRule> defaultSecurityRules();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<NetworkInterfaceCard> networkInterfaces();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<Subnet> subnets();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String resourceGuid();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String provisioningState();
|
||||||
|
|
||||||
|
@SerializedNames({"securityRules", "defaultSecurityRules", "networkInterfaces", "subnets", "resourceGuid", "provisioningState"})
|
||||||
|
public static NetworkSecurityGroupProperties create(final List<NetworkSecurityRule> securityRules,
|
||||||
|
final List<NetworkSecurityRule> defaultSecurityRules,
|
||||||
|
final List<NetworkInterfaceCard> networkInterfaces,
|
||||||
|
final List<Subnet> subnets,
|
||||||
|
final String resourceGuid,
|
||||||
|
final String provisioningState) {
|
||||||
|
return builder()
|
||||||
|
.securityRules((securityRules == null) ? null : ImmutableList.copyOf(securityRules))
|
||||||
|
.defaultSecurityRules((defaultSecurityRules == null) ? null : ImmutableList.copyOf(defaultSecurityRules))
|
||||||
|
.networkInterfaces((networkInterfaces == null) ? null : ImmutableList.copyOf(networkInterfaces))
|
||||||
|
.subnets((subnets == null) ? null : ImmutableList.copyOf(subnets))
|
||||||
|
.resourceGuid(resourceGuid)
|
||||||
|
.provisioningState(provisioningState)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_NetworkSecurityGroupProperties.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
public abstract Builder securityRules(List<NetworkSecurityRule> securityRules);
|
||||||
|
|
||||||
|
public abstract Builder defaultSecurityRules(List<NetworkSecurityRule> securityRules);
|
||||||
|
|
||||||
|
public abstract Builder networkInterfaces(List<NetworkInterfaceCard> networkInterfaces);
|
||||||
|
|
||||||
|
public abstract Builder subnets(List<Subnet> subnets);
|
||||||
|
|
||||||
|
public abstract Builder resourceGuid(String resourceGuid);
|
||||||
|
|
||||||
|
public abstract Builder provisioningState(String provisioningState);
|
||||||
|
|
||||||
|
public abstract NetworkSecurityGroupProperties build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.domain;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.json.SerializedNames;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class NetworkSecurityRule {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String etag();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract NetworkSecurityRuleProperties properties();
|
||||||
|
|
||||||
|
@SerializedNames({"name", "id", "etag", "properties"})
|
||||||
|
public static NetworkSecurityRule create(final String name,
|
||||||
|
final String id,
|
||||||
|
final String etag,
|
||||||
|
final NetworkSecurityRuleProperties properties) {
|
||||||
|
return new AutoValue_NetworkSecurityRule(name, id, etag, properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.domain;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import org.jclouds.azurecompute.arm.util.GetEnumValue;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.json.SerializedNames;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class NetworkSecurityRuleProperties {
|
||||||
|
public enum Protocol {
|
||||||
|
// * is an allowed value, will handle in
|
||||||
|
Tcp("Tcp"),
|
||||||
|
Udp("Udp"),
|
||||||
|
All("*"),
|
||||||
|
UNRECOGNIZED("Unrecognized");
|
||||||
|
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
private Protocol(String label) { this.label = label; }
|
||||||
|
|
||||||
|
public static Protocol fromValue(final String text) {
|
||||||
|
if ("*".equals(text)) {
|
||||||
|
return All;
|
||||||
|
} else {
|
||||||
|
return (Protocol) GetEnumValue.fromValueOrDefault(text, Protocol.UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Access {
|
||||||
|
Allow,
|
||||||
|
Deny,
|
||||||
|
UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static Access fromValue(final String text) {
|
||||||
|
return (Access) GetEnumValue.fromValueOrDefault(text, Access.UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Direction {
|
||||||
|
Inbound,
|
||||||
|
Outbound,
|
||||||
|
UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static Direction fromValue(final String text) {
|
||||||
|
return (Direction) GetEnumValue.fromValueOrDefault(text, Direction.UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String description();
|
||||||
|
|
||||||
|
public abstract Protocol protocol();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String sourcePortRange();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String destinationPortRange();
|
||||||
|
|
||||||
|
public abstract String sourceAddressPrefix();
|
||||||
|
|
||||||
|
public abstract String destinationAddressPrefix();
|
||||||
|
|
||||||
|
public abstract Access access();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer priority();
|
||||||
|
|
||||||
|
public abstract Direction direction();
|
||||||
|
|
||||||
|
@SerializedNames({"description", "protocol", "sourcePortRange", "destinationPortRange", "sourceAddressPrefix", "destinationAddressPrefix", "access", "priority", "direction"})
|
||||||
|
public static NetworkSecurityRuleProperties create(final String description,
|
||||||
|
final Protocol protocol,
|
||||||
|
final String sourcePortRange,
|
||||||
|
final String destinationPortRange,
|
||||||
|
final String sourceAddressPrefix,
|
||||||
|
final String destinationAddressPrefix,
|
||||||
|
final Access access,
|
||||||
|
final Integer priority,
|
||||||
|
final Direction direction) {
|
||||||
|
return builder()
|
||||||
|
.description(description)
|
||||||
|
.protocol(protocol)
|
||||||
|
.sourcePortRange(sourcePortRange)
|
||||||
|
.destinationPortRange(destinationPortRange)
|
||||||
|
.sourceAddressPrefix(sourceAddressPrefix)
|
||||||
|
.destinationAddressPrefix(destinationAddressPrefix)
|
||||||
|
.access(access)
|
||||||
|
.priority(priority)
|
||||||
|
.direction(direction)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_NetworkSecurityRuleProperties.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
public abstract Builder description(String description);
|
||||||
|
|
||||||
|
public abstract Builder protocol(Protocol protocol);
|
||||||
|
|
||||||
|
public abstract Builder sourcePortRange(String sourcePortRange);
|
||||||
|
|
||||||
|
public abstract Builder destinationPortRange(String destinationPortRange);
|
||||||
|
|
||||||
|
public abstract Builder sourceAddressPrefix(String sourceAddressPrefix);
|
||||||
|
|
||||||
|
public abstract Builder destinationAddressPrefix(String sourceAddressPrefix);
|
||||||
|
|
||||||
|
public abstract Builder access(Access access);
|
||||||
|
|
||||||
|
public abstract Builder priority(Integer priority);
|
||||||
|
|
||||||
|
public abstract Builder direction(Direction direction);
|
||||||
|
|
||||||
|
public abstract NetworkSecurityRuleProperties build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.features;
|
||||||
|
|
||||||
|
import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
|
||||||
|
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroup;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroupProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.functions.URIParser;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.oauth.v2.filters.OAuthFilter;
|
||||||
|
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
|
import org.jclouds.rest.annotations.SelectJson;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
|
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/networkSecurityGroups")
|
||||||
|
|
||||||
|
@QueryParams(keys = "api-version", values = "2016-03-30")
|
||||||
|
@RequestFilters(OAuthFilter.class)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public interface NetworkSecurityGroupApi {
|
||||||
|
|
||||||
|
@Named("networksecuritygroup:list")
|
||||||
|
@GET
|
||||||
|
@SelectJson("value")
|
||||||
|
@Fallback(EmptyListOnNotFoundOr404.class)
|
||||||
|
List<NetworkSecurityGroup> list();
|
||||||
|
|
||||||
|
@Named("networksecuritygroup:delete")
|
||||||
|
@Path("/{networksecuritygroupname}")
|
||||||
|
@DELETE
|
||||||
|
@ResponseParser(URIParser.class)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
URI delete(@PathParam("networksecuritygroupname") String nsgName);
|
||||||
|
|
||||||
|
@Named("networksecuritygroup:createOrUpdate")
|
||||||
|
@Path("/{networksecuritygroupname}")
|
||||||
|
@PUT
|
||||||
|
@MapBinder(BindToJsonPayload.class)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
NetworkSecurityGroup createOrUpdate(@PathParam("networksecuritygroupname") String nsgName,
|
||||||
|
@PayloadParam("location") String location,
|
||||||
|
@Nullable @PayloadParam("tags") Map<String, String> tags,
|
||||||
|
@PayloadParam("properties")NetworkSecurityGroupProperties properties);
|
||||||
|
|
||||||
|
@Named("networksecuritygroup:get")
|
||||||
|
@Path("/{networksecuritygroupname}")
|
||||||
|
@GET
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
NetworkSecurityGroup get(@PathParam("networksecuritygroupname") String nsgName);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.features;
|
||||||
|
|
||||||
|
import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
|
||||||
|
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRule;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.functions.URIParser;
|
||||||
|
import org.jclouds.oauth.v2.filters.OAuthFilter;
|
||||||
|
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
|
import org.jclouds.rest.annotations.SelectJson;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
|
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.util.List;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/networkSecurityGroups/{networksecuritygroup}")
|
||||||
|
|
||||||
|
@QueryParams(keys = "api-version", values = "2016-03-30")
|
||||||
|
@RequestFilters(OAuthFilter.class)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public interface NetworkSecurityRuleApi {
|
||||||
|
@Named("networksecurityrule:createOrUpdate")
|
||||||
|
@Path("/securityRules/{networksecurityrulename}")
|
||||||
|
@PUT
|
||||||
|
@MapBinder(BindToJsonPayload.class)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
NetworkSecurityRule createOrUpdate(@PathParam("networksecurityrulename") String ruleName,
|
||||||
|
@PayloadParam("properties") NetworkSecurityRuleProperties properties);
|
||||||
|
|
||||||
|
@Named("networksecurityrule:getDefaultRule")
|
||||||
|
@Path("/defaultSecurityRules/{networksecurityrulename}")
|
||||||
|
@GET
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
NetworkSecurityRule getDefaultRule(@PathParam("networksecurityrulename") String ruleName);
|
||||||
|
|
||||||
|
@Named("networksecurityrule:get")
|
||||||
|
@Path("/securityRules/{networksecurityrulename}")
|
||||||
|
@GET
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
NetworkSecurityRule get(@PathParam("networksecurityrulename") String ruleName);
|
||||||
|
|
||||||
|
@Named("networksecurityrule:delete")
|
||||||
|
@Path("/securityRules/{networksecurityrulename}")
|
||||||
|
@DELETE
|
||||||
|
@ResponseParser(URIParser.class)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
URI delete(@PathParam("networksecurityrulename") String ruleName);
|
||||||
|
|
||||||
|
@Named("networksecuritygroup:list")
|
||||||
|
@Path("/securityRules")
|
||||||
|
@GET
|
||||||
|
@SelectJson("value")
|
||||||
|
@Fallback(EmptyListOnNotFoundOr404.class)
|
||||||
|
List<NetworkSecurityRule> list();
|
||||||
|
|
||||||
|
@Named("networksecuritygroup:listDefaultRules")
|
||||||
|
@Path("/defaultSecurityRules")
|
||||||
|
@GET
|
||||||
|
@SelectJson("value")
|
||||||
|
@Fallback(EmptyListOnNotFoundOr404.class)
|
||||||
|
List<NetworkSecurityRule> listDefaultRules();
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.features;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroup;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroupProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRule;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties;
|
||||||
|
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Access;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Direction;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Protocol;
|
||||||
|
import org.jclouds.azurecompute.arm.functions.ParseJobStatus;
|
||||||
|
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
|
||||||
|
|
||||||
|
import org.jclouds.util.Predicates2;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.AssertJUnit.assertNull;
|
||||||
|
|
||||||
|
@Test(groups = "live", singleThreaded = true)
|
||||||
|
public class NetworkSecurityGroupApiLiveTest extends BaseAzureComputeApiLiveTest {
|
||||||
|
|
||||||
|
private String resourcegroup;
|
||||||
|
private static String DEFAULT_NSG_NAME = "testNetworkSecurityGroup";
|
||||||
|
|
||||||
|
private NetworkSecurityGroup createGroup() {
|
||||||
|
NetworkSecurityRule rule = NetworkSecurityRule.create("denyallout", null, null,
|
||||||
|
NetworkSecurityRuleProperties.builder()
|
||||||
|
.description("deny all out")
|
||||||
|
.protocol(Protocol.Tcp)
|
||||||
|
.sourcePortRange("*")
|
||||||
|
.destinationPortRange("*")
|
||||||
|
.sourceAddressPrefix("*")
|
||||||
|
.destinationAddressPrefix("*")
|
||||||
|
.access(Access.Deny)
|
||||||
|
.priority(4095)
|
||||||
|
.direction(Direction.Outbound)
|
||||||
|
.build());
|
||||||
|
ArrayList<NetworkSecurityRule> ruleList = new ArrayList<NetworkSecurityRule>();
|
||||||
|
ruleList.add(rule);
|
||||||
|
NetworkSecurityGroup nsg = NetworkSecurityGroup.create("samplensg", "westus", null,
|
||||||
|
NetworkSecurityGroupProperties.builder()
|
||||||
|
.securityRules(ruleList)
|
||||||
|
.build(),
|
||||||
|
null);
|
||||||
|
return nsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Override
|
||||||
|
public void setup() {
|
||||||
|
super.setup();
|
||||||
|
resourcegroup = getResourceGroupName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live")
|
||||||
|
public void deleteNetworkSecurityGroupDoesNotExist() {
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
URI uri = nsgApi.delete(DEFAULT_NSG_NAME);
|
||||||
|
assertNull(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "deleteNetworkSecurityGroupDoesNotExist")
|
||||||
|
public void createNetworkSecurityGroup() {
|
||||||
|
final NetworkSecurityGroup nsg = createGroup();
|
||||||
|
assertNotNull(nsg);
|
||||||
|
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
NetworkSecurityGroup result = nsgApi.createOrUpdate(DEFAULT_NSG_NAME,
|
||||||
|
nsg.location(),
|
||||||
|
nsg.tags(),
|
||||||
|
nsg.properties());
|
||||||
|
assertNotNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "createNetworkSecurityGroup")
|
||||||
|
public void listNetworkSecurityGroups() {
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
List<NetworkSecurityGroup> result = nsgApi.list();
|
||||||
|
|
||||||
|
// verify we have something
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(result.size(), 1);
|
||||||
|
|
||||||
|
// check that the nework security group matches the one we originally passed in
|
||||||
|
NetworkSecurityGroup original = createGroup();
|
||||||
|
NetworkSecurityGroup nsg = result.get(0);
|
||||||
|
assertEquals(original.name(), nsg.name());
|
||||||
|
assertEquals(original.location(), nsg.location());
|
||||||
|
assertEquals(original.tags(), nsg.tags());
|
||||||
|
|
||||||
|
// check the network security rule in the group
|
||||||
|
assertEquals(nsg.properties().securityRules().size(), 1);
|
||||||
|
NetworkSecurityRule originalRule = original.properties().securityRules().get(0);
|
||||||
|
NetworkSecurityRule nsgRule = nsg.properties().securityRules().get(0);
|
||||||
|
assertEquals(originalRule.name(), nsgRule.name());
|
||||||
|
assertTrue(originalRule.properties().equals(nsgRule.properties()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = {"listNetworkSecurityGroups", "getNetworkSecurityGroup"}, alwaysRun = true)
|
||||||
|
public void deleteNetworkSecurityGroup() {
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
URI uri = nsgApi.delete(DEFAULT_NSG_NAME);
|
||||||
|
if (uri != null) {
|
||||||
|
assertTrue(uri.toString().contains("api-version"));
|
||||||
|
assertTrue(uri.toString().contains("operationresults"));
|
||||||
|
|
||||||
|
boolean jobDone = Predicates2.retry(new Predicate<URI>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(URI uri) {
|
||||||
|
return ParseJobStatus.JobStatus.DONE == api.getJobApi().jobStatus(uri);
|
||||||
|
}
|
||||||
|
}, 60 * 2 * 1000 /* 2 minute timeout */).apply(uri);
|
||||||
|
assertTrue(jobDone, "delete operation did not complete in the configured timeout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "createNetworkSecurityGroup")
|
||||||
|
public void getNetworkSecurityGroup() {
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
NetworkSecurityGroup nsg = nsgApi.get(DEFAULT_NSG_NAME);
|
||||||
|
assertNotNull(nsg);
|
||||||
|
assertNotNull(nsg.etag());
|
||||||
|
assertEquals(nsg.name(), DEFAULT_NSG_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.features;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroup;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroupProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRule;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Protocol;
|
||||||
|
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Iterables.isEmpty;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
@Test(groups = "unit", testName = "NetworkSecurityGroupApiMockTest", singleThreaded = true)
|
||||||
|
public class NetworkSecurityGroupApiMockTest extends BaseAzureComputeApiMockTest {
|
||||||
|
private final String subscriptionid = "SUBSCRIPTIONID";
|
||||||
|
private final String resourcegroup = "myresourcegroup";
|
||||||
|
private final String apiVersion = "api-version=2016-03-30";
|
||||||
|
private static String DEFAULT_NSG_NAME = "testNetworkSecurityGroup";
|
||||||
|
|
||||||
|
private NetworkSecurityGroup createGroup() {
|
||||||
|
NetworkSecurityRule rule = NetworkSecurityRule.create("denyallout", null, null,
|
||||||
|
NetworkSecurityRuleProperties.builder()
|
||||||
|
.description("deny all out")
|
||||||
|
.protocol(Protocol.Tcp)
|
||||||
|
.sourcePortRange("*")
|
||||||
|
.destinationPortRange("*")
|
||||||
|
.sourceAddressPrefix("*")
|
||||||
|
.destinationAddressPrefix("*")
|
||||||
|
.access(NetworkSecurityRuleProperties.Access.Deny)
|
||||||
|
.priority(4095)
|
||||||
|
.direction(NetworkSecurityRuleProperties.Direction.Outbound)
|
||||||
|
.build());
|
||||||
|
ArrayList<NetworkSecurityRule> ruleList = new ArrayList<NetworkSecurityRule>();
|
||||||
|
ruleList.add(rule);
|
||||||
|
NetworkSecurityGroup nsg = NetworkSecurityGroup.create("samplensg", "westus", null,
|
||||||
|
NetworkSecurityGroupProperties.builder()
|
||||||
|
.securityRules(ruleList)
|
||||||
|
.build(),
|
||||||
|
null);
|
||||||
|
return nsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNetworkSecurityGroup() throws InterruptedException {
|
||||||
|
NetworkSecurityGroup nsg = createGroup();
|
||||||
|
|
||||||
|
server.enqueue(jsonResponse("/networksecuritygroupcreate.json").setResponseCode(200));
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
String json = String.format("{\"location\":\"%s\",\"properties\":%s}", "westus", new Gson().toJson(nsg.properties()));
|
||||||
|
NetworkSecurityGroup result = nsgApi.createOrUpdate(DEFAULT_NSG_NAME, "westus", null, nsg.properties());
|
||||||
|
assertSent(server, "PUT", path, json);
|
||||||
|
|
||||||
|
assertEquals(result.name(), DEFAULT_NSG_NAME);
|
||||||
|
assertEquals(result.location(), "westus");
|
||||||
|
assertEquals(result.properties().securityRules().size(), 1);
|
||||||
|
assertEquals(result.properties().securityRules().get(0).properties().protocol(), Protocol.Tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getNetworkSecurityGroup() throws InterruptedException {
|
||||||
|
NetworkSecurityGroup nsg = createGroup();
|
||||||
|
|
||||||
|
server.enqueue(jsonResponse("/networksecuritygroupget.json").setResponseCode(200));
|
||||||
|
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
NetworkSecurityGroup result = nsgApi.get(DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertEquals(result.name(), DEFAULT_NSG_NAME);
|
||||||
|
assertEquals(result.location(), "westus");
|
||||||
|
assertEquals(result.properties().securityRules().size(), 1);
|
||||||
|
assertEquals(result.properties().securityRules().get(0).properties().protocol(), Protocol.Tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getNetworkSecurityGroupReturns404() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
NetworkSecurityGroup result = nsgApi.get(DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void listNetworkSecurityGroups() throws InterruptedException {
|
||||||
|
server.enqueue(jsonResponse("/networksecuritygrouplist.json").setResponseCode(200));
|
||||||
|
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
List<NetworkSecurityGroup> result = nsgApi.list();
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups?%s", subscriptionid, resourcegroup, apiVersion);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertTrue(result.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void listNetworkSecurityGroupsReturns404() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
List<NetworkSecurityGroup> result = nsgApi.list();
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups?%s", subscriptionid, resourcegroup, apiVersion);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertTrue(isEmpty(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteNetworkSecurityGroup() throws InterruptedException {
|
||||||
|
server.enqueue(response202WithHeader());
|
||||||
|
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
URI uri = nsgApi.delete(DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
assertEquals(server.getRequestCount(), 1);
|
||||||
|
assertNotNull(uri);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
assertSent(server, "DELETE", path);
|
||||||
|
|
||||||
|
assertTrue(uri.toString().contains("api-version"));
|
||||||
|
assertTrue(uri.toString().contains("operationresults"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteNetworkSecurityGroupDoesNotExist() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
URI uri = nsgApi.delete(DEFAULT_NSG_NAME);
|
||||||
|
assertNull(uri);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
assertSent(server, "DELETE", path);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,217 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.features;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroup;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroupProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRule;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Access;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Direction;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Protocol;
|
||||||
|
import org.jclouds.azurecompute.arm.functions.ParseJobStatus;
|
||||||
|
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
|
||||||
|
|
||||||
|
import org.jclouds.util.Predicates2;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
|
@Test(groups = "live", singleThreaded = true)
|
||||||
|
public class NetworkSecurityRuleApiLiveTest extends BaseAzureComputeApiLiveTest {
|
||||||
|
|
||||||
|
private String resourcegroup;
|
||||||
|
private static String DEFAULT_NSG_NAME = "testNetworkSecurityGroup";
|
||||||
|
private static String UNKNOWN_RULE_NAME = "ruledoesntexist";
|
||||||
|
|
||||||
|
private NetworkSecurityGroup createGroup() {
|
||||||
|
NetworkSecurityRule rule = NetworkSecurityRule.create("denyallout", null, null,
|
||||||
|
NetworkSecurityRuleProperties.builder()
|
||||||
|
.description("deny all out")
|
||||||
|
.protocol(Protocol.Tcp)
|
||||||
|
.sourcePortRange("*")
|
||||||
|
.destinationPortRange("*")
|
||||||
|
.sourceAddressPrefix("*")
|
||||||
|
.destinationAddressPrefix("*")
|
||||||
|
.access(Access.Deny)
|
||||||
|
.priority(4095)
|
||||||
|
.direction(Direction.Outbound)
|
||||||
|
.build());
|
||||||
|
ArrayList<NetworkSecurityRule> ruleList = new ArrayList<NetworkSecurityRule>();
|
||||||
|
ruleList.add(rule);
|
||||||
|
NetworkSecurityGroup nsg = NetworkSecurityGroup.create("samplensg", "westus", null,
|
||||||
|
NetworkSecurityGroupProperties.builder()
|
||||||
|
.securityRules(ruleList)
|
||||||
|
.build(),
|
||||||
|
null);
|
||||||
|
return nsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NetworkSecurityRule createRule() {
|
||||||
|
NetworkSecurityRule rule = NetworkSecurityRule.create("allowalludpin", null, null,
|
||||||
|
NetworkSecurityRuleProperties.builder()
|
||||||
|
.description("allow all udp in")
|
||||||
|
.protocol(Protocol.Udp)
|
||||||
|
.sourcePortRange("*")
|
||||||
|
.destinationPortRange("*")
|
||||||
|
.sourceAddressPrefix("*")
|
||||||
|
.destinationAddressPrefix("*")
|
||||||
|
.access(Access.Allow)
|
||||||
|
.priority(4094)
|
||||||
|
.direction(Direction.Inbound)
|
||||||
|
.build());
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Override
|
||||||
|
public void setup() {
|
||||||
|
super.setup();
|
||||||
|
resourcegroup = getResourceGroupName();
|
||||||
|
|
||||||
|
// a network security group is needed
|
||||||
|
final NetworkSecurityGroup nsg = createGroup();
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
NetworkSecurityGroup result = nsgApi.createOrUpdate(DEFAULT_NSG_NAME,
|
||||||
|
nsg.location(),
|
||||||
|
nsg.tags(),
|
||||||
|
nsg.properties());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass(alwaysRun = true)
|
||||||
|
@Override
|
||||||
|
public void tearDown() {
|
||||||
|
// remove the security group we created
|
||||||
|
final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
|
||||||
|
URI uri = nsgApi.delete(DEFAULT_NSG_NAME);
|
||||||
|
if (uri != null) {
|
||||||
|
boolean jobDone = Predicates2.retry(new Predicate<URI>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(URI uri) {
|
||||||
|
return ParseJobStatus.JobStatus.DONE == api.getJobApi().jobStatus(uri);
|
||||||
|
}
|
||||||
|
}, 60 * 2 * 1000 /* 2 minute timeout */).apply(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live")
|
||||||
|
public void deleteNetworkSecurityRuleDoesNotExist() {
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
URI uri = ruleApi.delete(UNKNOWN_RULE_NAME);
|
||||||
|
assertNull(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "deleteNetworkSecurityRuleDoesNotExist")
|
||||||
|
public void createNetworkSecurityRule() {
|
||||||
|
final NetworkSecurityRule rule = createRule();
|
||||||
|
assertNotNull(rule);
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
NetworkSecurityRule result = ruleApi.createOrUpdate(rule.name(), rule.properties());
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(result.name(), rule.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "createNetworkSecurityRule")
|
||||||
|
public void getNetworkSecurityRule() {
|
||||||
|
final NetworkSecurityRule rule = createRule();
|
||||||
|
assertNotNull(rule);
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
NetworkSecurityRule result = ruleApi.get(rule.name());
|
||||||
|
assertNotNull(result);
|
||||||
|
assertNotNull(result.etag());
|
||||||
|
assertEquals(result.name(), rule.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "createNetworkSecurityRule")
|
||||||
|
public void getNetworkSecurityDefaultRule() {
|
||||||
|
String defaultRuleName = "AllowVnetInBound";
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
NetworkSecurityRule result = ruleApi.getDefaultRule(defaultRuleName);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertNotNull(result.etag());
|
||||||
|
assertEquals(result.name(), defaultRuleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "createNetworkSecurityRule")
|
||||||
|
public void listNetworkSecurityRules() {
|
||||||
|
final NetworkSecurityRule rule = createRule();
|
||||||
|
assertNotNull(rule);
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
List<NetworkSecurityRule> result = ruleApi.list();
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(result.size(), 2);
|
||||||
|
|
||||||
|
boolean rulePresent = Iterables.any(result, new Predicate<NetworkSecurityRule>() {
|
||||||
|
public boolean apply(NetworkSecurityRule input) {
|
||||||
|
return input.name().equals(rule.name());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assertTrue(rulePresent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "createNetworkSecurityRule")
|
||||||
|
public void listDefaultSecurityRules() {
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
List<NetworkSecurityRule> result = ruleApi.listDefaultRules();
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertTrue(result.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = {"listNetworkSecurityRules", "listDefaultSecurityRules", "getNetworkSecurityRule"}, alwaysRun = true)
|
||||||
|
public void deleteNetworkSecurityRule() {
|
||||||
|
final NetworkSecurityRule rule = createRule();
|
||||||
|
assertNotNull(rule);
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
URI uri = ruleApi.delete(rule.name());
|
||||||
|
if (uri != null) {
|
||||||
|
assertTrue(uri.toString().contains("api-version"));
|
||||||
|
assertTrue(uri.toString().contains("operationresults"));
|
||||||
|
|
||||||
|
boolean jobDone = Predicates2.retry(new Predicate<URI>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(URI uri) {
|
||||||
|
return ParseJobStatus.JobStatus.DONE == api.getJobApi().jobStatus(uri);
|
||||||
|
}
|
||||||
|
}, 60 * 2 * 1000 /* 2 minute timeout */).apply(uri);
|
||||||
|
assertTrue(jobDone, "delete operation did not complete in the configured timeout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,206 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.azurecompute.arm.features;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRule;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Protocol;
|
||||||
|
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Iterables.isEmpty;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
|
||||||
|
@Test(groups = "unit", testName = "NetworkSecurityRuleApiMockTest", singleThreaded = true)
|
||||||
|
public class NetworkSecurityRuleApiMockTest extends BaseAzureComputeApiMockTest {
|
||||||
|
private final String subscriptionid = "SUBSCRIPTIONID";
|
||||||
|
private final String resourcegroup = "myresourcegroup";
|
||||||
|
private final String apiVersion = "api-version=2016-03-30";
|
||||||
|
private static String DEFAULT_NSG_NAME = "testNetworkSecurityGroup";
|
||||||
|
|
||||||
|
private NetworkSecurityRule createRule() {
|
||||||
|
NetworkSecurityRule rule = NetworkSecurityRule.create("allowalludpin", null, null,
|
||||||
|
NetworkSecurityRuleProperties.builder()
|
||||||
|
.description("allow all udp in")
|
||||||
|
.protocol(Protocol.Udp)
|
||||||
|
.sourcePortRange("*")
|
||||||
|
.destinationPortRange("*")
|
||||||
|
.sourceAddressPrefix("*")
|
||||||
|
.destinationAddressPrefix("*")
|
||||||
|
.access(NetworkSecurityRuleProperties.Access.Allow)
|
||||||
|
.priority(4094)
|
||||||
|
.direction(NetworkSecurityRuleProperties.Direction.Inbound)
|
||||||
|
.build());
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNetworkSecurityRule() throws InterruptedException {
|
||||||
|
NetworkSecurityRule rule = createRule();
|
||||||
|
|
||||||
|
server.enqueue(jsonResponse("/networksecurityrulecreate.json").setResponseCode(200));
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, rule.name(), apiVersion);
|
||||||
|
NetworkSecurityRule result = ruleApi.createOrUpdate(rule.name(), rule.properties());
|
||||||
|
String json = String.format("{\"properties\":%s}", new Gson().toJson(rule.properties()));
|
||||||
|
|
||||||
|
assertSent(server, "PUT", path, json);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(result.name(), rule.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getNetworkSecurityRule() throws InterruptedException {
|
||||||
|
NetworkSecurityRule rule = createRule();
|
||||||
|
|
||||||
|
server.enqueue(jsonResponse("/networksecurityruleget.json").setResponseCode(200));
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, rule.name(), apiVersion);
|
||||||
|
NetworkSecurityRule result = ruleApi.get(rule.name());
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertEquals(result.name(), rule.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getNetworkSecurityRuleReturns404() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
|
||||||
|
String missingRuleName = "ruleismissing";
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, missingRuleName, apiVersion);
|
||||||
|
NetworkSecurityRule result = ruleApi.get(missingRuleName);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getNetworkSecurityDefaultRule() throws InterruptedException {
|
||||||
|
server.enqueue(jsonResponse("/networksecurityrulegetdefault.json").setResponseCode(200));
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
String ruleName = "AllowVnetInBound";
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/defaultSecurityRules/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, ruleName, apiVersion);
|
||||||
|
NetworkSecurityRule result = ruleApi.getDefaultRule(ruleName);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(result.name(), ruleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getNetworkSecurityDefaultRuleReturns404() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
|
||||||
|
String missingRuleName = "ruleismissing";
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/defaultSecurityRules/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, missingRuleName, apiVersion);
|
||||||
|
NetworkSecurityRule result = ruleApi.getDefaultRule(missingRuleName);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void listNetworkSecurityRules() throws InterruptedException {
|
||||||
|
server.enqueue(jsonResponse("/networksecurityrulelist.json").setResponseCode(200));
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
List<NetworkSecurityRule> result = ruleApi.list();
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertTrue(result.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void listNetworkSecurityRulesReturns404() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
List<NetworkSecurityRule> result = ruleApi.list();
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertTrue(isEmpty(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void listNetworkSecurityDefaultRules() throws InterruptedException {
|
||||||
|
server.enqueue(jsonResponse("/networksecurityrulelistdefault.json").setResponseCode(200));
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/defaultSecurityRules?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
List<NetworkSecurityRule> result = ruleApi.listDefaultRules();
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertTrue(result.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void listNetworkSecurityDefaultRulesReturns404() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/defaultSecurityRules?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
|
||||||
|
List<NetworkSecurityRule> result = ruleApi.listDefaultRules();
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertTrue(isEmpty(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteNetworkSecurityRule() throws InterruptedException {
|
||||||
|
server.enqueue(response202WithHeader());
|
||||||
|
|
||||||
|
NetworkSecurityRule rule = createRule();
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
URI uri = ruleApi.delete(rule.name());
|
||||||
|
|
||||||
|
assertEquals(server.getRequestCount(), 1);
|
||||||
|
assertNotNull(uri);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, rule.name(), apiVersion);
|
||||||
|
assertSent(server, "DELETE", path);
|
||||||
|
|
||||||
|
assertTrue(uri.toString().contains("api-version"));
|
||||||
|
assertTrue(uri.toString().contains("operationresults"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteNetworkSecurityRuleDoesNotExist() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
|
||||||
|
final NetworkSecurityRuleApi ruleApi = api.getNetworkSecurityRuleApi(resourcegroup, DEFAULT_NSG_NAME);
|
||||||
|
String dummyname = "dummyrulename";
|
||||||
|
URI uri = ruleApi.delete(dummyname);
|
||||||
|
assertNull(uri);
|
||||||
|
|
||||||
|
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, dummyname, apiVersion);
|
||||||
|
assertSent(server, "DELETE", path);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,125 @@
|
||||||
|
{
|
||||||
|
"name": "testNetworkSecurityGroup",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup",
|
||||||
|
"etag": "W/\"1883271c-c55b-4f5b-a95a-b7415833e0ae\"",
|
||||||
|
"type": "Microsoft.Network/networkSecurityGroups",
|
||||||
|
"location": "westus",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"resourceGuid": "028cb30d-f97f-4dbe-9fea-705da1f383ca",
|
||||||
|
"securityRules": [{
|
||||||
|
"name": "denyallout",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/securityRules/denyallout",
|
||||||
|
"etag": "W/\"1883271c-c55b-4f5b-a95a-b7415833e0ae\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "deny all out",
|
||||||
|
"protocol": "Tcp",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 4095,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"defaultSecurityRules": [{
|
||||||
|
"name": "AllowVnetInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetInBound",
|
||||||
|
"etag": "W/\"1883271c-c55b-4f5b-a95a-b7415833e0ae\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "Allow inbound traffic from all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowAzureLoadBalancerInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowAzureLoadBalancerInBound",
|
||||||
|
"etag": "W/\"1883271c-c55b-4f5b-a95a-b7415833e0ae\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "Allow inbound traffic from azure load balancer",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "AzureLoadBalancer",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65001,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "DenyAllInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/DenyAllInBound",
|
||||||
|
"etag": "W/\"1883271c-c55b-4f5b-a95a-b7415833e0ae\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "Deny all inbound traffic",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 65500,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowVnetOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetOutBound",
|
||||||
|
"etag": "W/\"1883271c-c55b-4f5b-a95a-b7415833e0ae\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "Allow outbound traffic from all VMs to all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowInternetOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowInternetOutBound",
|
||||||
|
"etag": "W/\"1883271c-c55b-4f5b-a95a-b7415833e0ae\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "Allow outbound traffic from all VMs to Internet",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "Internet",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65001,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "DenyAllOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/DenyAllOutBound",
|
||||||
|
"etag": "W/\"1883271c-c55b-4f5b-a95a-b7415833e0ae\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "Deny all outbound traffic",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 65500,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,125 @@
|
||||||
|
{
|
||||||
|
"name": "testNetworkSecurityGroup",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"type": "Microsoft.Network/networkSecurityGroups",
|
||||||
|
"location": "westus",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"resourceGuid": "028cb30d-f97f-4dbe-9fea-705da1f383ca",
|
||||||
|
"securityRules": [{
|
||||||
|
"name": "denyallout",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/securityRules/denyallout",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "deny all out",
|
||||||
|
"protocol": "Tcp",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 4095,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"defaultSecurityRules": [{
|
||||||
|
"name": "AllowVnetInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetInBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow inbound traffic from all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowAzureLoadBalancerInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowAzureLoadBalancerInBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow inbound traffic from azure load balancer",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "AzureLoadBalancer",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65001,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "DenyAllInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/DenyAllInBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Deny all inbound traffic",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 65500,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowVnetOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetOutBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow outbound traffic from all VMs to all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowInternetOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowInternetOutBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow outbound traffic from all VMs to Internet",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "Internet",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65001,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "DenyAllOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/DenyAllOutBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Deny all outbound traffic",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 65500,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,127 @@
|
||||||
|
{
|
||||||
|
"value": [{
|
||||||
|
"name": "testNetworkSecurityGroup",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"type": "Microsoft.Network/networkSecurityGroups",
|
||||||
|
"location": "westus",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"resourceGuid": "028cb30d-f97f-4dbe-9fea-705da1f383ca",
|
||||||
|
"securityRules": [{
|
||||||
|
"name": "denyallout",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/securityRules/denyallout",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "deny all out",
|
||||||
|
"protocol": "Tcp",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 4095,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"defaultSecurityRules": [{
|
||||||
|
"name": "AllowVnetInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetInBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow inbound traffic from all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowAzureLoadBalancerInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowAzureLoadBalancerInBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow inbound traffic from azure load balancer",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "AzureLoadBalancer",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65001,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "DenyAllInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/DenyAllInBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Deny all inbound traffic",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 65500,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowVnetOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetOutBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow outbound traffic from all VMs to all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowInternetOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowInternetOutBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow outbound traffic from all VMs to Internet",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "Internet",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65001,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "DenyAllOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims947groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/DenyAllOutBound",
|
||||||
|
"etag": "W/\"14e288e4-5d9b-48cf-89c4-b532b59d71de\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Deny all outbound traffic",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 65500,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "allowalludpin",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/securityRules/allowalludpin",
|
||||||
|
"etag": "W/\"d9b6cda9-3873-445d-bc70-cd9c13f87ba7\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "allow all udp in",
|
||||||
|
"protocol": "Udp",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 4094,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "allowalludpin",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/securityRules/allowalludpin",
|
||||||
|
"etag": "W/\"d9b6cda9-3873-445d-bc70-cd9c13f87ba7\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"description": "allow all udp in",
|
||||||
|
"protocol": "Udp",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 4094,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "AllowVnetInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims741groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetInBound",
|
||||||
|
"etag": "W/\"23efab91-398a-4984-a9a7-281af38f6538\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow inbound traffic from all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"value": [{
|
||||||
|
"name": "denyallout",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/securityRules/denyallout",
|
||||||
|
"etag": "W/\"409ae6c7-fbe1-4bc4-aadb-c1d8330844d2\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "deny all out",
|
||||||
|
"protocol": "Tcp",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 4095,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "allowalludpin",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/securityRules/allowalludpin",
|
||||||
|
"etag": "W/\"409ae6c7-fbe1-4bc4-aadb-c1d8330844d2\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "allow all udp in",
|
||||||
|
"protocol": "Udp",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 4094,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
{
|
||||||
|
"value": [{
|
||||||
|
"name": "AllowVnetInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetInBound",
|
||||||
|
"etag": "W/\"409ae6c7-fbe1-4bc4-aadb-c1d8330844d2\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow inbound traffic from all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowAzureLoadBalancerInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowAzureLoadBalancerInBound",
|
||||||
|
"etag": "W/\"409ae6c7-fbe1-4bc4-aadb-c1d8330844d2\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow inbound traffic from azure load balancer",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "AzureLoadBalancer",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65001,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "DenyAllInBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/DenyAllInBound",
|
||||||
|
"etag": "W/\"409ae6c7-fbe1-4bc4-aadb-c1d8330844d2\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Deny all inbound traffic",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 65500,
|
||||||
|
"direction": "Inbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowVnetOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowVnetOutBound",
|
||||||
|
"etag": "W/\"409ae6c7-fbe1-4bc4-aadb-c1d8330844d2\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow outbound traffic from all VMs to all VMs in VNET",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "VirtualNetwork",
|
||||||
|
"destinationAddressPrefix": "VirtualNetwork",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65000,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "AllowInternetOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/AllowInternetOutBound",
|
||||||
|
"etag": "W/\"409ae6c7-fbe1-4bc4-aadb-c1d8330844d2\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Allow outbound traffic from all VMs to Internet",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "Internet",
|
||||||
|
"access": "Allow",
|
||||||
|
"priority": 65001,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "DenyAllOutBound",
|
||||||
|
"id": "/subscriptions/e43b3d9c-f839-48a8-b0fb-691aee6f1e4d/resourceGroups/jims859groupjclouds/providers/Microsoft.Network/networkSecurityGroups/testNetworkSecurityGroup/defaultSecurityRules/DenyAllOutBound",
|
||||||
|
"etag": "W/\"409ae6c7-fbe1-4bc4-aadb-c1d8330844d2\"",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Succeeded",
|
||||||
|
"description": "Deny all outbound traffic",
|
||||||
|
"protocol": "*",
|
||||||
|
"sourcePortRange": "*",
|
||||||
|
"destinationPortRange": "*",
|
||||||
|
"sourceAddressPrefix": "*",
|
||||||
|
"destinationAddressPrefix": "*",
|
||||||
|
"access": "Deny",
|
||||||
|
"priority": 65500,
|
||||||
|
"direction": "Outbound"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
Loading…
Reference in New Issue