diff --git a/api/swagger.yaml b/api/swagger.yaml index e611aa7..2cda377 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -106,6 +106,20 @@ paths: "204": description: Everything okay + /version: + get: + summary: Retrieve the version of Poseidon + description: Return hash-like release information. + tags: + - miscellaneous + responses: + "200": + description: The release information could be returned. + "404": + $ref: "#/components/responses/NotFound" + "500": + $ref: "#/components/responses/InternalServerError" + /runners: post: summary: Provide a runner diff --git a/configuration.example.yaml b/configuration.example.yaml index 29823ed..435760c 100644 --- a/configuration.example.yaml +++ b/configuration.example.yaml @@ -53,3 +53,6 @@ sentry: dsn: https://example.io # The environment to be sent with events. # environment: staging + # This release information is used by Poseidon to provide the version route. + # Normally it is set by the deployment process. + # release: this is replaced in the deployment process diff --git a/internal/api/api.go b/internal/api/api.go index b77f970..f0a8926 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -3,6 +3,7 @@ package api import ( "github.com/gorilla/mux" "github.com/openHPI/poseidon/internal/api/auth" + "github.com/openHPI/poseidon/internal/config" "github.com/openHPI/poseidon/internal/environment" "github.com/openHPI/poseidon/internal/runner" "github.com/openHPI/poseidon/pkg/logging" @@ -14,6 +15,7 @@ var log = logging.GetLogger("api") const ( BasePath = "/api/v1" HealthPath = "/health" + VersionPath = "/version" RunnersPath = "/runners" EnvironmentsPath = "/execution-environments" ) @@ -40,6 +42,7 @@ func configureV1Router(router *mux.Router, runnerManager runner.Manager, environ }) v1 := router.PathPrefix(BasePath).Subrouter() v1.HandleFunc(HealthPath, Health).Methods(http.MethodGet) + v1.HandleFunc(VersionPath, Version).Methods(http.MethodGet) runnerController := &RunnerController{manager: runnerManager} environmentController := &EnvironmentController{manager: environmentManager} @@ -59,3 +62,14 @@ func configureV1Router(router *mux.Router, runnerManager runner.Manager, environ configureRoutes(v1) } } + +// Version handles the version route. +// It responds the release information stored in the configuration. +func Version(writer http.ResponseWriter, _ *http.Request) { + release := config.Config.Sentry.Release + if len(release) > 0 { + sendJSON(writer, release, http.StatusOK) + } else { + writer.WriteHeader(http.StatusNotFound) + } +}