Skip to content
Snippets Groups Projects
Commit 06916ba9 authored by Neil-Jocelyn Schark's avatar Neil-Jocelyn Schark
Browse files

Resolve "Add more logging to InMemoryKmsStore"

parent 0db45a71
Branches
No related tags found
1 merge request!21Resolve "Add more logging to InMemoryKmsStore"
Pipeline #270341 passed
......@@ -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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment