RedHatInsights / clowder-quarkus-config-source

A config source for Quarkus to do app configuration for Quarkus via Clowderfile.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

clowder-quarkus-config-source

Usage

Include the jar in your project’s pom.xml:

<dependency>
  <groupId>com.redhat.cloud.common</groupId>
  <artifactId>clowder-quarkus-config-source</artifactId>
  <version>0.1.1</version>
</dependency>

There is an optional property that determines the configuration file to use:

Table 1. Property
Name Default Value

acg.config

/cdapp/cdappconfig.json

If the configuration file is not found, a message is printed, and the config source is effectively disabled.

Sample log output when the config file can’t be found
2021-03-17 22:15:31,787 INFO  [com.red.clo.com.clo.con.ClowderConfigSourceFactory] (main) Using ClowderConfigSource with config at /cdapp/cdappconfig.json
2021-03-17 22:15:31,794 WARN  [com.red.clo.com.clo.con.ClowderConfigSource] (main) Can't read clowder config from /cdapp/cdappconfig.json, not doing translations.
NOTE

For Quarkus, you can put it in application.properties. The flag can also be given via system property (-Dacg.config=my-file.json) or environment (ACG_CONFIG=myfile.json java -jar …​), which then override the settings in application.properties.

Retrieving an endpoint URL from Clowder

Depending on your ClowdApp dependencies, Clowder may provide some endpoints configuration as shown below:

{
  "endpoints":[
    {
      "app":"notifications-backend",
      "hostname":"notifications-backend-service.ephemeral-24.svc",
      "name":"service",
      "port":8000
    },
    {
      "app":"rbac",
      "hostname":"rbac-service.ephemeral-24.svc",
      "name":"service",
      "port":8000
    }
  ]
}

Each Clowder endpoint URL can be injected into your Quarkus configuration file:

rbac-url=${clowder.endpoints.rbac-service:http://localhost:8080}

In this example, the clowder.endpoints.rbac-service configuration key is composed of:

  • the clowder.endpoints. prefix which is always required

  • the Clowder endpoint app field: rbac

  • a fixed separator: -

  • the Clowder endpoint name field: service

The resulting value will be http://rbac-service.ephemeral-24.svc:8000 which is composed of:

  • a fixed prefix: http://

  • the Clowder endpoint hostname field: rbac-service.ephemeral-24.svc

  • a fixed separator: :

  • the Clowder endpoint port field: 8000

If the clowder.endpoints.rbac-service configuration key is not found, then the http://localhost:8080 default value will be used. That default value is optional. Learn more about the Quarkus configuration properties and how the properties expressions are expanded in the Configuration Reference Guide.

The injection of a Clowder endpoint URL can also be done from your application code:

import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class MyService {

    @ConfigProperty(name = "clowder.endpoints.rbac-service", defaultValue = "http://localhost:8080")
    String myRbacUrl;

    public void doSomething() {
        // myRbacUrl can be used here
    }

    public void doSomethingElse() {
        String myOtherRbacUrl = ConfigProvider.getConfig().getValue("clowder.endpoints.rbac-service", String.class);
        // myRbacUrl and myOtherRbacUrl can be used here
    }
}

Further reading

There is an article that further explains the working of this config source.

About

A config source for Quarkus to do app configuration for Quarkus via Clowderfile.

License:Apache License 2.0


Languages

Language:Java 100.0%