diff --git a/ctrl/internal/infrastructure/store/in_memory_kms_store.go b/ctrl/internal/infrastructure/store/in_memory_kms_store.go index cd3e80f44fc49cf7f0d1dfdf3c298ef71fa28da6..d29679dc5932ef0cb4f49e75d133f02b328127c2 100644 --- a/ctrl/internal/infrastructure/store/in_memory_kms_store.go +++ b/ctrl/internal/infrastructure/store/in_memory_kms_store.go @@ -40,16 +40,20 @@ func (s *InMemoryKmsStore) Create(ctx context.Context, inputKms model.KMS) (mode _, span := s.tracer.Start(ctx, "Create KMS") defer span.End() + s.logger.Debugw("Creating KMS in store", + "kmsId", inputKms.Id.String(), + "kmsName", inputKms.Name) + s.dsMutex.Lock() defer s.dsMutex.Unlock() if _, kmsAlreadyExists := s.dataStore[inputKms.Id]; kmsAlreadyExists { - s.logger.Errorw("KMS already exists in database", + s.logger.Errorw("KMS already exists in store", "kmsId", inputKms.Id.String(), "kmsName", inputKms.Name) errorString := fmt.Sprintf( - "kms with id %s already exists in database", + "kms with id %s already exists in store", inputKms.Id.String(), ) @@ -58,6 +62,10 @@ func (s *InMemoryKmsStore) Create(ctx context.Context, inputKms model.KMS) (mode s.dataStore[inputKms.Id] = inputKms } + s.logger.Debugw("KMS created in store", + "kmsId", inputKms.Id.String(), + "kmsName", inputKms.Name) + return s.dataStore[inputKms.Id], nil } @@ -65,12 +73,15 @@ func (s *InMemoryKmsStore) Get(ctx context.Context, id uuid.UUID) (model.KMS, er _, span := s.tracer.Start(ctx, "Get KMS") defer span.End() + s.logger.Debugw("Getting KMS from store", + "kmsId", id.String()) + s.dsMutex.Lock() defer s.dsMutex.Unlock() kms, kmsExists := s.dataStore[id] if !kmsExists { - s.logger.Errorw("KMS not found in database", + s.logger.Errorw("KMS not found in store", "kmsId", id.String()) errorString := fmt.Sprintf("no kms found with id %s", id.String()) @@ -78,6 +89,10 @@ func (s *InMemoryKmsStore) Get(ctx context.Context, id uuid.UUID) (model.KMS, er return model.KMS{}, errors.New(errorString) } + s.logger.Debugw("KMS found in store", + "kmsId", kms.Id.String(), + "kmsName", kms.Name) + return kms, nil } @@ -85,6 +100,8 @@ func (s *InMemoryKmsStore) GetAll(ctx context.Context) ([]model.KMS, error) { _, span := s.tracer.Start(ctx, "GetAll KMS") defer span.End() + s.logger.Debugw("Getting all KMS from store") + s.dsMutex.Lock() defer s.dsMutex.Unlock() @@ -93,6 +110,9 @@ func (s *InMemoryKmsStore) GetAll(ctx context.Context) ([]model.KMS, error) { kmsList = append(kmsList, kms) } + s.logger.Debugw("Got all KMS from store", + "numberOfKMS", len(kmsList)) + return kmsList, nil } @@ -100,12 +120,16 @@ func (s *InMemoryKmsStore) Update(ctx context.Context, inputKms model.KMS) (mode _, span := s.tracer.Start(ctx, "Update KMS") defer span.End() + s.logger.Debugw("Updating KMS in store", + "kmsId", inputKms.Id.String(), + "kmsName", inputKms.Name) + s.dsMutex.Lock() defer s.dsMutex.Unlock() _, kmsExists := s.dataStore[inputKms.Id] if !kmsExists { - s.logger.Errorw("KMS not found in database", + s.logger.Errorw("KMS not found in store", "kmsId: ", inputKms.Id.String(), "kmsName: ", inputKms.Name) errorString := fmt.Sprintf("no kms found with id %s", inputKms.Id.String()) @@ -115,6 +139,10 @@ func (s *InMemoryKmsStore) Update(ctx context.Context, inputKms model.KMS) (mode s.dataStore[inputKms.Id] = inputKms + s.logger.Debugw("KMS updated in store", + "kmsId", inputKms.Id.String(), + "kmsName", inputKms.Name) + return s.dataStore[inputKms.Id], nil } @@ -122,12 +150,15 @@ func (s *InMemoryKmsStore) Delete(ctx context.Context, id uuid.UUID) error { _, span := s.tracer.Start(ctx, "Delete KMS") defer span.End() + s.logger.Debugw("Deleting KMS from store", + "kmsId", id.String()) + s.dsMutex.Lock() defer s.dsMutex.Unlock() _, kmsExists := s.dataStore[id] if !kmsExists { - s.logger.Errorw("KMS not found in database", + s.logger.Errorw("KMS not found in store", "kmsId: ", id.String()) errorString := fmt.Sprintf("no kms found with id %s", id.String()) @@ -136,5 +167,8 @@ func (s *InMemoryKmsStore) Delete(ctx context.Context, id uuid.UUID) error { delete(s.dataStore, id) + s.logger.Debugw("KMS deleted from store", + "kmsId", id.String()) + return nil }