Skip to main content
Version: 4.x

API

Overview

The configuration center exposes an open API that returns the configuration of an application in a given environment.

Rules

The result is composed from:

  • all values of the application in the environment
  • all values of the applications it depends on
  • the values of the services it depends on
  • only values of the requested environment

Usage

The configuration is fetched over HTTP; two parameter sets are available depending on where the call is made.

Inside deploy hooks

  • URL: /api/apis/config/

  • Method: GET

  • Parameters:

    NameTypeRequiredDefaultExampleDescription
    apiTokenstringyes$SPUG_API_TOKENfixed value, a built-in global variable that only exists inside deploy hooks
    formatstringnokvjsonoutput format: kv, env or json, i.e. key = value, key=value or {"key": "value"}
    noPrefixstringno1by default keys are prefixed with the application or service identifier to avoid collisions; pass this parameter to disable the prefix
  • Example

    The screenshot below calls the API in Before deploy on host and stores the values of the application in a .env file.

    about

Tip

During builds and deployments the values are also injected as environment variables named _SPUG_ plus the upper-cased <identifier>_<key>, e.g. _SPUG_API_ORDER_DB_HOST, so hooks can use them without calling the API; run env | grep _SPUG_ to list them.

Standalone

  • URL: /api/apis/config/

  • Method: GET

  • Parameters:

    NameTypeRequiredDefaultExampleDescription
    apiKeystringyesJLV8IGO0DhoxcM7Ithe access token configured under System / Settings / Open Service Settings; keep it secret
    appstringyesorderidentifier of the application (shown on the application pages)
    envstringyesdevidentifier of the environment (shown under Config Center / Environments)
    formatstringnokvjsonoutput format: kv, env or json, i.e. key = value, key=value or {"key": "value"}
    noPrefixstringno1by default keys are prefixed with the application or service identifier to avoid collisions; pass this parameter to disable the prefix
  • Example 1

    curl "https://demo.spug.cc/api/apis/config/?apiKey=JLV8IGO0DhoxcM7I&app=order&env=test"

    Output:

    db_order_database = order
    db_order_host = 172.26.89.90
    db_order_password = 123456
    db_order_port = 3306
    db_order_username = root
    order_app_debug = true
    order_cache_driver = file
    order_url = http://test-order.internal.com
    redis_host = 127.0.0.1
    redis_password = 123456
  • Example 2

    curl "https://demo.spug.cc/api/apis/config/?apiKey=JLV8IGO0DhoxcM7I&app=order&env=test&noPrefix=1"

    Output:

    app_debug = true
    cache_driver = file
    database = order
    host = 127.0.0.1
    password = 123456
    port = 3306
    url = http://test-order.internal.com
    username = root
    Note

    Comparing the two outputs shows that in noPrefix mode the host and password values of the Order DB service (identifier db_order) were overwritten by the Redis service (identifier redis), so two values were lost.

Updating values from deploys

During the server-side stage of standard and custom deploys, exporting a SPUG_SET variable creates or updates a configuration value. The format is app-or-service-identifier:environment-identifier:key=value, for example:

export SPUG_SET="order:prod:release_version=$SPUG_VERSION"

The change is recorded in the configuration history, see Deploy configuration.