quarkiverse / quarkus-openfga-client

Quarkus extension for OpenFGA support
https://openfga.dev
Apache License 2.0
8 stars 6 forks source link

Unable to load files for quarkus.openfga.devservices.authorization-model-location property #118

Closed ingmarfjolla closed 2 months ago

ingmarfjolla commented 3 months ago

Hello, I'm not sure if it's directly related to #115 , but I've been trying to use the quarkus.openfga.devservices.authorization-model-location=classpath:auth-model.json property to load my model without much success. My model has indirect relations like in the linked issue, where I'm modeling entitlements as seen here: https://openfga.dev/docs/modeling/advanced/entitlements.

However, I tried to test using the same authorization model used in this repo's integration tests but I get the same error:

java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkiverse.openfga.deployment.DevServicesOpenFGAProcessor#startContainers threw an exception: java.lang.RuntimeException: java.lang.RuntimeException: Unable to load authorization model from 'classpath:auth-model.json'

If I use the quarkus.openfga.devservices.authorization-model property though the authorization model in this repo will work, just not the location property. However if I use the entitlement model that I linked above, it fails with the same error as the other issue.

am I using the location property incorrectly or is it a bug? Thank you!

kdubb commented 3 months ago

Is your auth-model.json in the root of your main/resources?

ingmarfjolla commented 3 months ago

yes (unless I misunderstood what you meant by root), https://github.com/ingmarfjolla/quarkus-super-heroes/blob/authz/authn/auth-service/src/main/resources/openfga-model.json

wkerckho commented 2 months ago

I'm experiencing a similar issue in a multi-module Quarkus project, where I've put a json file to be loaded as the authorization-model (when using dev services) on the root of main/resources in a shared module.

// The following results in a enumeration of one URL:
Thread.currentThread().getContextClassLoader().getResources("/schema.json");

I did some debugging and noticed that an additional slash is appended in the normalizeLocation method. There is probably a reason why this is added, but this seams to be the cause of this issue.

When appending a slash, the JSON file can only be found if it is located in the main/resources of the current artifact (and not in the resource folders of possible dependencies). I can't explain this behavior, maybe it has something to do with the resource path actually referring to a folder? If no slash is added, calling getResources("schema.json") on the context classloader will include the JSON file located in the resources folder of the dependency, which I would expect is the desired behavior?