Read cloud specific configuration from configuration files

Patricia Arquette
Release: 2024-10-10 14:12:03
Original
769 people have browsed it

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
Copy after login

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')
Copy after login

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

Please feel free to comment with any suggestions/feedback.

The above is the detailed content of Read cloud specific configuration from configuration files. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!