diff --git a/README.md b/README.md index 55a0fd0..6ccba97 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## TODO -- [ ] Write code to upload to ftest server +- [x] Write code to upload to ftest server - [x] Package Docker container - [x] Upload to Docker Hub diff --git a/run.py b/run.py index c02f952..b6685cb 100755 --- a/run.py +++ b/run.py @@ -11,6 +11,7 @@ from urllib.parse import urlparse, urlunparse LOG_FILE = "webfinger.log" + def configure_logger(): logger = logging.getLogger("webfinger") logger.setLevel(logging.DEBUG) @@ -131,35 +132,26 @@ def test_access_control_allow_origin(resp): ), "Access-Control-Allow-Origin header should be '*' to allow any domain to access the resource with CORS. Please see https://www.rfc-editor.org/rfc/rfc7033.html#section-5" logger.info("[SUCESS] WebFinger endpoint is configured correctly for CORS") + def upload_logs_to_ftest(success: bool, logs: str): parsed_ftest_host = urlparse(FTEST_HOST) ftest = urlunparse( ( parsed_ftest_host.scheme, parsed_ftest_host.netloc, - "/suites//tests/results", - "", - "" + "/api/v1/results", "", + "" "", ) ) + logger.info("Uploading logs to ftest server {ftest}") + payload = {"success": success, "logs": logs, "auth": FTEST_AUTH} - raw_logs = "" - - with open(LOG_FILE) as log_file: - for line in log_file: - raw_logs += line - payload = { - "success": success, - "logs": logs, - "raw_logs": raw_logs, - } - - - res = requests.post(webfinger, headers={"Origin": "http://example.org"}) - - + res = requests.post( + FTEST_HOST, json=payload, headers={"Origin": "http://example.org"} + ) + logger.info("Upload successful") if __name__ == "__main__": @@ -226,3 +218,5 @@ if __name__ == "__main__": log = f"[FAIL] {test} failed with error:\n{error}\n-----\n" print(log) logs.append(log) + + upload_logs_to_ftest(success, logs)