All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.openfga.runtime.OpenFGARecorder Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package io.quarkiverse.openfga.runtime;

import static io.quarkiverse.openfga.client.OpenFGAClient.storeIdResolver;

import io.quarkiverse.openfga.client.AuthorizationModelClient;
import io.quarkiverse.openfga.client.OpenFGAClient;
import io.quarkiverse.openfga.client.StoreClient;
import io.quarkiverse.openfga.client.api.API;
import io.quarkiverse.openfga.runtime.config.OpenFGAConfig;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.TlsConfig;
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.mutiny.core.Vertx;

@Recorder
public class OpenFGARecorder {

    public RuntimeValue createAPI(OpenFGAConfig config, TlsConfig tlsConfig, boolean tracingEnabled,
            RuntimeValue vertx, ShutdownContext shutdownContext) {
        var api = new API(config, tlsConfig, tracingEnabled, Vertx.newInstance(vertx.getValue()));
        shutdownContext.addShutdownTask(api::close);
        return new RuntimeValue<>(api);
    }

    public RuntimeValue createClient(RuntimeValue api) {
        OpenFGAClient openFGAClient = new OpenFGAClient(api.getValue());
        return new RuntimeValue<>(openFGAClient);
    }

    public RuntimeValue createStoreClient(RuntimeValue api, OpenFGAConfig config) {
        var storeIdResolver = storeIdResolver(api.getValue(), config.store, config.alwaysResolveStoreId);
        StoreClient storeClient = new StoreClient(api.getValue(), storeIdResolver);
        return new RuntimeValue<>(storeClient);
    }

    public RuntimeValue createAuthModelClient(RuntimeValue api, OpenFGAConfig config) {
        var storeIdResolver = storeIdResolver(api.getValue(), config.store, config.alwaysResolveStoreId);
        AuthorizationModelClient authModelClient = new AuthorizationModelClient(api.getValue(), storeIdResolver,
                config.authorizationModelId.orElse(null));
        return new RuntimeValue<>(authModelClient);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy