Skip to content

Introduction

Setup

The default URL pattern is: - CONFIGSERVER_ADDRESS/BRANCH/APP_NAME-PROFILE.json

# expected environment variables:
#
CONFIGSERVER_ADDRESS=http://localhost:8888
BRANCH=master
PROFILE=development
APP_NAME=myapp # field required
CONFIG_FAIL_FAST=True

With fail_fast enabled by default (True) if there is an error when contacting the configuration server SystemExit(1) will be raised. And if the feature is disabled (False) an exception of the type ConnectionError is raised.

Standard output:

http://localhost:8888/master/myapp-development.json

The url pattern can be customize on constructor with parameter url.

from config.spring import ConfigClient

c = ConfigClient(
    app_name='myapp',
    url="{address}/{branch}/{profile}-{app_name}.yaml"
)
c.url
# OUTPUT: 'http://localhost:8888/master/development-myapp.json'

Default values

if no value was adjusted for the environment variables below, the default value will be assumed, as:

CONFIGSERVER_ADDRESS=http://localhost:8888
BRANCH=master
PROFILE=development
APP_NAME=
CONFIG_FAIL_FAST=True

Content-Type supported

  • JSON only

Notice

Looks that when request URL sent to Spring Cloud Config Server dosen't have a extension like .json, for example, the server don't load the profile appropriately. If you still want to disable automatic extension inclusion follow the steps reported in: issue-18 or follow steps below.

To reproduce this behavior can you use the docker-compose.yml and make a request to:

# loaded configuration without the appropriate profile
curl http://localhost:8888/master/simpleweb000-development

# loaded configuration with the correct profile
curl http://localhost:8888/master/simpleweb000-development.json 

Example with custom URL:

from config.spring import ConfigClient

c = ConfigClient(
    app_name='myapp',
    url="{address}/{branch}/{profile}-{app_name}.yaml"
)
c.url
# OUTPUT: 'http://localhost:8888/master/development-myapp.json'
c.url = c.url[:-5] # << split .json extension
print(c.url)
c.get_config() # returns: None. All the configuration will be available in the property: config.

Example with standard URL:

from config.spring import ConfigClient

c = ConfigClient(app_name='myapp')
c.url
# OUTPUT: 'http://localhost:8888/master/development-myapp.json'
c.url = c.url[:-5] # << split .json extension
print(c.url)
c.get_config() # returns: None. All the configuration will be available in the property: config.

Security

The config-client can interact with the Spring Cloud Config encryption and decryption API.

Encryption

# Default values
value = 
path = "/encrypt"
headers = {"Content-Type": "text/plain"}
**kwargs

Usage

from config.spring import ConfigClient

client = ConfigClient()
my_secret = client.encrypt('my_secret') # returns a str
print(my_secret)
# for example: a3c3333956a1ab2ade8b8219e36d0a4cb97d9a2789cbbcd858ea4ef3130563c6

Decryption

# Default values
value = 
path = "/decrypt"
headers = {"Content-Type": "text/plain"}
**kwargs

Usage

from config.spring import ConfigClient

client = ConfigClient()
my_secret = client.decrypt('a3c3333956a1ab2ade8b8219e36d0a4cb97d9a2789cbbcd858ea4ef3130563c6') # returns a str
print(my_secret)
# for example: my_secret