github.com/cilium/cilium@v1.16.2/pkg/maps/authmap/fake/auth_map.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package fake 5 6 import ( 7 "github.com/cilium/ebpf" 8 9 "github.com/cilium/cilium/pkg/datapath/linux/utime" 10 "github.com/cilium/cilium/pkg/maps/authmap" 11 ) 12 13 type AuthKey = authmap.AuthKey 14 type AuthInfo = authmap.AuthInfo 15 16 type fakeAuthMap struct { 17 Entries map[AuthKey]AuthInfo 18 } 19 20 func NewFakeAuthMap() *fakeAuthMap { 21 return &fakeAuthMap{ 22 Entries: map[AuthKey]AuthInfo{}, 23 } 24 } 25 26 func (f fakeAuthMap) Lookup(key AuthKey) (AuthInfo, error) { 27 info, exists := f.Entries[key] 28 if exists { 29 return info, nil 30 } 31 return info, ebpf.ErrKeyNotExist 32 } 33 34 func (f fakeAuthMap) Update(key AuthKey, expiration utime.UTime) error { 35 f.Entries[key] = AuthInfo{Expiration: expiration} 36 return nil 37 } 38 39 func (f fakeAuthMap) Delete(key AuthKey) error { 40 delete(f.Entries, key) 41 return nil 42 } 43 44 func (f fakeAuthMap) IterateWithCallback(cb authmap.IterateCallback) error { 45 for key, info := range f.Entries { 46 cb(&key, &info) 47 } 48 return nil 49 } 50 51 func (f fakeAuthMap) MaxEntries() uint32 { 52 return 1 << 8 53 }