From 51f51b1e92a28a1a563ecf8fd09db9e930388f1d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 17 Sep 2020 21:09:22 +0200 Subject: [PATCH] get version of ereuse-tag --- .../resources/versions/versions.py | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/resources/versions/versions.py b/ereuse_devicehub/resources/versions/versions.py index 20052e44..17dea637 100644 --- a/ereuse_devicehub/resources/versions/versions.py +++ b/ereuse_devicehub/resources/versions/versions.py @@ -1,19 +1,35 @@ import flask import json +import requests import teal.marshmallow import pkg_resources from typing import Callable, Iterable, Tuple +from urllib.parse import urlparse from flask import make_response, g from teal.resource import Resource, View +from ereuse_devicehub.resources.inventory.model import Inventory + + +def get_tag_version(): + """Get version of microservice ereuse-tag.""" + path = "/versions/version/" + url = urlparse(Inventory.current.tag_provider.to_text())._replace(path=path) + res = requests.get(url.geturl()) + if res.status_code == 200: + return json.loads(res.content) + else: + return {} class VersionView(View): def get(self, *args, **kwargs): - """Get version.""" - - v = "{}".format(pkg_resources.require('ereuse-devicehub')[0].version) - return json.dumps({'devicehub': v}) + """Get version of DeviceHub and ereuse-tag.""" + dh_version = pkg_resources.require('ereuse-devicehub')[0].version + tag_version = get_tag_version() + versions = {'devicehub': dh_version} + versions.update(tag_version) + return json.dumps(versions) class VersionDef(Resource):