Created
November 25, 2018 12:39
-
-
Save Luzifer/7ab435babf1b83e9eb4fed7daaa3d718 to your computer and use it in GitHub Desktop.
GCP Cloud-Function (PY3.7) to retrieve current Google Chrome version from official repo data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flask | |
import gzip | |
import json | |
import requests | |
import sys | |
import xml.etree.ElementTree as ET | |
REPO_URL = "https://dl.google.com/linux/chrome/rpm/stable/x86_64/repodata/other.xml.gz" | |
def fetch_repo(): | |
return ET.fromstring(gzip.decompress(requests.get(REPO_URL).content)) | |
def compile_versions(tree): | |
out = {} | |
for package in tree.findall('./{http://linux.duke.edu/metadata/other}package'): | |
if package.get('name', None) == None: | |
continue | |
v = package.find('./{http://linux.duke.edu/metadata/other}version') | |
if v.get('ver', None) == None: | |
continue | |
out[package.get('name')] = v.get('ver') | |
return out | |
def cloud_function_serve(request): | |
obj = compile_versions(fetch_repo()) | |
spath = request.path.strip('/') | |
if spath in obj: | |
resp = flask.Response(obj[spath]) | |
resp.headers['Content-Type'] = 'text/plain' | |
return resp | |
resp = flask.Response(json.dumps(obj)) | |
resp.headers['Content-Type'] = 'application/json' | |
return resp | |
def main(args): | |
obj = compile_versions(fetch_repo()) | |
if len(args) == 1 and args[0] in obj: | |
print(obj[args[0]]) | |
return | |
print(obj) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment