From e1db108369aa3b0cc13516da87f8120b075ad38c Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Fri, 7 Feb 2025 15:56:21 +0100 Subject: [PATCH] data-playground: adjust for /v1/compile --- Caddyfile | 3 --- Caddyfile-local | 4 ---- docker-compose.yaml | 3 +-- src/components/RegoEditor.js | 4 ++-- src/components/helpers.js | 9 +++++---- src/policies/filters.rego | 2 -- 6 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Caddyfile b/Caddyfile index d63b729..d0f5e0e 100644 --- a/Caddyfile +++ b/Caddyfile @@ -6,9 +6,6 @@ handle /v1/* { reverse_proxy http://eopa:8181 } - handle /exp/* { - reverse_proxy http://eopa:8181 - } handle { root * /usr/share/caddy diff --git a/Caddyfile-local b/Caddyfile-local index e70d0ec..0e21f46 100644 --- a/Caddyfile-local +++ b/Caddyfile-local @@ -6,10 +6,6 @@ reverse_proxy http://127.0.0.1:8181 } - handle /exp/* { # EOPA - reverse_proxy http://127.0.0.1:8181 - } - handle { # Observable Framework's dev server reverse_proxy http://127.0.0.1:3000 } diff --git a/docker-compose.yaml b/docker-compose.yaml index 6628201..5ecdf1d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,7 +7,7 @@ services: - eopa eopa: - image: ${EOPA_IMAGE:-ghcr.io/styrainc/enterprise-opa:edge} + image: ${EOPA_IMAGE:-ghcr.io/styrainc/enterprise-opa:latest} pull_policy: ${EOPA_PULL_POLICY:-always} ports: - "8181:8181" @@ -17,6 +17,5 @@ services: - --addr=:8181 - --log-level=debug - --no-license-fallback - - --set=plugins.exp_compile_api={} environment: EOPA_LICENSE_KEY: ${EOPA_LICENSE_KEY:-} diff --git a/src/components/RegoEditor.js b/src/components/RegoEditor.js index 06de987..99ed6ac 100644 --- a/src/components/RegoEditor.js +++ b/src/components/RegoEditor.js @@ -36,7 +36,7 @@ export function RegoEditor({ } // If we make it this far, the policy is on the server, so let's compile it: const { result, errors } = await (await compilePolicy(opa, input, mappings)).json(); - const query = result; + const { query } = result; if (errors) { parent.value = String(""); // this means "no query produced" parent.dispatchEvent(new InputEvent("input", {bubbles: true})); @@ -53,7 +53,7 @@ export function RegoEditor({ }); } - parent.value = String(result); // TODO(sr) check this + parent.value = String(query); parent.dispatchEvent(new InputEvent("input", {bubbles: true})); return []; }, { diff --git a/src/components/helpers.js b/src/components/helpers.js index 7a15b95..4cded81 100644 --- a/src/components/helpers.js +++ b/src/components/helpers.js @@ -11,19 +11,20 @@ export async function putPolicy(opa, id, code, raise = true) { } export async function compilePolicy(opa, input, mappings = {}, query = "data.filters.include") { - const resp = await fetch(`${opa}exp/compile`, { + const resp = await fetch(`${opa}v1/compile`, { method: "POST", body: JSON.stringify({ input, query, options: { - dialect: "postgres", - targetSQLTableMappings: mappings, + targetSQLTableMappings: { + postgres: mappings, + }, }, }), headers: { "Content-Type": "application/json", - "Accept": "application/vnd.styra.sql+json" + "Accept": "application/vnd.styra.sql.postgres+json" }, }); return resp; diff --git a/src/policies/filters.rego b/src/policies/filters.rego index 864587e..50bcad0 100644 --- a/src/policies/filters.rego +++ b/src/policies/filters.rego @@ -19,5 +19,3 @@ include if { input.products.price < 500 input.users.name == user } - -_use_metadata := rego.metadata.rule()