Created
October 15, 2020 00:50
-
-
Save jcjones/abe2f0ba63e502e35226171ff9d2a673 to your computer and use it in GitHub Desktop.
diff prod and stage onecrl work-in-progress buckets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rich.console import Console | |
from collections import defaultdict, Counter | |
import requests | |
console = Console() | |
def diff_entry(ident, prod, stage): | |
differences = 0 | |
for field in ["enabled", "issuerName", "serialNumber", "pubKeyHash", "subject"]: | |
if field not in prod and field not in stage: | |
continue | |
if prod[field] != stage[field]: | |
console.log(ident, f"Difference in {field}: {prod[field]} != {stage[field]}") | |
differences += 1 | |
for field in ["bug", "who", "why", "name"]: | |
if prod["details"][field] != stage["details"][field]: | |
console.log(ident, f"Difference in detail {field}: {prod['details'][field]} != {stage['details'][field]}") | |
differences += 1 | |
return differences | |
def get_id(entry): | |
if "issuerName" in entry and "serialNumber" in entry: | |
return f"{entry['issuerName']}-{entry['serialNumber']}" | |
if "pubKeyHash" in entry and "subject" in entry: | |
return f"{entry['pubKeyHash']}-{entry['subject']}" | |
breakpoint() | |
def diff_sets(counts, prod, stage): | |
ids = defaultdict(dict) | |
for entry in prod["data"]: | |
ident = get_id(entry) | |
ids[ident]["prod"] = entry | |
for entry in stage["data"]: | |
ident = get_id(entry) | |
ids[ident]["stage"] = entry | |
for ident, entry in ids.items(): | |
if "stage" not in entry or "prod" not in entry: | |
console.log(ident, entry) | |
if "stage" not in entry: | |
counts["not in stage"] += 1 | |
if "prod" not in entry: | |
counts["not in prod"] += 1 | |
else: | |
counts["diff found"] += diff_entry(ident, entry["prod"], entry["stage"]) | |
def get_records(service): | |
return requests.get(service + "/buckets/security-state-staging/collections/onecrl/records").json() | |
def main(): | |
counts = Counter() | |
stage_data = get_records("https://settings-writer.stage.mozaws.net/v1") | |
prod_data = get_records("https://settings-writer.prod.mozaws.net/v1") | |
diff_sets(counts, prod_data, stage_data) | |
console.print(counts) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment