{"id":7933,"library":"app-common-python","title":"Red Hat Insights App Common Python","description":"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.","status":"active","version":"0.2.9","language":"en","source_language":"en","source_url":"https://github.com/RedHatInsights/app-common-python","tags":["configuration","red hat","openshift","clowder","microservices","kubernetes"],"install":[{"cmd":"pip install app-common-python","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Provides access to Clowder-injected configuration data.","symbol":"LoadedConfig","correct":"from app_common_python import LoadedConfig"},{"note":"Helper function to check if the application is running in a Clowder-enabled environment.","symbol":"isClowderEnabled","correct":"from app_common_python import isClowderEnabled"}],"quickstart":{"code":"from app_common_python import LoadedConfig, isClowderEnabled\nimport os\n\ndef main():\n    if isClowderEnabled():\n        print(f\"Application running in Clowder environment.\")\n        # Access public port, for example\n        if hasattr(LoadedConfig, 'PublicPort'):\n            print(f\"Public Port: {LoadedConfig.PublicPort}\")\n        else:\n            print(\"PublicPort attribute not found in LoadedConfig. Check Clowder configuration.\")\n        \n        # Example: Get Kafka servers\n        kafka_servers = LoadedConfig.KafkaServers\n        print(f\"Kafka Servers: {kafka_servers}\")\n        \n        # Example: Get a specific Kafka topic by name\n        # Assuming 'my-topic' is a configured topic\n        if 'my-topic' in LoadedConfig.KafkaTopics:\n            my_topic = LoadedConfig.KafkaTopics['my-topic']\n            print(f\"Kafka Topic 'my-topic': {{'name': {my_topic.Name}, 'hostname': {my_topic.Hostname}}}\")\n    else:\n        print(\"Application not running in Clowder environment or Clowder not enabled.\")\n        print(\"Configuration might need to be provided via environment variables (e.g., ACG_CONFIG).\")\n\nif __name__ == \"__main__\":\n    # For local testing without Clowder, you might set ACG_CONFIG\n    # e.g., os.environ['ACG_CONFIG'] = 'path/to/test.json'\n    main()","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your application is deployed within a Clowder-managed OpenShift environment or provide a mock configuration if testing locally (e.g., via `ACG_CONFIG` environment variable).","message":"This library is specifically designed to interact with the Red Hat OpenShift Clowder operator for configuration management. It is not a general-purpose configuration library. Usage outside a Clowder-managed environment will result in `isClowderEnabled()` returning `False` and `LoadedConfig` attributes being unavailable or empty.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly review your Clowder `ClowdApp` and `ClowdEnvironment` definitions to ensure all required configuration keys are present and correctly structured for your application. Use `hasattr(LoadedConfig, 'attribute_name')` for robustness.","message":"Configuration values accessed via `LoadedConfig` (e.g., `LoadedConfig.PublicPort`, `LoadedConfig.KafkaServers`) directly reflect the JSON provided by Clowder. If the underlying Clowder configuration for your application is missing or malformed for a specific attribute, accessing that attribute will likely result in an `AttributeError` or an empty value.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set the `ACG_CONFIG` environment variable to the path of a valid Clowder-compatible JSON configuration file for local development or testing. Example: `export ACG_CONFIG=\"./test.json\"`.","message":"For local development or testing without a full Clowder deployment, configuration often needs to be supplied via environment variables, such as `ACG_CONFIG` pointing to a local JSON file. Failing to set these variables or providing an invalid file will lead to an unconfigured state.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the package using `pip install app-common-python`. Double-check the import statement: `from app_common_python import LoadedConfig`.","cause":"The `app-common-python` library is not installed in the current Python environment or there's a typo in the import statement.","error":"ModuleNotFoundError: No module named 'app_common_python'"},{"fix":"Verify that your application's `ClowdApp` configuration in OpenShift explicitly defines a public port. If running locally, ensure `ACG_CONFIG` is set and points to a valid JSON file containing the `PublicPort` entry. Always check `if hasattr(LoadedConfig, 'PublicPort'):` before accessing such attributes.","cause":"The `PublicPort` attribute is not present in the Clowder configuration loaded by `LoadedConfig`, or the application is not running in a Clowder-enabled environment (`isClowderEnabled()` is False).","error":"AttributeError: type object 'LoadedConfig' has no attribute 'PublicPort'"},{"fix":"Ensure the Kafka topic is correctly configured and referenced by its `requestedName` in your Clowder `ClowdApp` resource. Access Kafka topics robustly using `if 'my-topic' in LoadedConfig.KafkaTopics:`.","cause":"The requested Kafka topic 'my-topic' is not defined or available in the Clowder-provided configuration, or it's requested with an incorrect `requestedName`.","error":"KeyError: 'my-topic'"}]}