This repository was archived by the owner on Feb 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcleanup_orphaned_accounts.py
More file actions
executable file
·95 lines (71 loc) · 2.37 KB
/
cleanup_orphaned_accounts.py
File metadata and controls
executable file
·95 lines (71 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
"""
Cleanup orphaned accounts from interrupted tests.
Usage:
python cleanup_orphaned_accounts.py
"""
import os
import json
from fxa.core import Client
from fxa.errors import ClientError, ServerError
ACCT_TRACKING_FILE = os.path.join(os.path.dirname(__file__), '.accounts_tracking.json')
FXA_API_HOST = os.environ.get("FXA_API_HOST", "https://api-accounts.stage.mozaws.net")
def load_tracked_accounts():
if not os.path.exists(ACCT_TRACKING_FILE):
return []
try:
with open(ACCT_TRACKING_FILE, 'r') as f:
return json.load(f)
except (json.JSONDecodeError, IOError) as e:
print(f"Warning: Could not load tracking file: {e}")
return []
def save_tracked_accounts(accounts):
try:
if not accounts:
if os.path.exists(ACCT_TRACKING_FILE):
os.remove(ACCT_TRACKING_FILE)
else:
with open(ACCT_TRACKING_FILE, 'w') as f:
json.dump(accounts, f, indent=2)
except IOError as e:
print(f"Warning: Could not save tracking file: {e}")
raise
def remove_account_from_tracking(email):
accounts = load_tracked_accounts()
accounts = [acc for acc in accounts if acc['email'] != email]
save_tracked_accounts(accounts)
def cleanup_account(client, account):
email = account['email']
password = account['password']
try:
client.destroy_account(email, password)
print(f" ✓ Deleted: {email}")
return True
except (ServerError, ClientError) as ex:
print(f" ✗ Delete failed: {email} - {ex}")
return False
except Exception as ex:
print(f" ✗ Delete error: {email} - {ex}")
return False
def cleanup_all_accounts():
accounts = load_tracked_accounts()
if not accounts:
print("No accounts to clean up.")
return 0, 0
print(f"\nFound {len(accounts)} accounts")
print("\nAttempting to delete accounts...\n")
client = Client(FXA_API_HOST)
successful = 0
failed = 0
for account in accounts:
if cleanup_account(client, account):
successful += 1
remove_account_from_tracking(account['email'])
else:
failed += 1
print(f"\nResults: {successful} deleted, {failed} failed")
return successful, failed
def main():
cleanup_all_accounts()
if __name__ == "__main__":
main()