Skip to content

Commit

Permalink
Merge branch 'dev' into feature/remove-unnecessary-api-and-stats-gene…
Browse files Browse the repository at this point in the history
…ral-create
  • Loading branch information
PlutoNbai committed Dec 5, 2023
2 parents 8050c5f + 0539399 commit 353272d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions backend/router/host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
""" Host information endpoint. """
import logging

from flask import Blueprint, jsonify, HTTPStatus, Response
import platform
import subprocess

host_bp = Blueprint("host_bp", __name__)


@host_bp.route('/host/info', methods=['GET'])
def get_host_info() -> tuple[Response, HTTPStatus]:
"""Retrieves information about the host system.
Args:
Returns:
tuple: A tuple containing the JSON response and HTTP status code.
Raises:
None
Example:
To retrieve host information, make a GET request to this endpoint.
"""
system = platform.system()
version = platform.version()
cpu = platform.processor()
hostname = platform.node()

# Retrieve the current version of the code from Git
try:
version_number = subprocess.check_output(["git", "describe", "--always"]).strip().decode()
except Exception as err:
logging.info(f"Error retrieving code version: {err}")
version_number = "N/A"

host_info = {
'system': system,
'version': version,
'cpu': cpu,
'hostname': hostname,
'code_version': version_number
}

return jsonify(host_info), HTTPStatus.OK

0 comments on commit 353272d

Please sign in to comment.