get version of ereuse-tag

This commit is contained in:
Cayo Puigdefabregas 2020-09-17 21:09:22 +02:00
parent 255701467a
commit 51f51b1e92
1 changed files with 20 additions and 4 deletions

View File

@ -1,19 +1,35 @@
import flask import flask
import json import json
import requests
import teal.marshmallow import teal.marshmallow
import pkg_resources import pkg_resources
from typing import Callable, Iterable, Tuple from typing import Callable, Iterable, Tuple
from urllib.parse import urlparse
from flask import make_response, g from flask import make_response, g
from teal.resource import Resource, View 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): class VersionView(View):
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
"""Get version.""" """Get version of DeviceHub and ereuse-tag."""
dh_version = pkg_resources.require('ereuse-devicehub')[0].version
v = "{}".format(pkg_resources.require('ereuse-devicehub')[0].version) tag_version = get_tag_version()
return json.dumps({'devicehub': v}) versions = {'devicehub': dh_version}
versions.update(tag_version)
return json.dumps(versions)
class VersionDef(Resource): class VersionDef(Resource):