API

Introduction

The configuration center provides an open interface to obtain the configuration of the application in a certain environment.

Rule

Application configuration will be obtained from the following sources and combined:

  • The public and private configurations of the application in the specified environment
  • The public configurations of the application that it depends on
  • The configuration of the service that it depends on
  • Read only the above configurations of the specified environment according to the specified environment

Get Way

The configuration is obtained by calling the interface, and there are two ways to pass the parameters according to the needs

Get config in the publishing configuration hook

  • Request Address: /api/apis/config/

  • Request Method: GET

  • Request Parameters:

    Parameter NameTypeRequiredDefault ValueExampleDescription
    apiTokenstringYes$SPUG_API_TOKENFixed value, built-in global variable in Spug, can only be referenced in the hook of publishing configuration
    formatstringNokvjsonThe format of the returned value, currently supports kv, env and json three formats, respectively corresponding to key = value, key=value and {“key”: “value”}, where env is newly added in v2.3.8
    noPrefixstringNo1Newly added in v2.3.8, the default key will add the label of the application or service as the prefix to ensure that there will be no same name key to cause the unexpected cover of the configuration, if you do not need this feature, you can pass this parameter to disable this default behavior
  • Example

    The following screenshot is calling the interface to get the configuration in the Application Release Before hook, and will save the configuration of this application in this environment in the .env file. about

Use alone

  • Request Address: /api/apis/config/

  • Request Method: GET

  • Request Parameters:

    Parameter NameTypeRequiredDefault ValueExampleDescription
    apiKeystringYesJLV8IGO0DhoxcM7IThe access credential for calling the interface, configured in the system management / system settings / open service settings of Spug, please do not disclose to others
    appstringYesorderSpecify the application whose configuration is to be obtained. The identifier (the identifier set when creating the application, please view the identifier of the application in the application management or application configuration page)
    envstringYesdevSpecify the identifier of the environment where the application is located (the identifier set when creating the environment, please view the environment identifier in the configuration center / environment management page)
    formatstringNokvjsonThe format of the returned value, currently supports kv, env and json three formats, respectively corresponding to key = value, key=value and {“key”: “value”}, where env is newly added in v2.3.8
    noPrefixstringNo1Newly added in v2.3.8, the default key will add the label of the application or service as the prefix to ensure that there will be no same name key to cause the unexpected cover of the configuration, if you do not need this feature, you can pass this parameter to disable this default behavior
  • Example 1

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

    Output as follows

    1. db_order_database = order
    2. db_order_host = 172.26.89.90
    3. db_order_password = 123456
    4. db_order_port = 3306
    5. db_order_username = root
    6. order_app_debug = true
    7. order_cache_driver = file
    8. order_url = http://test-order.internal.com
    9. redis_host = 127.0.0.1
    10. redis_password = 123456
  • Example 2

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

    Output as follows

    1. app_debug = true
    2. cache_driver = file
    3. database = order
    4. host = 127.0.0.1
    5. password = 123456
    6. port = 3306
    7. url = http://test-order.internal.com
    8. username = root

API - 图2Notes

that you can find that in the noPrefix mode, the configuration host and password of the service Order Master Database (identifier db_order) was covered by the service Redis Service (identifier redis). So the final configuration was accidentally lost two parameter.