Skip to content
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

SDK should not panic if config reader not supplied #4303

Closed
tsandall opened this issue Jan 29, 2022 · 2 comments
Closed

SDK should not panic if config reader not supplied #4303

tsandall opened this issue Jan 29, 2022 · 2 comments
Assignees

Comments

@tsandall
Copy link
Member

The following code panics:

package main

import (
	"context"
	"log"

	"github.com/open-policy-agent/opa/sdk"
)

func main() {

	ctx := context.Background()
	opa, err := sdk.New(ctx, sdk.Options{}) // Config MUST be provided
	if err != nil {
		log.Fatal(err)
	}

	result, err := opa.Decision(ctx, sdk.DecisionOptions{})
	if err != nil {
		log.Fatal(err)
	}

	log.Println(result)
}

We should fix the sdk so that this doesn't cause a panic. All we need to do is check if the Config reader is nil and default to an empty object here: https://github.com/open-policy-agent/opa/blob/main/sdk/options.go#L64 (e.g., set bs to []byte("{}")).

@tsandall tsandall changed the title go sdk panics if Config reader is nil SDK should not panic if config reader not supplied Jan 29, 2022
@damienjburks
Copy link
Contributor

Is anyone assigned to this issue? I would like to take this on.

@anderseknert
Copy link
Member

@damienjburks 👍

damienjburks added a commit to damienjburks/opa that referenced this issue Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants