From f84de2833865efe4f4a07b3f6c0fe05aa99c9e6f Mon Sep 17 00:00:00 2001 From: Basraah Date: Thu, 21 Sep 2017 14:56:21 +1000 Subject: [PATCH] Remove seat API sync --- allianceauth/services/modules/seat/manager.py | 74 ------------------- allianceauth/services/modules/seat/tasks.py | 6 -- 2 files changed, 80 deletions(-) diff --git a/allianceauth/services/modules/seat/manager.py b/allianceauth/services/modules/seat/manager.py index 3f97d61d..5ce3cb04 100644 --- a/allianceauth/services/modules/seat/manager.py +++ b/allianceauth/services/modules/seat/manager.py @@ -5,10 +5,6 @@ import string import requests from django.conf import settings -from django.core.cache import cache -from django.core.exceptions import ObjectDoesNotExist - -from allianceauth.eveonline.managers import EveManager logger = logging.getLogger(__name__) @@ -135,76 +131,6 @@ class SeatManager: seat_keys[key["key_id"]] = None return seat_keys - @classmethod - def synchronize_eveapis(cls, user=None): - - # Fetch all of the API keys stored in SeAT already - seat_all_keys = cls.get_all_seat_eveapis() - - # retrieve only user-specific api keys if user is specified - if user: - keypairs = EveManager.get_api_key_pairs(user) - else: - # retrieve all api keys instead - keypairs = EveManager.get_all_api_key_pairs() - - for keypair in keypairs: - # Transfer the key if it isn't already in SeAT - if keypair.api_id not in seat_all_keys.keys(): - # Add new keys - logger.debug("Adding Api Key with ID %s" % keypair.api_id) - try: - ret = cls.exec_request('key', 'post', - key_id=keypair.api_id, - v_code=keypair.api_key, - raise_for_status=True) - logger.debug(ret) - except requests.HTTPError as e: - if e.response.status_code == 400: - logger.debug("API key already exists") - else: - logger.exception("API key sync failed") - continue # Skip the rest of the key processing - else: - # remove it from the list so it doesn't get deleted in the last step - seat_all_keys.pop(keypair.api_id) - - # Attach API key to the users SeAT account, if possible - try: - userinfo = cache.get_or_set('seat_user_status_' + cls.username_hash(keypair.user.seat.username), - lambda: cls.check_user_status(keypair.user.seat.username), - 300) # Cache for 5 minutes - - if not bool(userinfo): - # No SeAT account, skip - logger.debug("Could not find users SeAT id, cannot assign key to them") - continue - - # If the user has activated seat, assign the key to them - logger.debug("Transferring Api Key with ID %s to user %s with ID %s " % ( - keypair.api_id, - keypair.user.seat.username, - userinfo['id'])) - ret = cls.exec_request('key/transfer/{}/{}'.format(keypair.api_id, userinfo['id']), - 'get') - logger.debug(ret) - except ObjectDoesNotExist: - logger.debug("User does not have SeAT activated, could not assign key to user") - - if bool(seat_all_keys) and not user and getattr(settings, 'SEAT_PURGE_DELETED', False): - # remove from SeAT keys that were removed from Auth - for key, key_user in seat_all_keys.items(): - # Remove the key only if it is an account or character key - ret = cls.exec_request('key/{}'.format(key), 'get') - logger.debug(ret) - try: - if (ret['info']['type'] == "Account") or (ret['info']['type'] == "Character"): - logger.debug("Removing api key %s from SeAT database" % key) - ret = cls.exec_request('key/{}'.format(key), 'delete') - logger.debug(ret) - except KeyError: - pass - @classmethod def get_all_roles(cls): groups = {} diff --git a/allianceauth/services/modules/seat/tasks.py b/allianceauth/services/modules/seat/tasks.py index 3e4eace1..fe1390bb 100644 --- a/allianceauth/services/modules/seat/tasks.py +++ b/allianceauth/services/modules/seat/tasks.py @@ -64,9 +64,3 @@ class SeatTasks: @staticmethod def deactivate(): SeatUser.objects.all().delete() - - @staticmethod - @app.task - def run_api_sync(): - logger.debug("Running EVE API synchronization with SeAT") - SeatManager.synchronize_eveapis()