Explorar el Código

define constants for service types

abhishek9686 hace 9 meses
padre
commit
0f3b3ac0d2
Se han modificado 3 ficheros con 27 adiciones y 11 borrados
  1. 6 6
      controllers/acls.go
  2. 9 5
      logic/acls.go
  3. 12 0
      models/acl.go

+ 6 - 6
controllers/acls.go

@@ -54,14 +54,14 @@ func aclPolicyTypes(w http.ResponseWriter, r *http.Request) {
 		},
 		ProtocolTypes: []models.ProtocolType{
 			{
-				Name: "HTTP",
+				Name: models.Http,
 				AllowedProtocols: []models.Protocol{
 					models.TCP,
 				},
 				PortRange: "80",
 			},
 			{
-				Name: "HTTPS",
+				Name: models.Https,
 				AllowedProtocols: []models.Protocol{
 					models.TCP,
 				},
@@ -89,28 +89,28 @@ func aclPolicyTypes(w http.ResponseWriter, r *http.Request) {
 			// 	PortRange: "53",
 			// },
 			{
-				Name: "All TCP",
+				Name: models.AllTCP,
 				AllowedProtocols: []models.Protocol{
 					models.TCP,
 				},
 				PortRange: "All ports",
 			},
 			{
-				Name: "All UDP",
+				Name: models.AllUDP,
 				AllowedProtocols: []models.Protocol{
 					models.UDP,
 				},
 				PortRange: "All ports",
 			},
 			{
-				Name: "ICMP",
+				Name: models.ICMPService,
 				AllowedProtocols: []models.Protocol{
 					models.ICMP,
 				},
 				PortRange: "",
 			},
 			{
-				Name: "Custom",
+				Name: models.Custom,
 				AllowedProtocols: []models.Protocol{
 					models.UDP,
 					models.TCP,

+ 9 - 5
logic/acls.go

@@ -25,16 +25,18 @@ func MigrateDefaulAclPolicies(netID models.NetworkID) {
 	}
 	acl, err := GetAcl(fmt.Sprintf("%s.%s", netID, "all-nodes"))
 	if err == nil {
-		if acl.Proto.String() == "" {
-			acl.Proto = models.ALL
-			acl.Port = []string{}
-			UpsertAcl(acl)
-		}
+		//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)
 		}
@@ -43,6 +45,7 @@ func MigrateDefaulAclPolicies(netID models.NetworkID) {
 	if err == nil {
 		if acl.Proto.String() == "" {
 			acl.Proto = models.ALL
+			acl.ServiceType = models.Custom
 			acl.Port = []string{}
 			UpsertAcl(acl)
 		}
@@ -341,6 +344,7 @@ func UpdateAcl(newAcl, acl models.Acl) error {
 		acl.AllowedDirection = newAcl.AllowedDirection
 		acl.Port = newAcl.Port
 		acl.Proto = newAcl.Proto
+		acl.ServiceType = newAcl.ServiceType
 	}
 	acl.Enabled = newAcl.Enabled
 	d, err := json.Marshal(acl)

+ 12 - 0
models/acl.go

@@ -25,6 +25,17 @@ const (
 	ICMP Protocol = "icmp"
 )
 
+type ServiceType string
+
+const (
+	Http        = "HTTP"
+	Https       = "HTTPS"
+	AllTCP      = "All TCP"
+	AllUDP      = "All UDP"
+	ICMPService = "ICMP"
+	Custom      = "Custom"
+)
+
 func (p Protocol) String() string {
 	return string(p)
 }
@@ -75,6 +86,7 @@ type Acl struct {
 	Src              []AclPolicyTag          `json:"src_type"`
 	Dst              []AclPolicyTag          `json:"dst_type"`
 	Proto            Protocol                `json:"protocol"` // tcp, udp, etc.
+	ServiceType      string                  `json:"type"`
 	Port             []string                `json:"ports"`
 	AllowedDirection AllowedTrafficDirection `json:"allowed_traffic_direction"`
 	Enabled          bool                    `json:"enabled"`