• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / fx-private-relay / f186b7bc-dae5-4d16-b8f5-137c1242e750

08 May 2025 05:59PM CUT coverage: 85.213% (-0.03%) from 85.243%
f186b7bc-dae5-4d16-b8f5-137c1242e750

Pull #5550

circleci

groovecoder
fixup to test script removing a domain
Pull Request #5550: for MPP-3957: start update_fxrelay_allowlist_collection command

2468 of 3607 branches covered (68.42%)

Branch coverage included in aggregate %.

67 of 86 new or added lines in 3 files covered. (77.91%)

17384 of 19690 relevant lines covered (88.29%)

9.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.57
/privaterelay/management/commands/update_fxrelay_allowlist_collection.py
1
from django.conf import settings
1✔
2
from django.core.management.base import BaseCommand
1✔
3

4
from kinto_http import Client, KintoException
1✔
5
import requests
1✔
6

7
BUCKET = settings.KINTO_BUCKET
1✔
8
COLLECTION = settings.KINTO_COLLECTION
1✔
9

10

11
class Command(BaseCommand):
1✔
12
    help = "Updates the Firefox Relay allowlist Kinto collection from a JSON source."
1✔
13

14
    def handle(self, *args, **options):
1✔
15
        print(f"Connecting to ☁️ {settings.KINTO_SERVER}...")
1✔
16
        client = Client(server_url=settings.KINTO_SERVER, auth=settings.KINTO_AUTH_TOKEN)
1✔
17
        try:
1✔
18
            client.server_info()
1✔
19
            print("Connected to Kinto server successfully.")
1✔
NEW
20
        except Exception as e:
×
NEW
21
            self.stderr.write(f"❌ Failed to connect to Kinto server: {e}")
×
NEW
22
            return
×
23

24
        print(f"Ensuring 🪣 bucket {BUCKET} exists.")
1✔
25
        try:
1✔
26
            client.get_bucket(id=BUCKET)
1✔
27
            print(f"Bucket {BUCKET} already exists.")
1✔
NEW
28
        except KintoException:
×
NEW
29
            print(f"Bucket {BUCKET} not found. Creating...")
×
NEW
30
            try:
×
NEW
31
                client.create_bucket(id=BUCKET)
×
NEW
32
                print(f"Bucket {BUCKET} created.")
×
NEW
33
            except KintoException as e:
×
NEW
34
                self.stderr.write(f"❌ Failed to find or create bucket: {e}")
×
NEW
35
                return
×
36

37
        print(f"Ensuring 📁 collection {COLLECTION} exists.")
1✔
38
        try:
1✔
39
            client.get_collection(id=COLLECTION, bucket=BUCKET)
1✔
40
            print(f"Collection {COLLECTION} already exists.")
1✔
NEW
41
        except KintoException:
×
NEW
42
            print(f"Collection {COLLECTION} not found. Creating...")
×
NEW
43
            try:
×
NEW
44
                client.create_collection(id=COLLECTION, bucket=BUCKET)
×
NEW
45
                print(f"Collection {COLLECTION} created.")
×
NEW
46
            except KintoException as e:
×
NEW
47
                self.stderr.write(f"❌ Failed to find or create collection: {e}")
×
NEW
48
                return
×
49

50
        print(f"Loading new allowlist from 🌐 {settings.ALLOWLIST_JSON_INPUT_URL}.")
1✔
51
        response = requests.get(settings.ALLOWLIST_JSON_INPUT_URL)
1✔
52
        response.raise_for_status()
1✔
53
        new_allowlist = response.content.decode()
1✔
54

55
        new_domains = set(filter(None, new_allowlist.split("\n")))
1✔
56
        print(f"Parsed {len(new_domains)} from {settings.ALLOWLIST_JSON_INPUT_URL}.")
1✔
57

58
        print(f"Getting existing domain records from ☁️ {settings.KINTO_SERVER}, 🪣 bucket {BUCKET}, 📁 collection {COLLECTION}")
1✔
59
        existing_records = client.get_records(bucket=BUCKET, collection=COLLECTION)
1✔
60
        existing_domains = {rec['domain'] for rec in existing_records}
1✔
61
        print(f"Found {len(existing_domains)} existing domains.")
1✔
62

63
        # Delete records:
64
        # 1. no longer in the domain allowlist
65
        # 2. where id does not match domain
66
        for existing_record in existing_records:
1✔
67
            if (existing_record["domain"] not in new_domains or existing_record["domain"] != existing_record["id"]):
1!
68
                print(f'🗑 removed domain: {existing_record["domain"]}')
1✔
69
                client.delete_record(id=existing_record["id"], bucket=BUCKET, collection=COLLECTION)
1✔
70

71

72
        # Add new records for new domains in allowlist
73
        for domain in new_domains:
1✔
74
            if domain not in existing_domains:
1!
75
                print(f"✚ new domain: {domain}")
1✔
76
                record = {
1✔
77
                    "domain": domain,
78
                }
79
                client.create_record(id=domain, data=record, bucket=BUCKET, collection=COLLECTION)
1✔
80

81
        print("Allowlist synchronized 🔄 successfully. ✅")
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc