Skip to content

Commit

Permalink
return clone of map
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 committed Nov 4, 2024
1 parent e36eef4 commit 38cb4d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions logic/acls/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package acls

import (
"encoding/json"
"maps"
"sync"

"github.com/gravitl/netmaker/database"
Expand Down Expand Up @@ -133,7 +134,7 @@ func fetchACLContainer(containerID ContainerID) (ACLContainer, error) {
defer AclMutex.RUnlock()
if servercfg.CacheEnabled() {
if aclContainer, ok := fetchAclContainerFromCache(containerID); ok {
return aclContainer, nil
return maps.Clone(aclContainer), nil
}
}
aclJson, err := fetchACLContainerJson(ContainerID(containerID))
Expand All @@ -147,7 +148,7 @@ func fetchACLContainer(containerID ContainerID) (ACLContainer, error) {
if servercfg.CacheEnabled() {
storeAclContainerInCache(containerID, currentNetworkACL)
}
return currentNetworkACL, nil
return maps.Clone(currentNetworkACL), nil
}

// fetchACLContainerJson - fetch the current ACL of given container except in json string
Expand Down
7 changes: 3 additions & 4 deletions logic/acls/nodeacls/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ func AreNodesAllowed(networkID NetworkID, node1, node2 NodeID) bool {
}
var allowed bool
acls.AclMutex.Lock()
currNetAclCopy := maps.Clone(currentNetworkACL)
currNetworkACLNode1 := currNetAclCopy[acls.AclID(node1)]
currNetworkACLNode2 := currNetAclCopy[acls.AclID(node2)]
currNetworkACLNode1 := currentNetworkACL[acls.AclID(node1)]
currNetworkACLNode2 := currentNetworkACL[acls.AclID(node2)]
acls.AclMutex.Unlock()
allowed = currNetworkACLNode1.IsAllowed(acls.AclID(node2)) && currNetworkACLNode2.IsAllowed(acls.AclID(node1))
return allowed
Expand Down Expand Up @@ -69,5 +68,5 @@ func FetchAllACLs(networkID NetworkID) (acls.ACLContainer, error) {
if err != nil {
return nil, err
}
return currentNetworkACL, nil
return maps.Clone(currentNetworkACL), nil
}

0 comments on commit 38cb4d8

Please sign in to comment.