mirror of
https://github.com/gravitl/netmaker.git
synced 2026-04-22 16:07:11 +08:00
set Acl DB crud
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user