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

Merge branch '2-bugfix-cache-policy-result' into 'main'

Fix storing of policy result in cache

Closes #2

See merge request gaia-x/data-infrastructure-federation-services/tsa/policy!1
parents 72fc4a8c a7dbb4ab
No related branches found
Tags v1.2.2
No related merge requests found
Pipeline #53787 passed with stages
in 2 minutes and 18 seconds
......@@ -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")
}
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
// variable, then we'll return a custom response containing only the value of the empty variable
// without any mapping.
......@@ -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{
Result: result,
ETag: evaluationID,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment