6 "github.com/iotbzh/xds-agent/lib/apiv1"
7 "github.com/urfave/cli"
10 var cacheXdsVersion *apiv1.XDSVersion
12 // XdsVersionGet Get version of XDS agent & server
13 func XdsVersionGet(ver *apiv1.XDSVersion) error {
15 if cacheXdsVersion != nil {
20 dataVer := apiv1.XDSVersion{}
21 if err := HTTPCli.Get("/version", &dataVer); err != nil {
25 cacheXdsVersion = &dataVer
30 // XdsServerIDGet returns the XDS Server ID
31 func XdsServerIDGet() string {
32 ver := apiv1.XDSVersion{}
33 if err := XdsVersionGet(&ver); err != nil {
36 if len(ver.Server) < 1 {
39 return ver.Server[XdsServerIndexGet()].ID
42 // XdsServerIndexGet returns the index number of XDS Server
43 func XdsServerIndexGet() int {
44 // FIXME support multiple server
48 // ProjectsListGet Get the list of existing projects
49 func ProjectsListGet(prjs *[]apiv1.ProjectConfig) error {
51 if err := HTTPCli.HTTPGet("/projects", &data); err != nil {
54 Log.Debugf("Result of /projects: %v", string(data[:]))
56 return json.Unmarshal(data, &prjs)
59 // LogPost Helper to log a POST request
60 func LogPost(format string, data interface{}) {
61 b, _ := json.Marshal(data)
62 Log.Infof(format, string(b))
65 // GetID Return a string ID set with --id option or as simple parameter
66 func GetID(ctx *cli.Context) string {
67 id := ctx.String("id")
68 idArgs := ctx.Args().First()
69 if id == "" && idArgs != "" {