You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2018/03/29 08:06:55 UTC

[cloudstack] branch master updated: [CLOUDSTACK-10332] Users are not able to change/edit the protocol of an ACL rule (#2496)

This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new 36f4645  [CLOUDSTACK-10332] Users are not able to change/edit the protocol of an ACL rule (#2496)
36f4645 is described below

commit 36f4645154bae4b6c79b62d9df93cb94a3323255
Author: Rafael Weingärtner <ra...@gmail.com>
AuthorDate: Thu Mar 29 05:06:50 2018 -0300

    [CLOUDSTACK-10332] Users are not able to change/edit the protocol of an ACL rule (#2496)
    
    * [CLOUDSTACK-10332] Users are not able to change/edit the protocol of an ACL rule
    
    * Code formatting
---
 .../org/apache/cloudstack/api/ApiConstants.java    |  7 ++--
 .../user/network/UpdateNetworkACLItemCmd.java      |  6 ++++
 .../cloud/network/vpc/NetworkACLServiceImpl.java   | 23 +++++++------
 .../network/vpc/NetworkACLServiceImplTest.java     | 39 +++++++++++++++++++++-
 ui/scripts/vpc.js                                  |  2 +-
 5 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
index ac9406f..7825bb4 100644
--- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
@@ -309,7 +309,7 @@ public class ApiConstants {
     public static final String USERNAME = "username";
     public static final String USER_SECURITY_GROUP_LIST = "usersecuritygrouplist";
     public static final String USE_VIRTUAL_NETWORK = "usevirtualnetwork";
-    public static final String Update_IN_SEQUENCE ="updateinsequence";
+    public static final String Update_IN_SEQUENCE = "updateinsequence";
     public static final String VALUE = "value";
     public static final String VIRTUAL_MACHINE_ID = "virtualmachineid";
     public static final String VIRTUAL_MACHINE_IDS = "virtualmachineids";
@@ -453,6 +453,7 @@ public class ApiConstants {
     public static final String NSP_ID = "nspid";
     public static final String ACL_TYPE = "acltype";
     public static final String ACL_REASON = "reason";
+    public static final String ACL_RULE_PARTIAL_UPGRADE = "partialupgrade";
     public static final String SUBDOMAIN_ACCESS = "subdomainaccess";
     public static final String LOAD_BALANCER_DEVICE_ID = "lbdeviceid";
     public static final String LOAD_BALANCER_DEVICE_NAME = "lbdevicename";
@@ -707,14 +708,12 @@ public class ApiConstants {
             + " and just a plain ascii/utf8 representation of a hexadecimal string. If it is required to\n"
             + " use another algorithm the hexadecimal string is to be prefixed with a string of the form,\n"
             + " \"{<algorithm>}\", not including the double quotes. In this <algorithm> is the exact string\n"
-            + " representing the java supported algorithm, i.e. MD5 or SHA-256. Note that java does not\n"
-            + " contain an algorithm called SHA256 or one called sha-256, only SHA-256.";
+            + " representing the java supported algorithm, i.e. MD5 or SHA-256. Note that java does not\n" + " contain an algorithm called SHA256 or one called sha-256, only SHA-256.";
 
     public static final String HAS_ANNOTATION = "hasannotation";
     public static final String LAST_ANNOTATED = "lastannotated";
     public static final String LDAP_DOMAIN = "ldapdomain";
 
-
     public enum HostDetails {
         all, capacity, events, stats, min;
     }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java
index 1530239..1215f57 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java
@@ -79,6 +79,9 @@ public class UpdateNetworkACLItemCmd extends BaseAsyncCustomIdCmd {
     @Parameter(name = ApiConstants.ACL_REASON, type = CommandType.STRING, description = "A description indicating why the ACL rule is required.")
     private String reason;
 
+    @Parameter(name = ApiConstants.ACL_RULE_PARTIAL_UPGRADE, type = CommandType.BOOLEAN, required = false, description = "Indicates if the ACL rule is to be updated partially (merging the parameters sent with current configuration) or completely (disconsidering all of the current configurations). The default value is 'true'.")
+    private boolean partialUpgrade = true;
+
     // ///////////////////////////////////////////////////
     // ///////////////// Accessors ///////////////////////
     // ///////////////////////////////////////////////////
@@ -188,4 +191,7 @@ public class UpdateNetworkACLItemCmd extends BaseAsyncCustomIdCmd {
         }
     }
 
+    public boolean isPartialUpgrade() {
+        return partialUpgrade;
+    }
 }
diff --git a/server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java b/server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java
index bfa8428..5369ffa 100644
--- a/server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java
+++ b/server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java
@@ -829,6 +829,8 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
      *  We transfer the update information form {@link UpdateNetworkACLItemCmd} to the {@link NetworkACLItemVO} POJO passed as parameter.
      *  There is one validation performed here, which is regarding the number of the ACL. We will check if there is already an ACL rule with that number, and if this is the case an {@link InvalidParameterValueException} is thrown.
      *  All of the parameters in {@link UpdateNetworkACLItemCmd} that are not null will be set to their corresponding fields in {@link NetworkACLItemVO}.
+     *  If the parameter {@link UpdateNetworkACLItemCmd#isPartialUpgrade()} returns false, we will use null parameters, which will allow us to completely update the ACL rule.
+     *  However, the number and custom Uuid will never be set to null. Therefore, if it is not a partial upgrade, these values will remain the same.
      *
      *  We use {@link #validateAndCreateNetworkAclRuleAction(String)} when converting an action as {@link String} to its Enum corresponding value.
      */
@@ -841,38 +843,39 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
             }
             networkACLItemVo.setNumber(number);
         }
+        boolean isPartialUpgrade = updateNetworkACLItemCmd.isPartialUpgrade();
 
         Integer sourcePortStart = updateNetworkACLItemCmd.getSourcePortStart();
-        if (sourcePortStart != null) {
+        if (!isPartialUpgrade || sourcePortStart != null) {
             networkACLItemVo.setSourcePortStart(sourcePortStart);
         }
         Integer sourcePortEnd = updateNetworkACLItemCmd.getSourcePortEnd();
-        if (sourcePortEnd != null) {
+        if (!isPartialUpgrade || sourcePortEnd != null) {
             networkACLItemVo.setSourcePortEnd(sourcePortEnd);
         }
         List<String> sourceCidrList = updateNetworkACLItemCmd.getSourceCidrList();
-        if (CollectionUtils.isNotEmpty(sourceCidrList)) {
+        if (!isPartialUpgrade || CollectionUtils.isNotEmpty(sourceCidrList)) {
             networkACLItemVo.setSourceCidrList(sourceCidrList);
         }
         String protocol = updateNetworkACLItemCmd.getProtocol();
-        if (StringUtils.isNotBlank(protocol)) {
+        if (!isPartialUpgrade || StringUtils.isNotBlank(protocol)) {
             networkACLItemVo.setProtocol(protocol);
         }
         Integer icmpCode = updateNetworkACLItemCmd.getIcmpCode();
-        if (icmpCode != null) {
+        if (!isPartialUpgrade || icmpCode != null) {
             networkACLItemVo.setIcmpCode(icmpCode);
         }
         Integer icmpType = updateNetworkACLItemCmd.getIcmpType();
-        if (icmpType != null) {
+        if (!isPartialUpgrade || icmpType != null) {
             networkACLItemVo.setIcmpType(icmpType);
         }
         String action = updateNetworkACLItemCmd.getAction();
-        if (StringUtils.isNotBlank(action)) {
+        if (!isPartialUpgrade || StringUtils.isNotBlank(action)) {
             Action aclRuleAction = validateAndCreateNetworkAclRuleAction(action);
             networkACLItemVo.setAction(aclRuleAction);
         }
         TrafficType trafficType = updateNetworkACLItemCmd.getTrafficType();
-        if (trafficType != null) {
+        if (!isPartialUpgrade || trafficType != null) {
             networkACLItemVo.setTrafficType(trafficType);
         }
         String customId = updateNetworkACLItemCmd.getCustomId();
@@ -880,11 +883,11 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
             networkACLItemVo.setUuid(customId);
         }
         boolean display = updateNetworkACLItemCmd.isDisplay();
-        if (display != networkACLItemVo.isDisplay()) {
+        if (!isPartialUpgrade || display != networkACLItemVo.isDisplay()) {
             networkACLItemVo.setDisplay(display);
         }
         String reason = updateNetworkACLItemCmd.getReason();
-        if (StringUtils.isNotBlank(reason)) {
+        if (!isPartialUpgrade || StringUtils.isNotBlank(reason)) {
             networkACLItemVo.setReason(reason);
         }
     }
diff --git a/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java b/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java
index ee7a474..ed8602b 100644
--- a/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java
+++ b/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java
@@ -700,7 +700,8 @@ public class NetworkACLServiceImplTest {
     }
 
     @Test
-    public void transferDataToNetworkAclRulePojoTestAllValuesNull() {
+    public void transferDataToNetworkAclRulePojoTestPartialUpgradeAllValuesNull() {
+        Mockito.when(updateNetworkACLItemCmdMock.isPartialUpgrade()).thenReturn(true);
         Mockito.when(updateNetworkACLItemCmdMock.getNumber()).thenReturn(null);
         Mockito.when(updateNetworkACLItemCmdMock.getSourcePortStart()).thenReturn(null);
         Mockito.when(updateNetworkACLItemCmdMock.getSourcePortEnd()).thenReturn(null);
@@ -734,6 +735,42 @@ public class NetworkACLServiceImplTest {
     }
 
     @Test
+    public void transferDataToNetworkAclRulePojoTestNotPartialUpgradeAllValuesNull() {
+        Mockito.when(updateNetworkACLItemCmdMock.isPartialUpgrade()).thenReturn(false);
+
+        Mockito.when(updateNetworkACLItemCmdMock.getNumber()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getSourcePortStart()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getSourcePortEnd()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getSourceCidrList()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getProtocol()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getIcmpCode()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getIcmpType()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getAction()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getTrafficType()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getCustomId()).thenReturn(null);
+        Mockito.when(updateNetworkACLItemCmdMock.getReason()).thenReturn(null);
+
+        Mockito.when(updateNetworkACLItemCmdMock.isDisplay()).thenReturn(false);
+        Mockito.when(networkAclItemVoMock.isDisplay()).thenReturn(false);
+
+        networkAclServiceImpl.transferDataToNetworkAclRulePojo(updateNetworkACLItemCmdMock, networkAclItemVoMock, networkAclMock);
+
+        Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setNumber(Mockito.anyInt());
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setSourcePortStart(Mockito.anyInt());
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setSourcePortEnd(Mockito.anyInt());
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setSourceCidrList(Mockito.anyListOf(String.class));
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setProtocol(Mockito.anyString());
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setIcmpCode(Mockito.anyInt());
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setIcmpType(Mockito.anyInt());
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setAction(Mockito.any(Action.class));
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setTrafficType(Mockito.any(TrafficType.class));
+        Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setUuid(Mockito.anyString());
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setReason(Mockito.anyString());
+        Mockito.verify(networkAclItemVoMock, Mockito.times(1)).setDisplay(Mockito.anyBoolean());
+        Mockito.verify(networkAclServiceImpl, Mockito.times(1)).validateAndCreateNetworkAclRuleAction(Mockito.anyString());
+    }
+
+    @Test
     public void transferDataToNetworkAclRulePojoTestAllValuesWithUpdateData() {
         Mockito.when(updateNetworkACLItemCmdMock.getNumber()).thenReturn(1);
         Mockito.when(updateNetworkACLItemCmdMock.getSourcePortStart()).thenReturn(23);
diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js
index dcf8e38..7eb589e 100644
--- a/ui/scripts/vpc.js
+++ b/ui/scripts/vpc.js
@@ -671,7 +671,7 @@
 
                         delete args.data.protocolnumber;
                     }
-
+                    data.partialupgrade = false;
                     $.ajax({
                         url: createURL('updateNetworkACLItem'),
                         data: data,

-- 
To stop receiving notification emails like this one, please contact
dahn@apache.org.