diff --git a/cmd/console.go b/cmd/console.go index 6197a9d0..4fe95e64 100644 --- a/cmd/console.go +++ b/cmd/console.go @@ -60,6 +60,7 @@ manage collected flows.`, if err := ConsoleOptions.Parse(cmd.OutOrStdout(), "console", &config); err != nil { return err } + config.Console.Version = Version r, err := reporter.New(config.Reporting) if err != nil { diff --git a/console/config.go b/console/config.go index 564303a6..cd0686f1 100644 --- a/console/config.go +++ b/console/config.go @@ -3,13 +3,25 @@ package console +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + // Configuration describes the configuration for the console component. type Configuration struct { // ServeLiveFS serve files from the filesystem instead of the embedded versions. - ServeLiveFS bool + ServeLiveFS bool `yaml:"-"` + // Version is the version to display to the user. + Version string `yaml:"-"` } // DefaultConfiguration represents the default configuration for the console component. func DefaultConfiguration() Configuration { return Configuration{} } + +func (c *Component) configHandlerFunc(gc *gin.Context) { + gc.JSON(http.StatusOK, gin.H{"version": c.config.Version}) +} diff --git a/console/config_test.go b/console/config_test.go new file mode 100644 index 00000000..b16ec236 --- /dev/null +++ b/console/config_test.go @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2022 Free Mobile +// SPDX-License-Identifier: AGPL-3.0-only + +package console + +import ( + "testing" + + "github.com/gin-gonic/gin" + + "akvorado/common/helpers" +) + +func TestConfigHandler(t *testing.T) { + config := DefaultConfiguration() + config.Version = "1.2.3" + _, h, _, _ := NewMock(t, config) + helpers.TestHTTPEndpoints(t, h.Address, helpers.HTTPEndpointCases{ + { + URL: "/api/v0/console/configuration", + JSONOutput: gin.H{ + "version": "1.2.3", + }, + }, + }) +} diff --git a/console/frontend/src/App.vue b/console/frontend/src/App.vue index 5fb09906..2236f517 100644 --- a/console/frontend/src/App.vue +++ b/console/frontend/src/App.vue @@ -2,20 +2,22 @@ diff --git a/console/frontend/src/components/NavigationBar.vue b/console/frontend/src/components/NavigationBar.vue index ecad7a8f..386b9e54 100644 --- a/console/frontend/src/components/NavigationBar.vue +++ b/console/frontend/src/components/NavigationBar.vue @@ -11,13 +11,17 @@ Akvorado Logo - Akvorado + + Akvorado + + {{ serverConfiguration?.version }} + +
@@ -64,7 +68,7 @@ diff --git a/console/root.go b/console/root.go index 5583b2c6..29f77c5b 100644 --- a/console/root.go +++ b/console/root.go @@ -83,6 +83,7 @@ func (c *Component) Start() error { c.d.HTTP.AddHandler("/", netHTTP.HandlerFunc(c.assetsHandlerFunc)) endpoint := c.d.HTTP.GinRouter.Group("/api/v0/console", c.d.Auth.UserAuthentication()) + endpoint.GET("/configuration", c.configHandlerFunc) endpoint.GET("/docs/:name", c.docsHandlerFunc) endpoint.GET("/widget/flow-last", c.widgetFlowLastHandlerFunc) endpoint.GET("/widget/flow-rate", c.widgetFlowRateHandlerFunc)