Not sure what I am doing wrong but I am
# spicedb
k
Not sure what I am doing wrong but I am attempting to use the lookupResources, response, err := client.LookupResources(ctx, &v1.LookupResourcesRequest{ I can only seem to get access to it via the import v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" However, I cannot iterate through the response. From what I have seen, you can use response.Results or response.ResourceIds but they do not appear to be part of the response. for _, resourceID := range response.ResourceIds{ fmt.Printf("resource %s ", resourceID) }
v
so I'm not sure if that is the actual code you are using in your client, but lookup resources is a streaming API and you don't get the results directly from the
LookupResources
call here is an example https://github.com/authzed/zed/blob/main/internal/commands/permission.go#L477-L509
k
Am I using the correct call that would map to the following zed command? zed permission lookup-resources application can_access user:kwiggins --caveat-context '{"user_device": "managed","user_ip": "192.168.0.4"}'
v
im confused, did I help you with your first question? that zed call looks correct to me
k
Just want to confirm that the go equivalent is to use the LookupResources. I have seen on here, in a different thread, code for that function. I take it that the following code snippet is not valid? response, err := client.LookupResources(context.TODO(), &v1.LookupResourcesRequest{ ResourceObjectType: resourceType, Permission: permission, Subject: subject, }) if err != nil { log.Printf("Error looking up resources for permission %s on %s: %v", permission, resourceType, err) continue } // Print out the resources Alice has this permission on for _, resourceID := range response.ResourceIds { fmt.Printf("Alice has %s permission on %s:%s\n", permission, resourceType, resourceID) } } }
I was able to get it working, thanks for your link. I just needed to know more about grpc.ServerStreamingClient
just doing the following on the response for { res, err := response.Recv() if err == io.EOF { log.Println("EOF") break } if err != nil { log.Fatalf("error receiving stream: %v", err) } log.Printf("Received: %s", res.ResourceObjectId) }
y
glad to hear it! i just went to look at the tests for that repo and realized that they haven't been fleshed out - that might be good to have as a reference
17 Views