From 7fda4bd85e632a6bc4251d21e44d539d3196165f Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Tue, 17 Dec 2024 14:18:29 +0000 Subject: [PATCH] docs: Explain backwards compat in SDK use case Signed-off-by: Charlie Egan --- docs/content/v0-compatibility.md | 37 +++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/content/v0-compatibility.md b/docs/content/v0-compatibility.md index 14535f451e..6c742635e5 100644 --- a/docs/content/v0-compatibility.md +++ b/docs/content/v0-compatibility.md @@ -113,6 +113,37 @@ r := rego.New( ### v0.x compatibility mode in the OPA Go SDK -{{< info >}} -TODO -{{< /info >}} +In OPA 1.0, the recommended +[SDK package](https://pkg.go.dev/github.com/open-policy-agent/opa/v1/sdk) +import for most users is `github.com/open-policy-agent/opa/sdk/v1`. + +Those who need to support v0 bundles should set the Rego version on bundle +manifests as outlined above wherever possible. For users unable to do this, use +of a v0 import of the SDK package is required. For example: + +```go +package main + +import ( + "bytes" + "context" + "fmt" + + "github.com/open-policy-agent/opa/sdk" // <-- import v0 sdk package + // "github.com/open-policy-agent/opa/sdk/v1" // <-- import v1 sdk package +) + +func main() { + opa, _ := sdk.New(ctx, sdk.Options{ + ID: "opa-1", + Config: bytes.NewReader(config), + }) + + defer opa.Stop(ctx) + + // ... +} +``` + +Users in this scenario should look to version bundles as soon as possible to +allow them to use a v1 SDK instead.