github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmd/authn/utils.go (about) 1 // Package authn is authentication server for AIStore. 2 /* 3 * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package main 6 7 import ( 8 "github.com/NVIDIA/aistore/api/authn" 9 ) 10 11 type bckACLList []*authn.BckACL 12 13 func (bckList bckACLList) updated(bckACL *authn.BckACL) bool { 14 for _, acl := range bckList { 15 if acl.Bck.Equal(&bckACL.Bck) { 16 acl.Access = bckACL.Access 17 return true 18 } 19 } 20 return false 21 } 22 23 type cluACLList []*authn.CluACL 24 25 func (cluList cluACLList) updated(cluACL *authn.CluACL) bool { 26 for _, acl := range cluList { 27 if acl.ID == cluACL.ID { 28 acl.Access = cluACL.Access 29 return true 30 } 31 } 32 return false 33 } 34 35 // mergeBckACLs appends bucket ACLs from fromACLs which are not in toACL. 36 // If a bucket ACL is already in the list, its persmissions are updated. 37 // If cluIDFlt is set, only ACLs for buckets of the cluster with this ID are appended. 38 func mergeBckACLs(toACLs, fromACLs bckACLList, cluIDFlt string) []*authn.BckACL { 39 for _, n := range fromACLs { 40 if cluIDFlt != "" && n.Bck.Ns.UUID != cluIDFlt { 41 continue 42 } 43 if !toACLs.updated(n) { 44 toACLs = append(toACLs, n) 45 } 46 } 47 return toACLs 48 } 49 50 // mergeClusterACLs appends cluster ACLs from fromACLs which are not in toACL. 51 // If a cluster ACL is already in the list, its persmissions are updated. 52 // If cluIDFlt is set, only ACLs for cluster with this ID are appended. 53 func mergeClusterACLs(toACLs, fromACLs cluACLList, cluIDFlt string) []*authn.CluACL { 54 for _, n := range fromACLs { 55 if cluIDFlt != "" && cluIDFlt != n.ID { 56 continue 57 } 58 if !toACLs.updated(n) { 59 toACLs = append(toACLs, n) 60 } 61 } 62 return toACLs 63 }