Red Hat Insights App Common Python

0.2.9 · active · verified Thu Apr 16

app-common-python is a simple client access library designed to retrieve configuration for applications running within the Red Hat OpenShift Clowder operator environment. It provides Python wrappers and helper functions to easily access details related to Kafka topics, RDS certificate authorities, Kafka broker servers, object storage buckets, and other service dependency endpoints, abstracting away the underlying JSON configuration provided by Clowder. The current version is 0.2.9, with releases occurring periodically to update schemas and introduce new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use `LoadedConfig` and `isClowderEnabled` to access application configuration provided by the Clowder operator. It includes examples for checking the Clowder environment, retrieving a public port, and accessing Kafka server and topic details.

from app_common_python import LoadedConfig, isClowderEnabled
import os

def main():
    if isClowderEnabled():
        print(f"Application running in Clowder environment.")
        # Access public port, for example
        if hasattr(LoadedConfig, 'PublicPort'):
            print(f"Public Port: {LoadedConfig.PublicPort}")
        else:
            print("PublicPort attribute not found in LoadedConfig. Check Clowder configuration.")
        
        # Example: Get Kafka servers
        kafka_servers = LoadedConfig.KafkaServers
        print(f"Kafka Servers: {kafka_servers}")
        
        # Example: Get a specific Kafka topic by name
        # Assuming 'my-topic' is a configured topic
        if 'my-topic' in LoadedConfig.KafkaTopics:
            my_topic = LoadedConfig.KafkaTopics['my-topic']
            print(f"Kafka Topic 'my-topic': {{'name': {my_topic.Name}, 'hostname': {my_topic.Hostname}}}")
    else:
        print("Application not running in Clowder environment or Clowder not enabled.")
        print("Configuration might need to be provided via environment variables (e.g., ACG_CONFIG).")

if __name__ == "__main__":
    # For local testing without Clowder, you might set ACG_CONFIG
    # e.g., os.environ['ACG_CONFIG'] = 'path/to/test.json'
    main()

view raw JSON →