Skip to content

Commit

Permalink
build: ensure index.json is actually valid JSON before uploading (bac…
Browse files Browse the repository at this point in the history
…kport: 4-0-x) (#16750)

* build: ensure index.json is actually valid JSON before uploading

* chore: fix py linting for validation of index.json
  • Loading branch information
trop[bot] authored and MarshallOfSound committed Feb 5, 2019
1 parent 8054fc8 commit cbca75d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion script/upload-index-json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import json
import os
import sys
import urllib2
Expand All @@ -15,16 +16,28 @@
version = sys.argv[1]
authToken = os.getenv('META_DUMPER_AUTH_HEADER')

def is_json(myjson):
try:
json.loads(myjson)
except ValueError:
return False
return True

def get_content(retry_count = 5):
try:
request = urllib2.Request(
BASE_URL + version,
headers={"Authorization" : authToken}
)

return urllib2.urlopen(
proposed_content = urllib2.urlopen(
request
).read()

if is_json(proposed_content):
return proposed_content
print("bad attempt")
raise Exception("Failed to fetch valid JSON from the metadumper service")
except Exception as e:
if retry_count == 0:
raise e
Expand Down

0 comments on commit cbca75d

Please sign in to comment.