authorize: track session and service account access date (#3220)

* session: add accessed at date

* authorize: track session and service account access times

* Revert "databroker: add support for field masks on Put (#3210)"

This reverts commit 2dc778035d.

* add test

* fix data race in test

* add deadline for update

* track dropped accesses
This commit is contained in:
Caleb Doxsey 2022-03-31 09:19:04 -06:00 committed by GitHub
parent a243056cfa
commit 36f73fa6c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 474 additions and 67 deletions

2
internal/sets/sets.go Normal file
View file

@ -0,0 +1,2 @@
// Package sets contains set data structures.
package sets

View file

@ -0,0 +1,36 @@
package sets
// A SizeLimitedStringSet is a StringSet which is limited to a given size. Once
// the capacity is reached an element will be removed at random.
type SizeLimitedStringSet struct {
m map[string]struct{}
capacity int
}
// NewSizeLimitedStringSet create a new SizeLimitedStringSet.
func NewSizeLimitedStringSet(capacity int) *SizeLimitedStringSet {
return &SizeLimitedStringSet{
m: make(map[string]struct{}),
capacity: capacity,
}
}
// Add adds an element to the set.
func (s *SizeLimitedStringSet) Add(element string) {
s.m[element] = struct{}{}
for len(s.m) > s.capacity {
for k := range s.m {
delete(s.m, k)
break
}
}
}
// ForEach iterates over all the elements in the set.
func (s *SizeLimitedStringSet) ForEach(callback func(element string) bool) {
for k := range s.m {
if !callback(k) {
return
}
}
}