Skip to content

Standard Client

Usage

retrieving configurations

from config.spring import ConfigClient

config_client = ConfigClient(app_name='my_app')
config_client.get_config()

# option 1: dict like with direct access
config_client.config['spring']['cloud']['consul']['host']
config_client['spring.cloud.consul.host']

# option 2: dict like using get
config_client.config.get('spring').get('cloud').get('consul').get('port')

# option 3: using get_attribute method *deprecated*, please use: option 1 or option 2
config_client.get_attribute('spring.cloud.consul.port')

custom parameters on HTTP request

from config.spring import ConfigClient

config_client = ConfigClient(app_name='my_app')
config_client.get_config(timeout=5.0, headers={'Accept': 'application/json'})

spring cloud config with oauth2

from config.spring import ConfigClient
from config.auth import OAuth2

config_client = ConfigClient(
    app_name='my_app',
    auth=OAuth2(
        access_token_uri='http://srv/token',
        client_id='my_client_id',
        client_secret='client_credentials'
    )
)
response = config_client.get_config()
# This request will first request oauth token and after will request the config.

print(response)

For more info see: https://cloud.spring.io/spring-cloud-config/multi/multi__serving_plain_text.html

retrieving plain files

from config.spring import ConfigClient

config_client = ConfigClient(app_name='my_app')
response = config_client.get_file('nginx.conf')

print(response)

For more info see: https://cloud.spring.io/spring-cloud-config/multi/multi__serving_plain_text.html