def releasenotes_redirect(): """ View to redirect to https://wiki.ubuntu.com/ URLs for release notes. This used to be done in the Apache frontend, but that is going away to be replace by the content-cache. Old apache redirects: https://pastebin.canonical.com/p/3TXyyNkWkg/ """ version = flask.request.args.get("ver", "")[:5] for codename, release in Data().releases.items(): short_version = ".".join(release.version.split(".")[:2]) if version == short_version: release_slug = release.full_codename.replace(" ", "") return flask.redirect( f"https://wiki.ubuntu.com/{release_slug}/ReleaseNotes") return flask.redirect("https://wiki.ubuntu.com/Releases")
def notify_build(): """ An endpoint to trigger an update about a build event to be sent. This will usually be triggered by a webhook from Launchpad """ # Verify contents signature = hmac.new( flask.current_app.config["SECRET_KEY"].encode("utf-8"), flask.request.data, hashlib.sha1, ).hexdigest() if "X-Hub-Signature" not in flask.request.headers: return "No X-Hub-Signature provided\n", 403 if not hmac.compare_digest( signature, flask.request.headers["X-Hub-Signature"].split("=")[1] ): try: raise HTTPError(400) except HTTPError: flask.current_app.extensions["sentry"].captureException( extra={ "request_headers": str(flask.request.headers.keys()), "message": "x-hub-signature did not match", "expected_signature": signature, "header_contents": flask.request.headers[ "X-Hub-Signature" ], "extracted_signature": flask.request.headers[ "X-Hub-Signature" ].split("=")[1], } ) return "X-Hub-Signature does not match\n", 400 event_content = flask.request.json status = event_content["status"] build_url = ( "https://api.launchpad.net/devel" + event_content["livefs_build"] ) launchpad = Launchpad( username=os.environ["LAUNCHPAD_IMAGE_BUILD_USER"], token=os.environ["LAUNCHPAD_IMAGE_BUILD_TOKEN"], secret=os.environ["LAUNCHPAD_IMAGE_BUILD_SECRET"], session=session, auth_consumer=os.environ["LAUNCHPAD_IMAGE_BUILD_AUTH_CONSUMER"], ) build = launchpad.request(build_url).json() author_json = ( gnupg.GPG() .decrypt( build["metadata_override"]["_author_data"], passphrase=flask.current_app.config["SECRET_KEY"], ) .data ) if author_json: author = json.loads(author_json) else: return "_author_data could not be decoded\n", 400 email = author["email"] names = author["name"].split(" ") board = author["board"] snaps = ", ".join(build["metadata_override"]["extra_snaps"]) codename = build["distro_series_link"].split("/")[-1] version = Data().by_codename(codename).version arch = build["distro_arch_series_link"].split("/")[-1] build_link = build["web_link"] build_id = build_link.split("/")[-1] download_url = None if status == "Successfully built": download_url = launchpad.request( f"{build_url}?ws.op=getFileUrls" ).json()[0] session.post( "https://pages.ubuntu.com/index.php/leadCapture/save", data={ "FirstName": " ".join(names[:-1]), "LastName": names[-1] if len(names) > 1 else "", "Email": email, "formid": "3546", "lpId": "2154", "subId": "30", "munchkinId": "066-EOV-335", "imageBuilderVersion": version, "imageBuilderArchitecture": arch, "imageBuilderBoard": board, "imageBuilderSnaps": snaps, "imageBuilderID": build_id, "imageBuilderBuildlink": build_link, "imageBuilderStatus": status, "imageBuilderDownloadlink": download_url, }, ) return "Submitted\n", 202