New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin documentation request for adding an route to the OPA runtime params #3937
Comments
Heya! Thanks for filing the issue. I had another close look at the code and found two things:
I'm a bit hesitant documenting this extension path at large, but here's a snippet that hopefully unblocks you: package main
import (
"context"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/open-policy-agent/opa/runtime"
)
func main() {
ctx := context.Background()
router := mux.NewRouter()
router.HandleFunc("/customEndpoint", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`{"myCustomResponse": true}`)) // ignore error
})
params := runtime.Params{
Addrs: &[]string{"0.0.0.0:8080"},
Router: router,
}
rt, err := runtime.NewRuntime(ctx, params)
if err != nil {
log.Fatal(err)
}
log.Fatal(rt.Serve(ctx))
} |
Thank you for the response! Your explanation answers and satisfies my original ask.
Update Thanks bigtime! |
Request
I was wondering if anyone could provide a code snippet/example for a plugin extension that adds an http route to the OPA runtime params, similar to "println_decision_logger" plugin example on the OPA website (ref: println_decision_logger example).
Background
Hello,
Looking to extend OPA via custom plugins for the OPA runtime (ref: Custom Plugins for OPA Runtime). I would like to implement an additional http endpoint (ex: /hello-world) and register it with OPA. I have discovered I can use the "net/http" package and create an endpoint that way (see bellow code example), but that would require I use a separate port from OPA (8090 instead of OPA's 8181).
I found a PR (PR: Add Router to runtime.Params) that may solve my multi-port issue that has been merged recently, but I can't seem to figure out how I would get it to work and can't find any code snippets/examples.
net/http code snippet using a separate port:
Note
This issue is a pull over from my OPA Slack channel question. (Original Slack Channel Question)
The text was updated successfully, but these errors were encountered: