diff --git a/Makefile b/Makefile index 4fc3154e..42318d25 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ GOFMT ?= gofmt -s GOFLAGS := -v -mod=vendor EXTRA_GOFLAGS ?= -LDFLAGS := -X "code.vikunja.io/api/pkg/cmd.Version=$(shell git describe --tags --always --abbrev=10 | sed 's/-/+/' | sed 's/^v//' | sed 's/-g/-/')" -X "main.Tags=$(TAGS)" +LDFLAGS := -X "code.vikunja.io/api/pkg/version.Version=$(shell git describe --tags --always --abbrev=10 | sed 's/-/+/' | sed 's/^v//' | sed 's/-g/-/')" -X "main.Tags=$(TAGS)" PACKAGES ?= $(filter-out code.vikunja.io/api/pkg/integrations,$(shell go list -mod=vendor ./... | grep -v /vendor/)) SOURCES ?= $(shell find . -name "*.go" -type f) @@ -187,13 +187,12 @@ do-the-swag: @hash swag > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ go install $(GOFLAGS) github.com/swaggo/swag/cmd/swag; \ fi - swag init -g pkg/routes/routes.go -s ./pkg/swagger; + swag init -g pkg/routes/routes.go -o ./pkg/swagger; # Fix the generated swagger file, currently a workaround until swaggo can properly use go mod - sed -i '/"definitions": {/a "code.vikunja.io.web.HTTPError": {"type": "object","properties": {"code": {"type": "integer"},"message": {"type": "string"}}},' docs/docs.go; - sed -i 's/code.vikunja.io\/web.HTTPError/code.vikunja.io.web.HTTPError/g' docs/docs.go; - sed -i 's/package\ docs/package\ swagger/g' docs/docs.go; - sed -i 's/` + \\"`\\" + `/` + "`" + `/g' docs/docs.go; - mv ./docs/docs.go ./pkg/swagger/docs.go; + sed -i '/"definitions": {/a "code.vikunja.io.web.HTTPError": {"type": "object","properties": {"code": {"type": "integer"},"message": {"type": "string"}}},' pkg/swagger/docs.go; + sed -i 's/code.vikunja.io\/web.HTTPError/code.vikunja.io.web.HTTPError/g' pkg/swagger/docs.go; + sed -i 's/package\ docs/package\ swagger/g' pkg/swagger/docs.go; + sed -i 's/` + \\"`\\" + `/` + "`" + `/g' pkg/swagger/docs.go; .PHONY: misspell-check misspell-check: diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index fd4668b1..87fbc95d 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -28,9 +28,6 @@ import ( "os" ) -// Version sets the version to be printed to the user. Gets overwritten by "make release" or "make build" with last git commit or tag. -var Version = "0.1" - func init() { cobra.OnInitialize(initialize) } diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 1f69cb5d..d4458039 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -17,6 +17,7 @@ package cmd import ( + "code.vikunja.io/api/pkg/version" "fmt" "github.com/spf13/cobra" ) @@ -29,6 +30,6 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of Vikunja", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Vikunja api version " + Version) + fmt.Println("Vikunja api version " + version.Version) }, } diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 6cd4cd73..4661006f 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -21,6 +21,7 @@ import ( "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/routes" "code.vikunja.io/api/pkg/swagger" + "code.vikunja.io/api/pkg/version" "context" "fmt" "github.com/spf13/cobra" @@ -39,10 +40,10 @@ var webCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // Version notification - fmt.Printf("Vikunja version %s\n", Version) + fmt.Printf("Vikunja version %s\n", version.Version) // Additional swagger information - swagger.SwaggerInfo.Version = Version + swagger.SwaggerInfo.Version = version.Version // Start the webserver e := routes.NewEcho() diff --git a/pkg/config/config.go b/pkg/config/config.go index 9dcd594f..2ae2541b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -40,6 +40,7 @@ const ( ServiceRootpath Key = `service.rootpath` ServicePageCount Key = `service.pagecount` ServiceEnableMetrics Key = `service.enablemetrics` + ServiceMotd Key = `service.motd` DatabaseType Key = `database.type` DatabaseHost Key = `database.host` @@ -133,6 +134,8 @@ func InitConfig() { ServiceRootpath.setDefault(exPath) ServicePageCount.setDefault(50) ServiceEnableMetrics.setDefault(false) + ServiceMotd.setDefault("") + // Database DatabaseType.setDefault("sqlite") DatabaseHost.setDefault("localhost") diff --git a/pkg/routes/api/v1/info.go b/pkg/routes/api/v1/info.go new file mode 100644 index 00000000..7adf3633 --- /dev/null +++ b/pkg/routes/api/v1/info.go @@ -0,0 +1,45 @@ +// Vikunja is a todo-list application to facilitate your life. +// Copyright 2019 Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package v1 + +import ( + "code.vikunja.io/api/pkg/config" + "code.vikunja.io/api/pkg/version" + "github.com/labstack/echo/v4" + "net/http" +) + +type vikunjaInfos struct { + Version string `json:"version"` + FrontendURL string `json:"frontend_url"` + Motd string `json:"motd"` +} + +// Info is the handler to get infos about this vikunja instance +// @Summary Info +// @Description Returns the version, frontendurl and motd of Vikunja +// @tags service +// @Produce json +// @Success 200 {object} v1.vikunjaInfos +// @Router /info [get] +func Info(c echo.Context) error { + return c.JSON(http.StatusOK, vikunjaInfos{ + Version: version.Version, + FrontendURL: config.ServiceFrontendurl.GetString(), + Motd: config.ServiceMotd.GetString(), + }) +} diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index aecf909c..953dda58 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -215,6 +215,9 @@ func registerAPIRoutes(a *echo.Group) { a.POST("/user/password/reset", apiv1.UserResetPassword) a.POST("/user/confirm", apiv1.UserConfirmEmail) + // Info endpoint + a.GET("/info", apiv1.Info) + // ===== Routes with Authetification ===== // Authetification a.Use(middleware.JWT([]byte(config.ServiceJWTSecret.GetString()))) diff --git a/pkg/swagger/docs.go b/pkg/swagger/docs.go index 6414851c..58be2dbb 100644 --- a/pkg/swagger/docs.go +++ b/pkg/swagger/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2019-06-04 19:35:31.322131656 +0200 CEST m=+0.130618199 +// 2019-07-16 00:32:48.008049583 +0200 CEST m=+0.169009519 package swagger @@ -30,6 +30,27 @@ var doc = `{ "host": "{{.Host}}", "basePath": "/api/v1", "paths": { + "/info": { + "get": { + "description": "Returns the version, frontendurl and motd of Vikunja", + "produces": [ + "application/json" + ], + "tags": [ + "service" + ], + "summary": "Info", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "$ref": "#/definitions/v1.vikunjaInfos" + } + } + } + } + }, "/labels": { "get": { "security": [ @@ -37,7 +58,7 @@ var doc = `{ "JWTKeyAuth": [] } ], - "description": "Returns all labels which are either created by the user or associated with a task the user has at least read-access to.", + "description": "Returns an array with all assignees for this task.", "consumes": [ "application/json" ], @@ -45,9 +66,9 @@ var doc = `{ "application/json" ], "tags": [ - "labels" + "assignees" ], - "summary": "Get all labels a user has access to", + "summary": "Get all assignees for a task", "parameters": [ { "type": "integer", @@ -57,18 +78,18 @@ var doc = `{ }, { "type": "string", - "description": "Search labels by label text.", + "description": "Search assignees by their username.", "name": "s", "in": "query" } ], "responses": { "200": { - "description": "The labels", + "description": "The assignees", "schema": { "type": "array", "items": { - "$ref": "#/definitions/models.Label" + "$ref": "#/definitions/models.User" } } }, @@ -3984,7 +4005,7 @@ var doc = `{ "description": "A unix timestamp when this relation was last updated. You cannot change this value.", "type": "integer" }, - "username": { + "userID": { "description": "The username.", "type": "string" } @@ -4414,6 +4435,20 @@ var doc = `{ "type": "string" } } + }, + "v1.vikunjaInfos": { + "type": "object", + "properties": { + "frontend_url": { + "type": "string" + }, + "motd": { + "type": "string" + }, + "version": { + "type": "string" + } + } } }, "securityDefinitions": { diff --git a/pkg/swagger/swagger.json b/pkg/swagger/swagger.json index 6913f28c..15bca1d5 100644 --- a/pkg/swagger/swagger.json +++ b/pkg/swagger/swagger.json @@ -17,6 +17,27 @@ "host": "{{.Host}}", "basePath": "/api/v1", "paths": { + "/info": { + "get": { + "description": "Returns the version, frontendurl and motd of Vikunja", + "produces": [ + "application/json" + ], + "tags": [ + "service" + ], + "summary": "Info", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "$ref": "#/definitions/v1.vikunjaInfos" + } + } + } + } + }, "/labels": { "get": { "security": [ @@ -24,7 +45,7 @@ "JWTKeyAuth": [] } ], - "description": "Returns all labels which are either created by the user or associated with a task the user has at least read-access to.", + "description": "Returns an array with all assignees for this task.", "consumes": [ "application/json" ], @@ -32,9 +53,9 @@ "application/json" ], "tags": [ - "labels" + "assignees" ], - "summary": "Get all labels a user has access to", + "summary": "Get all assignees for a task", "parameters": [ { "type": "integer", @@ -44,18 +65,18 @@ }, { "type": "string", - "description": "Search labels by label text.", + "description": "Search assignees by their username.", "name": "s", "in": "query" } ], "responses": { "200": { - "description": "The labels", + "description": "The assignees", "schema": { "type": "array", "items": { - "$ref": "#/definitions/models.Label" + "$ref": "#/definitions/models.User" } } }, @@ -3970,7 +3991,7 @@ "description": "A unix timestamp when this relation was last updated. You cannot change this value.", "type": "integer" }, - "username": { + "userID": { "description": "The username.", "type": "string" } @@ -4400,6 +4421,20 @@ "type": "string" } } + }, + "v1.vikunjaInfos": { + "type": "object", + "properties": { + "frontend_url": { + "type": "string" + }, + "motd": { + "type": "string" + }, + "version": { + "type": "string" + } + } } }, "securityDefinitions": { diff --git a/pkg/swagger/swagger.yaml b/pkg/swagger/swagger.yaml index 0d7a6ec6..f8c2c000 100644 --- a/pkg/swagger/swagger.yaml +++ b/pkg/swagger/swagger.yaml @@ -312,7 +312,7 @@ definitions: description: A unix timestamp when this relation was last updated. You cannot change this value. type: integer - username: + userID: description: The username. type: string type: object @@ -658,6 +658,15 @@ definitions: old_password: type: string type: object + v1.vikunjaInfos: + properties: + frontend_url: + type: string + motd: + type: string + version: + type: string + type: object host: '{{.Host}}' info: contact: @@ -677,19 +686,32 @@ info: title: Vikunja API version: '{{.Version}}' paths: + /info: + get: + description: Returns the version, frontendurl and motd of Vikunja + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.vikunjaInfos' + type: object + summary: Info + tags: + - service /labels: get: consumes: - application/json - description: Returns all labels which are either created by the user or associated - with a task the user has at least read-access to. + description: Returns an array with all assignees for this task. parameters: - description: The page number. Used for pagination. If not provided, the first page of results is returned. in: query name: p type: integer - - description: Search labels by label text. + - description: Search assignees by their username. in: query name: s type: string @@ -697,10 +719,10 @@ paths: - application/json responses: "200": - description: The labels + description: The assignees schema: items: - $ref: '#/definitions/models.Label' + $ref: '#/definitions/models.User' type: array "500": description: Internal error @@ -709,9 +731,9 @@ paths: type: object security: - JWTKeyAuth: [] - summary: Get all labels a user has access to + summary: Get all assignees for a task tags: - - labels + - assignees put: consumes: - application/json diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 00000000..5dda611f --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,23 @@ +// Vikunja is a todo-list application to facilitate your life. +// Copyright 2019 Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package version + +// This package holds the version info +// It is an own package to avoid import cycles + +// Version sets the version to be printed to the user. Gets overwritten by "make release" or "make build" with last git commit or tag. +var Version = "0.7"