From 1a8ea0db4af4f6bc204360c1ad765628df89bf84 Mon Sep 17 00:00:00 2001
From: Yordan Kinkov <yordan.kinkov@vereign.com>
Date: Tue, 11 Oct 2022 10:21:44 +0300
Subject: [PATCH] #1 Rename TTL variable to cacheTTL

---
 internal/clients/policy/client.go        | 6 +++---
 internal/service/infohub/service.go      | 3 +--
 internal/service/infohub/service_test.go | 4 ++--
 internal/storage/storage.go              | 2 +-
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/internal/clients/policy/client.go b/internal/clients/policy/client.go
index c6b664a..651b31b 100644
--- a/internal/clients/policy/client.go
+++ b/internal/clients/policy/client.go
@@ -40,7 +40,7 @@ func New(addr string, opts ...ClientOption) *Client {
 // The policy is expected as a string path uniquely identifying the
 // policy that has to be evaluated. For example, with policy = `gaiax/didResolve/1.0`,
 // the client will do HTTP request to http://policyhost/policy/gaiax/didResolve/1.0/evaluation.
-func (c *Client) Evaluate(ctx context.Context, policy string, data interface{}, evaluationID string, ttl *int) ([]byte, error) {
+func (c *Client) Evaluate(ctx context.Context, policy string, data interface{}, evaluationID string, cacheTTL *int) ([]byte, error) {
 	uri := c.addr + "/policy/" + policy + "/evaluation"
 	policyURL, err := url.ParseRequestURI(uri)
 	if err != nil {
@@ -61,8 +61,8 @@ func (c *Client) Evaluate(ctx context.Context, policy string, data interface{},
 		req.Header.Set(headerEvaluationID, evaluationID)
 	}
 
-	if ttl != nil {
-		req.Header.Set(headerCacheTTL, strconv.Itoa(*ttl))
+	if cacheTTL != nil {
+		req.Header.Set(headerCacheTTL, strconv.Itoa(*cacheTTL))
 	}
 
 	resp, err := c.httpClient.Do(req.WithContext(ctx))
diff --git a/internal/service/infohub/service.go b/internal/service/infohub/service.go
index 1c38b6a..f21a0ef 100644
--- a/internal/service/infohub/service.go
+++ b/internal/service/infohub/service.go
@@ -3,7 +3,6 @@ package infohub
 import (
 	"context"
 	"encoding/json"
-
 	"github.com/google/uuid"
 	"github.com/hyperledger/aries-framework-go/pkg/doc/verifiable"
 	"go.uber.org/zap"
@@ -207,7 +206,7 @@ func (s *Service) triggerExport(ctx context.Context, exportCfg *storage.ExportCo
 	s.logger.Info("export triggered", zap.String("exportName", exportCfg.ExportName))
 	for policy, input := range exportCfg.Policies {
 		cacheKey := exportCacheKey(exportCfg.ExportName, policy)
-		_, err := s.policy.Evaluate(ctx, policy, input, cacheKey, exportCfg.TTL)
+		_, err := s.policy.Evaluate(ctx, policy, input, cacheKey, exportCfg.CacheTTL)
 		if err != nil {
 			return err
 		}
diff --git a/internal/service/infohub/service_test.go b/internal/service/infohub/service_test.go
index 121971a..c585ea2 100644
--- a/internal/service/infohub/service_test.go
+++ b/internal/service/infohub/service_test.go
@@ -86,7 +86,7 @@ func TestService_Export(t *testing.T) {
 						ExportName: "testexport",
 						Contexts:   []string{"https://www.w3.org/2018/credentials/examples/v1"},
 						Policies:   map[string]interface{}{"test/test/1.0": map[string]interface{}{"hello": "test world"}},
-						TTL:        ptr.Int(60),
+						CacheTTL:   ptr.Int(60),
 					}, nil
 				},
 			},
@@ -136,7 +136,7 @@ func TestService_Export(t *testing.T) {
 						ExportName: "testexport",
 						Contexts:   []string{"https://www.w3.org/2018/credentials/examples/v1"},
 						Policies:   map[string]interface{}{"test/test/1.0": map[string]interface{}{"hello": "test world"}},
-						TTL:        ptr.Int(60),
+						CacheTTL:   ptr.Int(60),
 					}, nil
 				},
 			},
diff --git a/internal/storage/storage.go b/internal/storage/storage.go
index 542a114..5c6072c 100644
--- a/internal/storage/storage.go
+++ b/internal/storage/storage.go
@@ -15,7 +15,7 @@ type ExportConfiguration struct {
 	ExportName string
 	Contexts   []string
 	Policies   map[string]interface{}
-	TTL        *int
+	CacheTTL   *int
 }
 
 type Storage struct {
-- 
GitLab