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

Context Error Invoking SyncUser() #46

Open
gingersab opened this issue Oct 29, 2024 · 1 comment
Open

Context Error Invoking SyncUser() #46

gingersab opened this issue Oct 29, 2024 · 1 comment

Comments

@gingersab
Copy link

gingersab commented Oct 29, 2024

I'm seeing an issue with SyncUser(ctx, *models.UserCreate). Regardless of how the context is created or passed, I hit the error ErrorCode: ContextError, ErrorType: general_error, Message: The context is missing or invalid

The following is based on the example provided in the README

Permit configuration is in its own package

type PermitService struct {
	permitCfg      *config.PermitConfig
	permitOperator *permit.Client
}

func NewPermitService(token string) *PermitService {
	cfg := config.NewConfigBuilder(token).Build()
	client := permit.New(cfg)
	return &PermitService{
		permitCfg:      &cfg,
		permitOperator: client,
	}
}

func (permitSvc *PermitService) AddUser(username string, ctx context.Context) {
	newUser := models.NewUserCreate(username) //works
	_, err := permitSvc.permitOperator.SyncUser(ctx, *newUser) //produces context error
	if err != nil {
		log.Fatal(err.Error())
	}
}

Attempt to add a new user originates from a different package

ctx := context.TODO() //also tried background context
permitSvc := pdp.NewPermitService(pdpApiKey) //pdpApiKey is valid
pdpSvc := pdp.NewPdpService(permitSvc) //abstraction layer
pdpSvc.PdpSvc.AddUser("test-user", ctx)

From what I've been able to ascertain, the error originates from the call to

client.APIKeysApi.GetApiKeyScope(ctx).Execute()

and is returned here

return nil, PermitErrors.NewPermitContextError(additionalErrorMessage)

@gingersab
Copy link
Author

gingersab commented Nov 4, 2024

Solved this by passing the PDP URL

cfg := config.NewConfigBuilder(token).WithPdpUrl("https://cloudpdp.api.permit.io").Build()

The docs should be updated to illustrate that this is required. It may also be useful to update the log surrounding this since it's not immediately obvious or transparent that context is missing or invalid is referring to an invalid PDP location

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

1 participant