Open angeloalvarez opened 3 months ago
That's a great suggestion! This solution will also allow Eolic to be configured by config maps on K8s clusters.
Since we are already using the pydantic models to handle serializable schemas, we could use BaseSettings or the regular BaseModel to handle json, yaml, toml and also some future configuration by environment variables
Thank you for your insightful suggestion!
I’ve made the necessary changes to the code to implement this solution, which will indeed allow Eolic to be configured using config maps on K8s clusters. By leveraging Pydantic's BaseSettings, we can now efficiently handle JSON, YAML, TOML configurations, and future environment variable setups.
I hope this approach works well for you! If you have any thoughts or suggestions, I’d love to hear them!
Is your feature request related to a problem? Please describe.
The primary use case for this utility is to read configuration files that can be integrated into the initialization process of an existing class. This will enhance the flexibility of the class by allowing configurations to be easily loaded and modified via external JSON files.
Describe the solution you'd like
I would like to implement a utility function for reading JSON files to enhance the way our project handles external configurations and data. The proposed solution involves creating a dedicated package within our project structure to manage file reading operations. Specifically, the read_json_file function will be designed to:
Accept a file path as an argument and return the contents of the file as either a dictionary or a list, depending on the JSON structure.
Handle common errors gracefully, such as when the file is not found or when the file contents are not valid JSON.
Be integrated with the initialization process of an existing class within our project, allowing the class to load its configuration from an external JSON file. This will provide greater flexibility in managing class configurations and reduce the need to hardcode settings directly into the code.
Describe alternatives you've considered
One alternative would be to continue hardcoding configurations directly within the class, but this would reduce flexibility and make it more difficult to update settings without modifying the code. Another option could involve using a different file format (e.g., YAML), with the potential for future support for YAML to allow even greater flexibility.