Skip to content
Snippets Groups Projects
Commit a7dbb4ab authored by Lyuben Penkovski's avatar Lyuben Penkovski
Browse files

Fix storing of policy result in cache

parent 72fc4a8c
No related branches found
No related tags found
No related merge requests found
...@@ -96,17 +96,6 @@ func (s *Service) Evaluate(ctx context.Context, req *policy.EvaluateRequest) (*p ...@@ -96,17 +96,6 @@ func (s *Service) Evaluate(ctx context.Context, req *policy.EvaluateRequest) (*p
return nil, errors.New("policy evaluation result expressions are empty") return nil, errors.New("policy evaluation result expressions are empty")
} }
jsonValue, err := json.Marshal(resultSet[0].Expressions[0].Value)
if err != nil {
logger.Error("error encoding result to json", zap.Error(err))
return nil, errors.New("error encoding result to json")
}
if err := s.cache.Set(ctx, evaluationID, "", "", jsonValue); err != nil {
logger.Error("error storing policy result in cache", zap.Error(err))
return nil, errors.New("error storing policy result in cache")
}
// If there is only a single result from the policy evaluation and it was assigned to an empty // If there is only a single result from the policy evaluation and it was assigned to an empty
// variable, then we'll return a custom response containing only the value of the empty variable // variable, then we'll return a custom response containing only the value of the empty variable
// without any mapping. // without any mapping.
...@@ -121,6 +110,17 @@ func (s *Service) Evaluate(ctx context.Context, req *policy.EvaluateRequest) (*p ...@@ -121,6 +110,17 @@ func (s *Service) Evaluate(ctx context.Context, req *policy.EvaluateRequest) (*p
} }
} }
jsonValue, err := json.Marshal(result)
if err != nil {
logger.Error("error encoding result to json", zap.Error(err))
return nil, errors.New("error encoding result to json")
}
if err := s.cache.Set(ctx, evaluationID, "", "", jsonValue); err != nil {
logger.Error("error storing policy result in cache", zap.Error(err))
return nil, errors.New("error storing policy result in cache")
}
return &policy.EvaluateResult{ return &policy.EvaluateResult{
Result: result, Result: result,
ETag: evaluationID, ETag: evaluationID,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment