2024-06-03 08:42:38 +02:00
|
|
|
import os
|
2024-06-03 10:42:48 +02:00
|
|
|
import logging
|
2024-06-03 08:42:38 +02:00
|
|
|
|
2024-06-03 10:42:48 +02:00
|
|
|
from server_manager import ServerManager
|
|
|
|
from server_data import ServerData
|
2024-06-03 08:42:38 +02:00
|
|
|
|
2024-06-03 10:42:48 +02:00
|
|
|
def validate_env_vars():
|
2024-06-03 09:31:50 +02:00
|
|
|
api_key = os.getenv('API_KEY')
|
|
|
|
host = os.getenv('HOST')
|
|
|
|
if not api_key:
|
|
|
|
raise Exception('API_KEY not found in environment variables')
|
|
|
|
if not host:
|
|
|
|
raise Exception('HOST not found in environment variables')
|
2024-06-03 10:42:48 +02:00
|
|
|
return host, api_key
|
|
|
|
|
|
|
|
def main():
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
host, api_key = validate_env_vars()
|
2024-06-03 09:31:50 +02:00
|
|
|
|
2024-06-03 10:42:48 +02:00
|
|
|
server_data = ServerData()
|
|
|
|
post_data = server_data.create_post_data()
|
2024-06-03 09:31:50 +02:00
|
|
|
|
2024-06-03 10:42:48 +02:00
|
|
|
server_manager = ServerManager(host, api_key)
|
2024-06-03 09:31:50 +02:00
|
|
|
|
|
|
|
# Check if the server already exists
|
2024-06-03 10:42:48 +02:00
|
|
|
server_id = server_manager.existing_server_id(post_data)
|
2024-06-03 09:31:50 +02:00
|
|
|
|
|
|
|
# If the server exists, update it
|
|
|
|
if server_id:
|
2024-06-03 10:42:48 +02:00
|
|
|
logging.info('Server already exists with id: {}, Updating...'.format(server_id))
|
|
|
|
logging.info(server_manager.update_server(post_data, server_id))
|
2024-06-03 09:31:50 +02:00
|
|
|
else:
|
2024-06-03 10:42:48 +02:00
|
|
|
logging.info('Server does not exist, Creating...')
|
|
|
|
logging.info(server_manager.create_server(post_data))
|
2024-06-03 09:31:50 +02:00
|
|
|
|
2024-06-03 08:42:38 +02:00
|
|
|
if __name__ == '__main__':
|
2024-06-03 10:42:48 +02:00
|
|
|
main()
|