summaryrefslogtreecommitdiffstats
path: root/utils.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-12-04 11:25:42 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-12-04 11:29:48 +0100
commite54535129f23970619042a328ad9a139bba21c5d (patch)
tree14b8685078613fc9fd955465eca959d1480cd8cd /utils.go
parentdb05ee6a19f75e6fabaf8e6af09926edae554bc2 (diff)
Update connection options: --url/XDS_AGENT_URL and --url-server/XDS_SERVER_URL.
--url option (or XDS_AGENT_URL env var) must be used to setup connection with XDS agent running locally on developer host. --url-server (XDS_SERVER_URL env var) may be set to overwrite default connection settings with XDS server.
Diffstat (limited to 'utils.go')
-rw-r--r--utils.go36
1 files changed, 28 insertions, 8 deletions
diff --git a/utils.go b/utils.go
index f70d5da..d632415 100644
--- a/utils.go
+++ b/utils.go
@@ -20,28 +20,48 @@ package main
import (
"encoding/json"
+ "fmt"
+ "github.com/franciscocpg/reflectme"
"github.com/iotbzh/xds-agent/lib/xaapiv1"
"github.com/urfave/cli"
)
var cacheXdsVersion *xaapiv1.XDSVersion
+var cacheData = xaapiv1.XDSVersion{}
// XdsVersionGet Get version of XDS agent & server
func XdsVersionGet(ver *xaapiv1.XDSVersion) error {
- // Use cached data
- if cacheXdsVersion != nil {
- ver = cacheXdsVersion
- return nil
+ // Update cached data
+ if cacheXdsVersion == nil {
+ if err := HTTPCli.Get("/version", &cacheData); err != nil {
+ return err
+ }
}
+ reflectme.Copy(&cacheData, ver)
+ return nil
+}
+
+// XdsConfigGet Get current XDS Agent config
+func XdsConfigGet(cfg *xaapiv1.APIConfig) error {
+ return HTTPCli.Get("/config", cfg)
+}
- dataVer := xaapiv1.XDSVersion{}
- if err := HTTPCli.Get("/version", &dataVer); err != nil {
+// XdsConfigSet Set XDS Agent config
+func XdsConfigSet(cfg xaapiv1.APIConfig) error {
+ // clear cache
+ cacheXdsVersion = nil
+
+ newCfg := xaapiv1.APIConfig{}
+ if err := HTTPCli.Post("/config", cfg, &newCfg); err != nil {
return err
}
- cacheXdsVersion = &dataVer
- *ver = dataVer
+ idx := XdsServerIndexGet()
+ if !newCfg.Servers[idx].Connected {
+ return fmt.Errorf("XDS server %s still not connected", cfg.Servers[idx].URL)
+ }
+
return nil
}