mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-08-25 23:07:32 +00:00
Proof of concept: client-side logout
Signed-off-by: Margo Crawford <margaretc@vmware.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package cachefile implements the file format for session caches.
|
||||
@@ -152,6 +152,19 @@ func (c *sessionCache) lookup(key oidcclient.SessionCacheKey) *sessionEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// delete a cache entry by key. Returns whether it successfully deleted an entry.
|
||||
func (c *sessionCache) delete(key oidcclient.SessionCacheKey) bool {
|
||||
length := len(c.Sessions)
|
||||
for i := range c.Sessions {
|
||||
if reflect.DeepEqual(c.Sessions[i].Key, key) {
|
||||
c.Sessions[i] = c.Sessions[length-1]
|
||||
c.Sessions = c.Sessions[:length-1]
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// insert a cache entry.
|
||||
func (c *sessionCache) insert(entries ...sessionEntry) {
|
||||
c.Sessions = append(c.Sessions, entries...)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package filesession implements a simple YAML file-based login.sessionCache.
|
||||
@@ -113,6 +113,22 @@ func (c *Cache) PutToken(key oidcclient.SessionCacheKey, token *oidctypes.Token)
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteToken deletes the token from the session cache at the given cache cache key.
|
||||
// It returns whether it deleted a token.
|
||||
func (c *Cache) DeleteToken(key oidcclient.SessionCacheKey) bool {
|
||||
_, err := os.Stat(c.path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
// if the cache file doesn't exist there's no session info
|
||||
// to delete
|
||||
return false
|
||||
}
|
||||
deleted := false
|
||||
c.withCache(func(cache *sessionCache) {
|
||||
deleted = cache.delete(key)
|
||||
})
|
||||
return deleted
|
||||
}
|
||||
|
||||
// withCache is an internal helper which locks, reads the cache, processes/mutates it with the provided function, then
|
||||
// saves it back to the file.
|
||||
func (c *Cache) withCache(transact func(*sessionCache)) {
|
||||
|
||||
Reference in New Issue
Block a user