github.com/cilium/cilium@v1.16.2/pkg/auth/authmap.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package auth
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/cilium/cilium/pkg/identity"
    10  	"github.com/cilium/cilium/pkg/policy"
    11  	"github.com/cilium/cilium/pkg/time"
    12  )
    13  
    14  // authMap provides an abstraction for the BPF map "auth"
    15  type authMap interface {
    16  	Update(key authKey, info authInfo) error
    17  	Delete(key authKey) error
    18  	DeleteIf(predicate func(key authKey, info authInfo) bool) error
    19  	Get(key authKey) (authInfo, error)
    20  	All() (map[authKey]authInfo, error)
    21  	MaxEntries() uint32
    22  }
    23  
    24  type authMapCacher interface {
    25  	authMap
    26  	GetCacheInfo(key authKey) (authInfoCache, error)
    27  }
    28  
    29  type authKey struct {
    30  	localIdentity  identity.NumericIdentity
    31  	remoteIdentity identity.NumericIdentity
    32  	remoteNodeID   uint16
    33  	authType       policy.AuthType
    34  }
    35  
    36  func (r authKey) String() string {
    37  	return fmt.Sprintf("localIdentity=%d, remoteIdentity=%d, remoteNodeID=%d, authType=%s", r.localIdentity, r.remoteIdentity, r.remoteNodeID, r.authType)
    38  }
    39  
    40  type authInfo struct {
    41  	expiration time.Time
    42  }
    43  
    44  type authInfoCache struct {
    45  	authInfo
    46  	storedAt time.Time
    47  }
    48  
    49  func (r authInfo) String() string {
    50  	return fmt.Sprintf("expiration=%s", r.expiration)
    51  }