Skip to content

Commit

Permalink
Update version of OPA, golang and fix some failing linter checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Todor Videv committed Feb 1, 2024
1 parent 9d25601 commit bef213c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ executors:
environment:
GOPATH: /go
NEO4J_TEST_URL: "bolt://localhost:7687"
POLICY_AGENT_TEST_URL: "http://localhost:8181"
OPA_URL: "http://localhost:8181"
- image: neo4j:4.3.10-enterprise
environment:
NEO4J_AUTH: none
NEO4J_HEAP_MEMORY: 256
NEO4J_CACHE_MEMORY: 256M
NEO4J_ACCEPT_LICENSE_AGREEMENT: "yes"
- image: openpolicyagent/opa:0.57.0
- image: openpolicyagent/opa:0.61.0
command: [ "run", "--server", "--addr=0.0.0.0:8181", "--log-format=json-pretty", "--set=decision_logs.console=true" ]

jobs:
Expand Down
5 changes: 3 additions & 2 deletions content/content_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"bytes"
"errors"
"fmt"
"github.com/Financial-Times/opa-client-go"
"net/http"
"os"
"testing"

"github.com/Financial-Times/opa-client-go"

"github.com/Financial-Times/content-rw-neo4j/v3/policy"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -1006,7 +1007,7 @@ func checkDBClean(d *cmneo4j.Driver, t *testing.T) {
}

func getAgent(p string, l *logger.UPPLogger, t *testing.T) policy.Agent {
url := os.Getenv("POLICY_AGENT_TEST_URL")
url := os.Getenv("OPA_URL")
if url == "" {
url = "http://localhost:8181"
}
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
environment:
- NEO4J_TEST_URL=bolt://neo4j:7687
- CGO_ENABLED=1
- POLICY_AGENT_TEST_URL=http://opa:8181
- OPA_URL=http://opa:8181
command: ["go", "test", "-mod=readonly", "-v", "-race", "-tags=integration", "./..."]
depends_on:
- neo4j
Expand All @@ -25,7 +25,7 @@ services:
- "7474:7474"
- "7687:7687"
opa:
image: openpolicyagent/opa:0.57.0
image: openpolicyagent/opa:0.61.0
ports:
- "8181:8181"
command:
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/Financial-Times/content-rw-neo4j/v3

go 1.21

toolchain go1.21.5

require (
github.com/Financial-Times/base-ft-rw-app-go/v2 v2.0.0-20211207113529-d0faaa432d5d
github.com/Financial-Times/cm-neo4j-driver v1.1.0
Expand Down
2 changes: 1 addition & 1 deletion helm/content-rw-neo4j/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ image:
openPolicyAgentSidecar:
name: open-policy-agent
repository: openpolicyagent/opa
tag: 0.57.0
tag: 0.61.0
pullPolicy: IfNotPresent
serviceAccount: eksctl-content-rw-neo4j-serviceaccount
resources:
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"fmt"
"github.com/Financial-Times/opa-client-go"
"os"
"time"

"github.com/Financial-Times/opa-client-go"

"github.com/Financial-Times/content-rw-neo4j/v3/policy"

cli "github.com/jawher/mow.cli"
Expand Down Expand Up @@ -73,8 +74,8 @@ func main() {
EnvVar: "DB_DRIVER_LOG_LEVEL",
})

opaUrl := app.String(cli.StringOpt{
Name: "opaUrl",
opaURL := app.String(cli.StringOpt{
Name: "opaURL",
Desc: "URL of the policy agent.",
EnvVar: "OPA_URL",
})
Expand Down Expand Up @@ -112,7 +113,7 @@ func main() {
paths := map[string]string{
policy.SpecialContentKey: *opaSpecialContentPolicyPath,
}
opaClient := opa.NewOpenPolicyAgentClient(*opaUrl, paths, opa.WithLogger(log))
opaClient := opa.NewOpenPolicyAgentClient(*opaURL, paths, opa.WithLogger(log))
agent := policy.NewOpenPolicyAgent(opaClient, log)

contentDriver := content.NewContentService(driver, agent, log)
Expand Down
7 changes: 4 additions & 3 deletions policy/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package policy
import (
"errors"
"fmt"

"github.com/Financial-Times/go-logger/v2"
"github.com/Financial-Times/opa-client-go"
)
Expand Down Expand Up @@ -38,12 +39,12 @@ func (o *OpenPolicyAgent) EvaluateSpecialContentPolicy(
) (*SpecialContentPolicyResult, error) {
r := &SpecialContentPolicyResult{}

decisionId, err := o.client.DoQuery(q, SpecialContentKey, r)
decisionID, err := o.client.DoQuery(q, SpecialContentKey, r)
if err != nil {
return nil, fmt.Errorf("%w: Kafka Ingest Policy: %w", ErrEvaluatePolicy, err)
return nil, fmt.Errorf("%w: Special Content Policy: %w", ErrEvaluatePolicy, err)
}

o.log.Infof("Evaluated Kafka Ingest Policy: decisionId: %q, result: %v", decisionId, r)
o.log.Infof("Evaluated Special Content Policy: decisionID: %q, result: %v", decisionID, r)

return r, nil
}
24 changes: 13 additions & 11 deletions policy/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package policy
import (
"errors"
"fmt"
"github.com/Financial-Times/go-logger/v2"
"github.com/Financial-Times/opa-client-go"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"

"github.com/Financial-Times/go-logger/v2"
"github.com/Financial-Times/opa-client-go"
)

const (
testDecisionId = "1e58b3bf-995c-473e-90e9-ab1f10af74ab"
testDecisionID = "1e58b3bf-995c-473e-90e9-ab1f10af74ab"
)

func TestAgent_EvaluateSpecialContentPolicy(t *testing.T) {
Expand All @@ -26,9 +28,9 @@ func TestAgent_EvaluateSpecialContentPolicy(t *testing.T) {
}{
{
name: "Evaluate a valid decision for special content",
server: createHttpTestServer(
server: createHTTPTestServer(
t,
fmt.Sprintf(`{"decision_id": %q, "result": {"is_special_content": true}}`, testDecisionId),
fmt.Sprintf(`{"decision_id": %q, "result": {"is_special_content": true}}`, testDecisionID),
),
paths: map[string]string{
SpecialContentKey: "special/content",
Expand All @@ -43,9 +45,9 @@ func TestAgent_EvaluateSpecialContentPolicy(t *testing.T) {
},
{
name: "Evaluate a valid decision for non-special content",
server: createHttpTestServer(
server: createHTTPTestServer(
t,
fmt.Sprintf(`{"decision_id": %q, "result": {"is_special_content": false}}`, testDecisionId),
fmt.Sprintf(`{"decision_id": %q, "result": {"is_special_content": false}}`, testDecisionID),
),
paths: map[string]string{
SpecialContentKey: "special/content",
Expand All @@ -60,7 +62,7 @@ func TestAgent_EvaluateSpecialContentPolicy(t *testing.T) {
},
{
name: "Evaluate and receive an error.",
server: createHttpTestServer(
server: createHTTPTestServer(
t,
``,
),
Expand All @@ -85,7 +87,7 @@ func TestAgent_EvaluateSpecialContentPolicy(t *testing.T) {
if err != nil {
if !errors.Is(err, test.expectedError) {
t.Errorf(
"Unexpected error recieved from call to EvaluateSpecialContentPolicy: %v",
"Unexpected error received from call to EvaluateSpecialContentPolicy: %v",
err,
)
}
Expand All @@ -96,7 +98,7 @@ func TestAgent_EvaluateSpecialContentPolicy(t *testing.T) {
}
}

func createHttpTestServer(t *testing.T, response string) *httptest.Server {
func createHTTPTestServer(t *testing.T, response string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(response))
Expand Down

0 comments on commit bef213c

Please sign in to comment.