|
4 | 4 | import stat |
5 | 5 | import sys |
6 | 6 | import time |
7 | | -from datetime import datetime, timedelta |
| 7 | +from datetime import datetime, timedelta, timezone |
8 | 8 | from urllib.parse import parse_qs |
9 | 9 |
|
10 | 10 | import jwt |
@@ -91,35 +91,6 @@ def store_shared_access_key_for_case(self, case_uuid, token): |
91 | 91 | protect_token_cache(self._resource_id, ".sharedkey", case_uuid) |
92 | 92 | return |
93 | 93 |
|
94 | | - def cleanup_shared_keys(self): |
95 | | - tokendir = get_token_dir() |
96 | | - if not os.path.exists(tokendir): |
97 | | - return |
98 | | - for f in os.listdir(tokendir): |
99 | | - ff = os.path.join(tokendir, f) |
100 | | - if os.path.isfile(ff): |
101 | | - (name, ext) = os.path.splitext(ff) |
102 | | - if ext.lower() == ".sharedkey": |
103 | | - try: |
104 | | - with open(ff, "r") as file: |
105 | | - token = file.read() |
106 | | - pq = parse_qs(token) |
107 | | - se = pq["se"][0] |
108 | | - end = datetime.strptime( |
109 | | - se, "%Y-%m-%dT%H:%M:%S.%fZ" |
110 | | - ) |
111 | | - now = datetime.utcnow() |
112 | | - if now > end: |
113 | | - os.unlink(ff) |
114 | | - pass |
115 | | - pass |
116 | | - pass |
117 | | - except Exception: |
118 | | - pass |
119 | | - pass |
120 | | - pass |
121 | | - return |
122 | | - |
123 | 94 | def has_case_token(self, case_uuid): |
124 | 95 | return os.path.exists( |
125 | 96 | get_token_path(self._resource_id, ".sharedkey", case_uuid) |
@@ -487,3 +458,31 @@ def get_auth_provider( |
487 | 458 | ] |
488 | 459 | ): |
489 | 460 | return AuthProviderManaged(resource_id) |
| 461 | + |
| 462 | + |
| 463 | +def cleanup_shared_keys(): |
| 464 | + tokendir = get_token_dir() |
| 465 | + if not os.path.exists(tokendir): |
| 466 | + return |
| 467 | + for f in os.listdir(tokendir): |
| 468 | + ff = os.path.join(tokendir, f) |
| 469 | + if os.path.isfile(ff): |
| 470 | + (name, ext) = os.path.splitext(ff) |
| 471 | + if ext.lower() == ".sharedkey": |
| 472 | + try: |
| 473 | + with open(ff, "r") as file: |
| 474 | + token = file.read() |
| 475 | + pq = parse_qs(token) |
| 476 | + se = pq["se"][0] |
| 477 | + end = datetime.strptime(se, "%Y-%m-%dT%H:%M:%S.%fZ") |
| 478 | + now = datetime.now(timezone.utc) |
| 479 | + if now.timestamp() > end.timestamp(): |
| 480 | + os.unlink(ff) |
| 481 | + pass |
| 482 | + pass |
| 483 | + pass |
| 484 | + except Exception: |
| 485 | + pass |
| 486 | + pass |
| 487 | + pass |
| 488 | + return |
0 commit comments