2022-04-12 11:21:55 +00:00
|
|
|
#!/usr/bin/env python3
|
2015-04-12 03:36:55 +00:00
|
|
|
|
2019-02-05 19:36:31 +00:00
|
|
|
import json
|
2015-04-12 03:36:55 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2022-04-12 21:07:40 +00:00
|
|
|
from urllib.request import Request, urlopen
|
2015-04-12 03:36:55 +00:00
|
|
|
|
2019-06-26 18:32:42 +00:00
|
|
|
sys.path.append(
|
|
|
|
os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../.."))
|
2019-06-24 17:18:04 +00:00
|
|
|
|
2022-04-04 09:32:57 +00:00
|
|
|
from lib.util import store_artifact, scoped_cwd, safe_mkdir, get_out_dir, \
|
|
|
|
ELECTRON_DIR
|
2015-04-12 03:36:55 +00:00
|
|
|
|
2018-09-27 05:50:01 +00:00
|
|
|
OUT_DIR = get_out_dir()
|
2015-04-12 03:36:55 +00:00
|
|
|
|
2018-08-17 22:49:12 +00:00
|
|
|
BASE_URL = 'https://electron-metadumper.herokuapp.com/?version='
|
2015-04-12 14:23:50 +00:00
|
|
|
|
2024-06-26 16:25:58 +00:00
|
|
|
AUTH_TOKEN = os.getenv('META_DUMPER_AUTH_HEADER')
|
2015-04-12 03:36:55 +00:00
|
|
|
|
2019-02-05 19:36:31 +00:00
|
|
|
def is_json(myjson):
|
|
|
|
try:
|
|
|
|
json.loads(myjson)
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2024-06-26 16:25:58 +00:00
|
|
|
def get_content(version, retry_count=5):
|
|
|
|
for attempt in range(retry_count):
|
|
|
|
try:
|
|
|
|
request = Request(
|
|
|
|
BASE_URL + version,
|
|
|
|
headers={"Authorization": AUTH_TOKEN}
|
|
|
|
)
|
|
|
|
|
|
|
|
with urlopen(request) as resp:
|
|
|
|
proposed_content = resp.read()
|
|
|
|
|
|
|
|
if is_json(proposed_content):
|
|
|
|
return proposed_content
|
|
|
|
|
|
|
|
print("Received content is not valid JSON.")
|
|
|
|
if attempt == retry_count - 1:
|
|
|
|
return None
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Attempt {attempt + 1} failed: {e}")
|
|
|
|
if attempt == retry_count - 1:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if attempt < retry_count - 1:
|
|
|
|
print("Retrying...")
|
|
|
|
|
|
|
|
return None
|
2018-08-21 20:29:44 +00:00
|
|
|
|
2015-04-12 03:36:55 +00:00
|
|
|
def main():
|
2024-06-26 16:25:58 +00:00
|
|
|
if not AUTH_TOKEN or AUTH_TOKEN == "":
|
2018-08-17 05:23:46 +00:00
|
|
|
raise Exception("Please set META_DUMPER_AUTH_HEADER")
|
2024-06-26 16:25:58 +00:00
|
|
|
|
|
|
|
if len(sys.argv) < 2 or not sys.argv[1]:
|
|
|
|
raise Exception("Version is required")
|
|
|
|
|
|
|
|
version = sys.argv[1]
|
|
|
|
|
2019-06-24 17:18:04 +00:00
|
|
|
with scoped_cwd(ELECTRON_DIR):
|
2018-08-17 05:23:46 +00:00
|
|
|
safe_mkdir(OUT_DIR)
|
2015-04-12 03:36:55 +00:00
|
|
|
index_json = os.path.relpath(os.path.join(OUT_DIR, 'index.json'))
|
2024-06-26 16:25:58 +00:00
|
|
|
new_content = get_content(version)
|
2018-08-17 05:23:46 +00:00
|
|
|
|
2024-06-26 16:25:58 +00:00
|
|
|
if new_content is None:
|
|
|
|
raise Exception("Failed to fetch valid JSON after maximum retries.")
|
2018-08-17 05:23:46 +00:00
|
|
|
|
2022-04-13 21:51:00 +00:00
|
|
|
with open(index_json, "wb") as f:
|
2018-08-17 05:23:46 +00:00
|
|
|
f.write(new_content)
|
2015-04-12 03:36:55 +00:00
|
|
|
|
2022-05-06 19:57:18 +00:00
|
|
|
store_artifact(OUT_DIR, 'headers/dist', [index_json])
|
2015-04-12 03:36:55 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|