Fix merge conflict upstream/resf

Signed-off-by: Mustafa Gezen <mustafa@ctrliq.com>
This commit is contained in:
Mustafa Gezen 2022-08-16 12:48:53 +02:00
parent 8ef874b5ae
commit 0a712673a7
Signed by untrusted user who does not match committer: mustafa
GPG Key ID: DCDF010D946438C1
2 changed files with 52 additions and 16 deletions

View File

@ -106,9 +106,11 @@ func (s *Server) importRpmKey(publicKey string) error {
// WarmGPGKey warms up a specific GPG key
// This involves shelling out to GPG to import the key
func (s *Server) WarmGPGKey(key string, armoredKey string, gpgKey *crypto.Key, db *models.Key) (*LoadedKey, error) {
s.keyImportLock.ReadLock(key)
defer s.keyImportLock.ReadUnlock(key)
cachedKey := s.keys[key]
// This means that the key is already loaded
// We need to delete and replace it
if cachedKey != nil {
return cachedKey, nil
}

View File

@ -57,6 +57,33 @@ import (
const TaskQueue = "keykeeper"
type MapStringLock struct {
*sync.RWMutex
m map[string]*sync.Mutex
}
func (m *MapStringLock) ReadLock(key string) {
m.RLock()
defer m.RUnlock()
if m.m[key] == nil {
m.Lock()
m.m[key] = &sync.Mutex{}
m.Unlock()
}
m.m[key].Lock()
}
func (m *MapStringLock) ReadUnlock(key string) {
m.RLock()
defer m.RUnlock()
if m.m[key] == nil {
m.Lock()
m.m[key] = &sync.Mutex{}
m.Unlock()
}
m.m[key].Unlock()
}
type Server struct {
keykeeperpb.UnimplementedKeykeeperServiceServer
@ -67,6 +94,7 @@ type Server struct {
temporal client.Client
stores map[string]store.Store
keys map[string]*LoadedKey
keyImportLock *MapStringLock
defaultStore string
}
@ -85,10 +113,16 @@ func NewServer(db peridotdb.Access, c client.Client) (*Server, error) {
log: logrus.New(),
db: db,
storage: storage,
worker: worker.New(c, TaskQueue, worker.Options{}),
worker: worker.New(c, TaskQueue, worker.Options{
DeadlockDetectionTimeout: 15 * time.Minute,
}),
temporal: c,
stores: map[string]store.Store{"awssm": sm},
keys: map[string]*LoadedKey{},
keyImportLock: &MapStringLock{
RWMutex: &sync.RWMutex{},
m: map[string]*sync.Mutex{},
},
defaultStore: "awssm",
}, nil
}