Commit 2b6b9d20 authored by Julien Schröter's avatar Julien Schröter

Add endpoint providing version information

parent 29ed642f
......@@ -910,7 +910,36 @@ paths:
type: string
'500':
description: The server was unable to perform the requested operation.
'/version':
get:
summary: Get version information about the running server.
responses:
'200':
description: Version information about the running server.
content:
text/json:
schema:
type: object
required:
- identifier
- commit
- environment
- pipeline
- job
- built-on
properties:
identifier:
type: string
commit:
type: string
environment:
type: string
pipeline:
type: string
job:
type: string
built-on:
type: string
components:
parameters:
userid:
......
......@@ -11,6 +11,7 @@ import (
"gitlab.akamu.de/akamu/game-server-go/sendmail"
"gitlab.akamu.de/akamu/game-server-go/token/otp"
"gitlab.akamu.de/akamu/game-server-go/version"
"gitlab.akamu.de/akamu/game-server-go/schemas"
......@@ -239,6 +240,10 @@ func SetupRoutes(courseRepository course.CourseQuery, flashcardRepository flashc
}
})
router.GET("/version", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, version.Version)
})
usernameavailable.SetupUsernameavailableRoutes(router.Group("/usernameavailable"), userRepository)
user.SetupUserRoutes(authGroup.Group("/user"), userRepository, titleRepository)
flashcard.SetupFlashcardRoutes(authGroup.Group("/flashcard"), flashcardRepository)
......
package version
import (
"encoding/json"
"fmt"
)
// Identifier is a custom identifier for the current version/milestone. Do not overwrite the value.
var Identifier string = "unset" // $(< MILESTONE)
// Commit is the short sha hash for the current commit. Do not overwrite the value.
var Commit string = "unset" // $CI_COMMIT_SHORT_SHA
// Environment is the built branch. Do not overwrite value.
var Environment string = "unset" // $CI_COMMIT_REF_NAME
// Pipeline is the IID of the pipeline which built the project. Do not overwrite the value.
var Pipeline string = "unset" // $CI_PIPELINE_ID
// Job is the CI job which built the project. Do not overwrite the value.
var Job string = "unset" // $CI_JOB_ID
// BuiltOn is the time and date the project was built. Do not overwrite the value.
var BuiltOn string = "unset" // $(date)
// VersionType is a struct bundeling version information.
type VersionType struct {
Identifier string `json:"identifier"`
Commit string `json:"commit"`
Environment string `json:"environment"`
Pipeline string `json:"pipeline"`
Job string `json:"job"`
BuiltOn string `json:"built-on"`
}
// ToJSON returns a json representation of the version information.
func (v *VersionType) ToJSON() (string, error) {
b, err := json.Marshal(v)
if err != nil {
return "", fmt.Errorf("failed to provide version information: %v", err)
}
return string(b), nil
}
// Version is an instance of VersionType with the current version's information.
// Do not modify these values.
var Version VersionType = VersionType{
Identifier: Identifier,
Commit: Commit,
Environment: Environment,
Pipeline: Pipeline,
Job: Job,
BuiltOn: BuiltOn,
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment