set Acl DB crud

This commit is contained in:
abhishek9686
2024-09-24 19:09:15 +04:00
parent 873d3ea8d8
commit e258f12ecb
3 changed files with 56 additions and 8 deletions
+2
View File
@@ -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
View File
@@ -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
View File
@@ -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"`
}