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
andprivate
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 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
,env
andjson
three formats, respectively corresponding tokey = value
,key=value
and{"key": "value"}
, whereenv
is newly added in v2.3.8noPrefix string No 1 Newly 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 namekey
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.
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
,env
andjson
three formats, respectively corresponding tokey = value
,key=value
and{"key": "value"}
, whereenv
is newly added in v2.3.8noPrefix string No 1 Newly 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 namekey
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
curl "https://demo.spug.cc/api/apis/config/?apiKey=JLV8IGO0DhoxcM7I&app=order&env=test"
Output as follows
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 = 123456Example 2
curl "https://demo.spug.cc/api/apis/config/?apiKey=JLV8IGO0DhoxcM7I&app=order&env=test&noPrefix=1"
Output as follows
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
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.