Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: third_party/gsutil/third_party/boto/scripts/rebuild_endpoints.py

Issue 1377933002: [catapult] - Copy Telemetry's gsutilz over to third_party. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: Rename to gsutil. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/gsutil/third_party/boto/scripts/rebuild_endpoints.py
diff --git a/third_party/gsutil/third_party/boto/scripts/rebuild_endpoints.py b/third_party/gsutil/third_party/boto/scripts/rebuild_endpoints.py
new file mode 100644
index 0000000000000000000000000000000000000000..37ac37d80d9275cdd4021f18f62598968ea8a972
--- /dev/null
+++ b/third_party/gsutil/third_party/boto/scripts/rebuild_endpoints.py
@@ -0,0 +1,53 @@
+import json
+from pyquery import PyQuery as pq
+import requests
+
+
+class FetchError(Exception):
+ pass
+
+
+def fetch_endpoints():
+ # We utilize what the Java SDK publishes as a baseline.
+ resp = requests.get('https://raw2.github.com/aws/aws-sdk-java/master/src/main/resources/etc/regions.xml')
+
+ if int(resp.status_code) != 200:
+ raise FetchError("Failed to fetch the endpoints. Got {0}: {1}".format(
+ resp.status,
+ resp.body
+ ))
+
+ return resp.text
+
+
+def parse_xml(raw_xml):
+ return pq(raw_xml, parser='xml')
+
+
+def build_data(doc):
+ data = {}
+
+ # Run through all the regions. These have all the data we need.
+ for region_elem in doc('Regions').find('Region'):
+ region = pq(region_elem, parser='xml')
+ region_name = region.find('Name').text()
+
+ for endp in region.find('Endpoint'):
+ service_name = endp.find('ServiceName').text
+ endpoint = endp.find('Hostname').text
+
+ data.setdefault(service_name, {})
+ data[service_name][region_name] = endpoint
+
+ return data
+
+
+def main():
+ raw_xml = fetch_endpoints()
+ doc = parse_xml(raw_xml)
+ data = build_data(doc)
+ print(json.dumps(data, indent=4, sort_keys=True))
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « third_party/gsutil/third_party/boto/scripts/git-release-notes.py ('k') | third_party/gsutil/third_party/boto/setup.cfg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698