"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Read cloud specific configuration from configuration files

Read cloud specific configuration from configuration files

Published on 2024-11-08
Browse:133

Read cloud specific configuration from configuration files

Configuration specific to cloud provider can be separated in a config file by setting cloud provider name as a section.

Define a configuration file

Create a configuration file - config.ini in the src package and define cloud provider specific configuration similar to below.

[aws]
bucket_name: test-aws-bucket

[gcp]
bucket_name: test-gcp-bucket

Read the configuration in the code

Read cloud provider from environment variable.

cloud_provider = os.environ.get('CLOUD_PROVIDER')

Declare a config parser in python and read the configuration file

config = configparser.ConfigParser()
config_path = os.path.join(os.path.dirname(__file__), 'config.ini')
config.read(config_path)
bucket_name = config.get(cloud_provider,'bucket_name')

In this way, we can separate cloud provider specific configuration in config files.

Please feel free to comment with any suggestions/feedback.

Release Statement This article is reproduced at: https://dev.to/grkashyap/read-cloud-specific-configuration-from-configuration-files-5db0?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3