summaryrefslogtreecommitdiffstats
path: root/recipes-sota/aktualizr/garage-sign-version.inc
blob: f2d04e8ef57464021ed740073e63b2f18668404a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
python () {
    if d.getVar("GARAGE_SIGN_VERSION", True) or not d.getVar("SOTA_PACKED_CREDENTIALS", True):
        return
    import json
    import urllib.request
    import zipfile
    with zipfile.ZipFile(d.getVar("SOTA_PACKED_CREDENTIALS", True), 'r') as zip_ref:
        try:
            with zip_ref.open('tufrepo.url', mode='r') as url_file:
                url = url_file.read().decode().strip(' \t\n') + '/health/version'
        except (KeyError, ValueError, RuntimeError):
            return
    r = urllib.request.urlopen(url)
    if r.code != 200:
        return
    resp = r.read().decode('utf-8')
    j = json.loads(resp)
    version = 'cli-' + j['version'] + '.tgz'
    d.setVar("GARAGE_SIGN_VERSION", version)
}

# vim:set ts=4 sw=4 sts=4 expandtab: