Skip to content

Commit

Permalink
Merge branch 'develop' into NET-1778
Browse files Browse the repository at this point in the history
  • Loading branch information
yabinma authored Dec 4, 2024
2 parents 553b055 + 5cb49e3 commit 73f7354
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion controllers/acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func getAcls(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
acls, err := logic.ListAcls(models.NetworkID(netID))
acls, err := logic.ListAclsByNetwork(models.NetworkID(netID))
if err != nil {
logger.Log(0, r.Header.Get("user"), "failed to get all network acl entries: ", err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
Expand Down
18 changes: 9 additions & 9 deletions logic/acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func CreateDefaultAclNetworkPolicies(netID models.NetworkID) {
if netID.String() == "" {
return
}
_, _ = ListAcls(netID)
_, _ = ListAclsByNetwork(netID)
if !IsAclExists(fmt.Sprintf("%s.%s", netID, "all-nodes")) {
defaultDeviceAcl := models.Acl{
ID: fmt.Sprintf("%s.%s", netID, "all-nodes"),
Expand Down Expand Up @@ -106,7 +106,7 @@ func CreateDefaultAclNetworkPolicies(netID models.NetworkID) {

// DeleteDefaultNetworkPolicies - deletes all default network acl policies
func DeleteDefaultNetworkPolicies(netId models.NetworkID) {
acls, _ := ListAcls(netId)
acls, _ := ListAclsByNetwork(netId)
for _, acl := range acls {
if acl.NetworkID == netId && acl.Default {
DeleteAcl(acl)
Expand Down Expand Up @@ -353,7 +353,7 @@ func GetDefaultPolicy(netID models.NetworkID, ruleType models.AclPolicyType) (mo
srcMap = nil
dstMap = nil
}()
policies, _ := ListAcls(netID)
policies, _ := ListAclsByNetwork(netID)
for _, policy := range policies {
if !policy.Enabled {
continue
Expand All @@ -373,7 +373,7 @@ func GetDefaultPolicy(netID models.NetworkID, ruleType models.AclPolicyType) (mo
return acl, nil
}

func listAcls() (acls []models.Acl) {
func ListAcls() (acls []models.Acl) {
if servercfg.CacheEnabled() && len(aclCacheMap) > 0 {
return listAclFromCache()
}
Expand All @@ -399,7 +399,7 @@ func listAcls() (acls []models.Acl) {

// ListUserPolicies - lists all acl policies enforced on an user
func ListUserPolicies(u models.User) []models.Acl {
allAcls := listAcls()
allAcls := ListAcls()
userAcls := []models.Acl{}
for _, acl := range allAcls {

Expand All @@ -424,7 +424,7 @@ func ListUserPolicies(u models.User) []models.Acl {

// listPoliciesOfUser - lists all user acl policies applied to user in an network
func listPoliciesOfUser(user models.User, netID models.NetworkID) []models.Acl {
allAcls := listAcls()
allAcls := ListAcls()
userAcls := []models.Acl{}
for _, acl := range allAcls {
if acl.NetworkID == netID && acl.RuleType == models.UserPolicy {
Expand Down Expand Up @@ -453,7 +453,7 @@ func listPoliciesOfUser(user models.User, netID models.NetworkID) []models.Acl {

// listDevicePolicies - lists all device policies in a network
func listDevicePolicies(netID models.NetworkID) []models.Acl {
allAcls := listAcls()
allAcls := ListAcls()
deviceAcls := []models.Acl{}
for _, acl := range allAcls {
if acl.NetworkID == netID && acl.RuleType == models.DevicePolicy {
Expand All @@ -464,9 +464,9 @@ func listDevicePolicies(netID models.NetworkID) []models.Acl {
}

// ListAcls - lists all acl policies
func ListAcls(netID models.NetworkID) ([]models.Acl, error) {
func ListAclsByNetwork(netID models.NetworkID) ([]models.Acl, error) {

allAcls := listAcls()
allAcls := ListAcls()
netAcls := []models.Acl{}
for _, acl := range allAcls {
if acl.NetworkID == netID {
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ func initialize() { // Client Mode Prereq Check
logger.FatalLog("Error connecting to database: ", err.Error())
}
logger.Log(0, "database successfully connected")

//initialize cache
_, _ = logic.GetNetworks()
_, _ = logic.GetAllNodes()
_, _ = logic.GetAllHosts()
_, _ = logic.GetAllExtClients()
_ = logic.ListAcls()
_, _ = logic.GetAllEnrollmentKeys()

migrate.Run()

logic.SetJWTSecret()
Expand Down
2 changes: 0 additions & 2 deletions migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (

// Run - runs all migrations
func Run() {
_, _ = logic.GetAllNodes()
_, _ = logic.GetAllHosts()
updateEnrollmentKeys()
assignSuperAdmin()
createDefaultTagsAndPolicies()
Expand Down

0 comments on commit 73f7354

Please sign in to comment.