|
@@ -8,16 +8,22 @@ def create_api_key_for_handlers():
|
|
api_key_list = []
|
|
api_key_list = []
|
|
|
|
|
|
for botname in BOTLIST:
|
|
for botname in BOTLIST:
|
|
- if not APIKey.objects.filter(name=botname).exists():
|
|
|
|
- api_key, key = APIKey.objects.create_key(name=botname)
|
|
|
|
- api_key_list.append([botname, key])
|
|
|
|
- print(f"Initial API Key for {botname} handler created.")
|
|
|
|
- else:
|
|
|
|
- print(f"Initial API Key for {botname} handler already exists.")
|
|
|
|
|
|
+ existing_keys = APIKey.objects.filter(name=botname, revoked=False)
|
|
|
|
+ if existing_keys.exists():
|
|
|
|
+ # Делаем все старые ключи для этого бота неактивными (revoked)
|
|
|
|
+ for old_key in existing_keys:
|
|
|
|
+ old_key.revoked = True
|
|
|
|
+ old_key.save()
|
|
|
|
+ print(f"Старые ключи для {botname} устарели (revoked).")
|
|
|
|
|
|
|
|
+ # Создаем новый ключ
|
|
|
|
+ api_key, key = APIKey.objects.create_key(name=botname)
|
|
|
|
+ api_key_list.append([botname, key])
|
|
|
|
+ print(f"Новый API Key для {botname} создан.")
|
|
|
|
+
|
|
|
|
+ # Формируем строки вида botname_key=ключ
|
|
api_key_list = list(map(lambda x: x[0] + '_key=' + x[1], api_key_list))
|
|
api_key_list = list(map(lambda x: x[0] + '_key=' + x[1], api_key_list))
|
|
txt = '\n'.join(api_key_list)
|
|
txt = '\n'.join(api_key_list)
|
|
|
|
|
|
with open('platform_running/handlers/.env', 'w') as f:
|
|
with open('platform_running/handlers/.env', 'w') as f:
|
|
f.write(txt)
|
|
f.write(txt)
|
|
-
|
|
|