Explorar el Código

NET-1784: Migrate All Policies (#3245)

* migrate all policies

* migrate all policies

* add acl policy type for any traffic

* use any service type for migration
Abhishek K hace 9 meses
padre
commit
7093373c77
Se han modificado 4 ficheros con 21 adiciones y 31 borrados
  1. 8 0
      controllers/acls.go
  2. 10 30
      logic/acls.go
  3. 2 1
      migrate/migrate.go
  4. 1 0
      models/acl.go

+ 8 - 0
controllers/acls.go

@@ -53,6 +53,14 @@ func aclPolicyTypes(w http.ResponseWriter, r *http.Request) {
 			// models.NetmakerSubNetRangeAClID,
 		},
 		ProtocolTypes: []models.ProtocolType{
+			{
+				Name: models.Any,
+				AllowedProtocols: []models.Protocol{
+					models.ALL,
+				},
+				PortRange:        "All ports",
+				AllowPortSetting: false,
+			},
 			{
 				Name: models.Http,
 				AllowedProtocols: []models.Protocol{

+ 10 - 30
logic/acls.go

@@ -18,37 +18,17 @@ var (
 	aclCacheMap   = make(map[string]models.Acl)
 )
 
-func MigrateDefaulAclPolicies(netID models.NetworkID) {
-	if netID.String() == "" {
-		return
-	}
-	acl, err := GetAcl(fmt.Sprintf("%s.%s", netID, "all-nodes"))
-	if err == nil {
-		//if acl.Proto.String() == "" {
-		acl.Proto = models.ALL
-		acl.ServiceType = models.Custom
-		acl.Port = []string{}
-		UpsertAcl(acl)
-		//}
-	}
-	acl, err = GetAcl(fmt.Sprintf("%s.%s", netID, "all-users"))
-	if err == nil {
-		//if acl.Proto.String() == "" {
-		acl.Proto = models.ALL
-		acl.ServiceType = models.Custom
-		acl.Port = []string{}
-		UpsertAcl(acl)
-		//}
-	}
-	acl, err = GetAcl(fmt.Sprintf("%s.%s", netID, "all-remote-access-gws"))
-	if err == nil {
-		//if acl.Proto.String() == "" {
-		acl.Proto = models.ALL
-		acl.ServiceType = models.Custom
-		acl.Port = []string{}
-		UpsertAcl(acl)
-		//}
+func MigrateAclPolicies() {
+	acls := ListAcls()
+	for _, acl := range acls {
+		if acl.Proto.String() == "" {
+			acl.Proto = models.ALL
+			acl.ServiceType = models.Any
+			acl.Port = []string{}
+			UpsertAcl(acl)
+		}
 	}
+
 }
 
 // CreateDefaultAclNetworkPolicies - create default acl network policies

+ 2 - 1
migrate/migrate.go

@@ -437,6 +437,7 @@ func createDefaultTagsAndPolicies() {
 	for _, network := range networks {
 		logic.CreateDefaultTags(models.NetworkID(network.NetID))
 		logic.CreateDefaultAclNetworkPolicies(models.NetworkID(network.NetID))
-		logic.MigrateDefaulAclPolicies(models.NetworkID(network.NetID))
+
 	}
+	logic.MigrateAclPolicies()
 }

+ 1 - 0
models/acl.go

@@ -34,6 +34,7 @@ const (
 	AllUDP      = "All UDP"
 	ICMPService = "ICMP"
 	Custom      = "Custom"
+	Any         = "Any"
 )
 
 func (p Protocol) String() string {