瀏覽代碼

set Acl DB crud

abhishek9686 11 月之前
父節點
當前提交
e258f12ecb
共有 3 個文件被更改,包括 56 次插入8 次删除
  1. 2 0
      database/database.go
  2. 40 0
      logic/acls.go
  3. 14 8
      models/acl.go

+ 2 - 0
database/database.go

@@ -47,6 +47,8 @@ const (
 	GENERATED_TABLE_NAME = "generated"
 	// NODE_ACLS_TABLE_NAME - stores the node ACL rules
 	NODE_ACLS_TABLE_NAME = "nodeacls"
+	// ACLS_TABLE_NAME - table for acls v2
+	ACLS_TABLE_NAME = "acls"
 	// SSO_STATE_CACHE - holds sso session information for OAuth2 sign-ins
 	SSO_STATE_CACHE = "ssostatecache"
 	// METRICS_TABLE_NAME - stores network metrics

+ 40 - 0
logic/acls.go

@@ -0,0 +1,40 @@
+package logic
+
+import (
+	"encoding/json"
+
+	"github.com/gravitl/netmaker/database"
+	"github.com/gravitl/netmaker/models"
+)
+
+// Create - creates acl policy
+func Create(a models.Acl) error {
+	d, err := json.Marshal(a)
+	if err != nil {
+		return err
+	}
+	return database.Insert(a.ID.String(), string(d), database.ACLS_TABLE_NAME)
+}
+
+// Delete - deletes acl policy
+func Delete(a models.Acl) error {
+	return database.DeleteRecord(database.ACLS_TABLE_NAME, a.ID.String())
+}
+
+// List - lists all acl policies
+func List(a models.Acl) ([]models.Acl, error) {
+	data, err := database.FetchRecords(database.TAG_TABLE_NAME)
+	if err != nil && !database.IsEmptyRecord(err) {
+		return []models.Acl{}, err
+	}
+	acls := []models.Acl{}
+	for _, dataI := range data {
+		acl := models.Acl{}
+		err := json.Unmarshal([]byte(dataI), &acl)
+		if err != nil {
+			continue
+		}
+		acls = append(acls, acl)
+	}
+	return acls, nil
+}

+ 14 - 8
models/acl.go

@@ -1,7 +1,8 @@
 package models
 
-type SrcType string
-type DstType string
+import (
+	"github.com/google/uuid"
+)
 
 // AllowedTrafficDirection - allowed direction of traffic
 type AllowedTrafficDirection int
@@ -13,15 +14,20 @@ const (
 	TrafficDirectionBi
 )
 
-const (
-	SrcUser SrcType = "user"
-	SrcHost SrcType = "host"
+type AclPolicyType string
 
-	DstHost DstType = "host"
+const (
+	UserPolicy   AclPolicyType = "user-policy"
+	DevicePolicy AclPolicyType = "device-policy"
 )
 
 type Acl struct {
-	Src              SrcType                 `json:"src_type"`
-	Dst              DstType                 `json:"dst_type"`
+	ID               uuid.UUID               `json:"id"`
+	Name             string                  `json:"name"`
+	NetworkID        NetworkID               `json:"network_id"`
+	RuleType         AclPolicyType           `json:"policy_type"`
+	Src              []string                `json:"src_type"`
+	Dst              []string                `json:"dst_type"`
 	AllowedDirection AllowedTrafficDirection `json:"allowed_traffic_direction"`
+	Enabled          bool                    `json:"enabled"`
 }