|
@@ -0,0 +1,24 @@
|
|
|
+from rest_framework_api_key.models import APIKey
|
|
|
+from webservice_running.handlers.config import BOTLIST
|
|
|
+
|
|
|
+
|
|
|
+def create_webservice_seed():
|
|
|
+ create_api_key_for_handlers()
|
|
|
+
|
|
|
+def create_api_key_for_handlers():
|
|
|
+ api_key_list = []
|
|
|
+
|
|
|
+ for botname in BOTLIST:
|
|
|
+ if not APIKey.objects.filter(name=f"api-key-for-{botname}").exists():
|
|
|
+ api_key, key = APIKey.objects.create_key(name=f"api-key-for-{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.")
|
|
|
+
|
|
|
+ api_key_list = list(map(lambda x: x[0] + '_key=' + x[1], api_key_list))
|
|
|
+ txt = '\n'.join(api_key_list)
|
|
|
+
|
|
|
+ with open('webservice_running/handlers/.env', 'w') as f:
|
|
|
+ f.write(txt)
|
|
|
+
|