7 "github.com/gin-gonic/gin"
8 "github.com/iotbzh/xds-agent/lib/xaapiv1"
9 "github.com/iotbzh/xds-agent/lib/xdsconfig"
10 common "github.com/iotbzh/xds-common/golib"
13 var confMut sync.Mutex
15 // GetConfig returns the configuration
16 func (s *APIService) getConfig(c *gin.Context) {
18 defer confMut.Unlock()
22 c.JSON(http.StatusOK, cfg)
25 // SetConfig sets configuration
26 func (s *APIService) setConfig(c *gin.Context) {
27 var cfgArg xaapiv1.APIConfig
28 if c.BindJSON(&cfgArg) != nil {
29 common.APIError(c, "Invalid arguments")
34 defer confMut.Unlock()
36 s.Log.Debugln("SET config: ", cfgArg)
38 // First delete/disable XDS Server that are no longer listed
39 for _, svr := range s.xdsServers {
41 for _, svrArg := range cfgArg.Servers {
42 if svr.ID == svrArg.ID {
48 s.DelXdsServer(svr.ID)
53 for _, svr := range cfgArg.Servers {
54 cfg := xdsconfig.XDSServerConf{
57 ConnRetry: svr.ConnRetry,
59 if _, err := s.AddXdsServer(cfg); err != nil {
60 common.APIError(c, err.Error())
65 c.JSON(http.StatusOK, s._getConfig())
68 func (s *APIService) _getConfig() xaapiv1.APIConfig {
69 cfg := xaapiv1.APIConfig{
70 Version: s.Config.Version,
71 APIVersion: s.Config.APIVersion,
72 VersionGitTag: s.Config.VersionGitTag,
73 Servers: []xaapiv1.ServerCfg{},
76 for _, svr := range s.xdsServers {
77 cfg.Servers = append(cfg.Servers, xaapiv1.ServerCfg{
81 PartialURL: svr.PartialURL,
82 ConnRetry: svr.ConnRetry,
83 Connected: svr.Connected,
84 Disabled: svr.Disabled,