diff --git a/controllers/acls.go b/controllers/acls.go index f5bcad851..1bc2c61ca 100644 --- a/controllers/acls.go +++ b/controllers/acls.go @@ -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")) diff --git a/logic/acls.go b/logic/acls.go index 12e74229a..97b0f7415 100644 --- a/logic/acls.go +++ b/logic/acls.go @@ -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"), @@ -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) @@ -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 @@ -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() } @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/main.go b/main.go index 6cc217fbf..566d61cf9 100644 --- a/main.go +++ b/main.go @@ -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() diff --git a/migrate/migrate.go b/migrate/migrate.go index b4a866ab7..19e9232aa 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -20,8 +20,6 @@ import ( // Run - runs all migrations func Run() { - _, _ = logic.GetAllNodes() - _, _ = logic.GetAllHosts() updateEnrollmentKeys() assignSuperAdmin() createDefaultTagsAndPolicies()