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
|
|
|
|
2018-08-17 05:23:46 +00:00
|
|
|
version = sys.argv[1]
|
|
|
|
authToken = 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
|
|
|
|
|
2018-08-21 20:29:44 +00:00
|
|
|
def get_content(retry_count = 5):
|
|
|
|
try:
|
2022-04-12 21:07:40 +00:00
|
|
|
request = Request(
|
2018-08-21 20:29:44 +00:00
|
|
|
BASE_URL + version,
|
|
|
|
headers={"Authorization" : authToken}
|
|
|
|
)
|
|
|
|
|
2022-04-12 21:07:40 +00:00
|
|
|
proposed_content = urlopen(
|
2018-08-21 20:29:44 +00:00
|
|
|
request
|
|
|
|
).read()
|
2019-02-05 19:36:31 +00:00
|
|
|
|
|
|
|
if is_json(proposed_content):
|
|
|
|
return proposed_content
|
|
|
|
print("bad attempt")
|
|
|
|
raise Exception("Failed to fetch valid JSON from the metadumper service")
|
2018-08-21 20:29:44 +00:00
|
|
|
except Exception as e:
|
|
|
|
if retry_count == 0:
|
|
|
|
raise e
|
|
|
|
return get_content(retry_count - 1)
|
|
|
|
|
2015-04-12 03:36:55 +00:00
|
|
|
def main():
|
2018-08-17 05:23:46 +00:00
|
|
|
if not authToken or authToken == "":
|
|
|
|
raise Exception("Please set META_DUMPER_AUTH_HEADER")
|
2015-04-12 03:36:55 +00:00
|
|
|
# Upload the index.json.
|
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'))
|
2018-08-17 05:23:46 +00:00
|
|
|
|
2018-08-21 20:29:44 +00:00
|
|
|
new_content = get_content()
|
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())
|