Verified Commit d3d68943 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add /api/v0/version endpoint

parent 25c69858
Loading
Loading
Loading
Loading
+1 −0
Changes for .gitlab-ci.yml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ docker-build:
        - mkdir -p /kaniko/.docker
        - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    script:
        - echo "{\"commit\":\"$CI_COMMIT_SHA\",\"datetime\":\"$CI_COMMIT_TIMESTAMP\"}" > PORTAL_VERSION
        - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
    only:
        - master
+1 −0
Changes for portal/api/__init__.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
from .blueprint import bp
from .rest import *
from .version import *

portal/api/version.py

0 → 100644
+28 −0
Changes for portal/api/version.py: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
import json
from datetime import datetime
from pathlib import Path

from .blueprint import bp


@bp.get("/version")
def get_version():
    portal_version_path = Path("./PORTAL_VERSION")
    if portal_version_path.is_file():
        with open("PORTAL_VERSION") as f:
            version_info = json.load(f)
    else:
        version_info = {"datetime": datetime.now().isoformat()}

    return {
        "authors": [
            {
                "name": "Jakob Moser",
                "email": "moser@cl.uni-heidelberg.de",
                "role": "Maintainer",
            },
        ],
        "commit": version_info.get("commit"),
        "datetime": version_info["datetime"],
        "isDevelop": version_info.get("commit") is None,
    }
+60 −0
Changes for portal/static/docs/api/v0/openapi-spec.yaml: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -12,3 +12,63 @@ servers:
      description: Production server for Portal
    - url: http://localhost:5000/api/v0
      description: Development server on localhost
paths:
    /version:
        summary: Path used to get details about the version of this application.
        description: ""
        get:
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/ApplicationVersion"
                    description: Successful response - returns one `ApplicationVersion` entity.
            operationId: getApplicationVersion
            summary: Get the application version
            description:
                Get the (singleton) `ApplicationVersion` instance describing the
                version of this app.
components:
    schemas:
        ApplicationVersion:
            title: ApplicationVersion
            description: Version details about the application
            required:
                - isDevelop
                - datetime
                - authors
                - commit
            type: object
            properties:
                authors:
                    type: array
                    items:
                        type: object
                        properties:
                            name:
                                type: string
                            email:
                                type: string
                            role:
                                type: string
                commit:
                    type: string
                    nullable: true
                datetime:
                    format: date-time
                    description: The datetime of the build or the current datetime.
                    type: string
                isDevelop:
                    description:
                        Indicates if this is a development version or one that comes
                        from a built Docker image.
                    type: boolean
            example:
                authors:
                    - name: Max Mustermann
                      email: mustermann@mail.example
                      role: Maintainer
                commit: 9988d805651ce7d553ac8556eb52692953a19db5
                datetime: 2023-01-16T08:21:29+00:00
                isDevelop: false
 No newline at end of file