/info endpoint (#85)
continuous-integration/drone/push Build is passing Details

This commit is contained in:
konrad 2019-07-15 22:54:38 +00:00 committed by Gitea
parent c3ea45d900
commit e2d9de191d
11 changed files with 200 additions and 36 deletions

View File

@ -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:

View File

@ -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)
}

View File

@ -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)
},
}

View File

@ -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()

View File

@ -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")

45
pkg/routes/api/v1/info.go Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
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(),
})
}

View File

@ -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())))

View File

@ -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": {

View File

@ -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": {

View File

@ -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

23
pkg/version/version.go Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
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"