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

Get List of Projects with Org API Key #5

Open
jblackburn21 opened this issue Mar 31, 2023 · 1 comment
Open

Get List of Projects with Org API Key #5

jblackburn21 opened this issue Mar 31, 2023 · 1 comment

Comments

@jblackburn21
Copy link

I'm get a panic when trying to list all projects using an Org API Key. This works with an environment scoped API Key.

package main

import (
	"context"
	"fmt"
	"github.com/permitio/permit-golang/pkg/config"
	"github.com/permitio/permit-golang/pkg/permit"
	"go.uber.org/zap"
)

func main() {
	// This line initializes the SDK and connects your Go app
	// to the Permit.io PDP container (you've set in the previous step), with the API key provided.
	permitClient := permit.NewPermit(
		// Building new config for Permit client
		config.NewConfigBuilder(
			// your api key		"***").
			// Set the PDP URL
			WithLogger(zap.NewExample()).
			WithPdpUrl("http://localhost:7766").
			Build(),
	)

	ctx := context.TODO()

	projects, _ := permitClient.Api.Projects.List(ctx, 1, 10)

	for i := 0; i < len(projects); i++ {
		fmt.Println(projects[i].Name)
	}

}

However, I get this panic

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10453946c]

goroutine 1 [running]:
github.com/permitio/permit-golang/pkg/config.GetApiKeyLevel(...)
        /Users/jblackburn/repos/github/permit/permit-golang/pkg/config/utils.go:17
github.com/permitio/permit-golang/pkg/config.PermitContextFactory({0x10464d6c8?, 0x14000112008?}, 0x140000779f0?, {0x0, 0x0}, {0x0, 0x0}, 0x0)
        /Users/jblackburn/repos/github/permit/permit-golang/pkg/config/context.go:54 +0x7c
github.com/permitio/permit-golang/pkg/api.(*permitBaseApi).lazyLoadPermitContext(0x1400000c2e8, {0x10464d6c8?, 0x14000112008?}, {0x140000f5b08, 0x1, 0xf00001042fcc78?})
        /Users/jblackburn/repos/github/permit/permit-golang/pkg/api/api.go:25 +0x90
github.com/permitio/permit-golang/pkg/api.(*Projects).List(0x1400000c2e8, {0x10464d6c8, 0x14000112008}, 0x1, 0xa)
        /Users/jblackburn/repos/github/permit/permit-golang/pkg/api/projects.go:37 +0x70
main.main()
        /Users/jblackburn/repos/poc/permit-sdk/main.go:30 +0x150
exit status 2

I was able to work through these panics, but then get this error

{"level":"error","msg":"","error":"ErrorCode: ContextError ErrorType:general_error Message:The context is missing or invalid - You're trying to use an SDK method that's specific to a project,but you haven't set the current project in your client's context yet,or you are using an organization level API key.Please set the context to a specificproject using `PermitClient.SetPermitContext()` method."}
@gingersab
Copy link

gingersab commented Oct 29, 2024

I'm seeing a similar issue with SyncUser(ctx, *models.UserCreate)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants