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
publicandprivateconfigurations of the application in the specified environment - The
publicconfigurations 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 Name Type Required Default Value Example Description apiToken string Yes $SPUG_API_TOKEN Fixed value, built-in global variable in Spug, can only be referenced in the hook of publishing configurationformat string No kv json The format of the returned value, currently supports kv,envandjsonthree formats, respectively corresponding tokey = value,key=valueand{"key": "value"}, whereenvis newly added in v2.3.8noPrefix string No 1 Newly added in v2.3.8, the default keywill add the label of the application or service as the prefix to ensure that there will be no same namekeyto 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 Beforehook, and will save the configuration of this application in this environment in the.envfile.
Use alone
-
Request Address:
/api/apis/config/ -
Request Method:
GET -
Request Parameters:
Parameter Name Type Required Default Value Example Description apiKey string Yes JLV8IGO0DhoxcM7I The access credential for calling the interface, configured in the system management / system settings / open service settings of Spug, please do not disclose to othersapp string Yes order Specify 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) env string Yes dev Specify 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) format string No kv json The format of the returned value, currently supports kv,envandjsonthree formats, respectively corresponding tokey = value,key=valueand{"key": "value"}, whereenvis newly added in v2.3.8noPrefix string No 1 Newly added in v2.3.8, the default keywill add the label of the application or service as the prefix to ensure that there will be no same namekeyto 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
curl "https://demo.spug.cc/api/apis/config/?apiKey=JLV8IGO0DhoxcM7I&app=order&env=test"Output as follows
db_order_database = orderdb_order_host = 172.26.89.90db_order_password = 123456db_order_port = 3306db_order_username = rootorder_app_debug = trueorder_cache_driver = fileorder_url = http://test-order.internal.comredis_host = 127.0.0.1redis_password = 123456 -
Example 2
curl "https://demo.spug.cc/api/apis/config/?apiKey=JLV8IGO0DhoxcM7I&app=order&env=test&noPrefix=1"Output as follows
app_debug = truecache_driver = filedatabase = orderhost = 127.0.0.1password = 123456port = 3306url = http://test-order.internal.comusername = root
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.