mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-15 07:20:17 +02:00
Use local swagger spec files (#866)
Allows auth to keep working if CCP changes "latest" definition. Requires adarnauth-esi>=1.4
This commit is contained in:
parent
9d90af4a3d
commit
eee6a9132d
@ -11,6 +11,10 @@ from corputils.managers import CorpStatsManager
|
|||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -41,7 +45,7 @@ class CorpStats(models.Model):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
try:
|
try:
|
||||||
c = self.token.get_esi_client(Character='v4', Corporation='v2')
|
c = self.token.get_esi_client(spec_file=SWAGGER_SPEC_PATH)
|
||||||
assert c.Character.get_characters_character_id(character_id=self.token.character_id).result()[
|
assert c.Character.get_characters_character_id(character_id=self.token.character_id).result()[
|
||||||
'corporation_id'] == int(self.corp.corporation_id)
|
'corporation_id'] == int(self.corp.corporation_id)
|
||||||
members = c.Corporation.get_corporations_corporation_id_members(
|
members = c.Corporation.get_corporations_corporation_id_members(
|
||||||
@ -52,7 +56,6 @@ class CorpStats(models.Model):
|
|||||||
# the swagger spec doesn't have a maxItems count
|
# the swagger spec doesn't have a maxItems count
|
||||||
# manual testing says we can do over 350, but let's not risk it
|
# manual testing says we can do over 350, but let's not risk it
|
||||||
member_id_chunks = [member_ids[i:i + 255] for i in range(0, len(member_ids), 255)]
|
member_id_chunks = [member_ids[i:i + 255] for i in range(0, len(member_ids), 255)]
|
||||||
c = self.token.get_esi_client(Character='v1') # ccplease bump versions of whole resources
|
|
||||||
member_name_chunks = [c.Character.get_characters_names(character_ids=id_chunk).result() for id_chunk in
|
member_name_chunks = [c.Character.get_characters_names(character_ids=id_chunk).result() for id_chunk in
|
||||||
member_id_chunks]
|
member_id_chunks]
|
||||||
member_list = {}
|
member_list = {}
|
||||||
|
1
corputils/swagger.json
Normal file
1
corputils/swagger.json
Normal file
File diff suppressed because one or more lines are too long
@ -12,6 +12,9 @@ from eveonline.models import EveCharacter, EveCorporationInfo
|
|||||||
from corputils.models import CorpStats
|
from corputils.models import CorpStats
|
||||||
from esi.decorators import token_required
|
from esi.decorators import token_required
|
||||||
from bravado.exception import HTTPError
|
from bravado.exception import HTTPError
|
||||||
|
import os
|
||||||
|
|
||||||
|
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
|
||||||
|
|
||||||
MEMBERS_PER_PAGE = int(getattr(settings, 'CORPSTATS_MEMBERS_PER_PAGE', 20))
|
MEMBERS_PER_PAGE = int(getattr(settings, 'CORPSTATS_MEMBERS_PER_PAGE', 20))
|
||||||
|
|
||||||
@ -41,9 +44,8 @@ def corpstats_add(request, token):
|
|||||||
if EveCharacter.objects.filter(character_id=token.character_id).exists():
|
if EveCharacter.objects.filter(character_id=token.character_id).exists():
|
||||||
corp_id = EveCharacter.objects.get(character_id=token.character_id).corporation_id
|
corp_id = EveCharacter.objects.get(character_id=token.character_id).corporation_id
|
||||||
else:
|
else:
|
||||||
corp_id = \
|
corp_id = token.get_esi_client(spec_file=SWAGGER_SPEC_PATH).Character.get_characters_character_id(
|
||||||
token.get_esi_client(Character='v4').Character.get_characters_character_id(character_id=token.character_id).result()[
|
character_id=token.character_id).result()['corporation_id']
|
||||||
'corporation_id']
|
|
||||||
corp = EveCorporationInfo.objects.get(corporation_id=corp_id)
|
corp = EveCorporationInfo.objects.get(corporation_id=corp_id)
|
||||||
cs = CorpStats.objects.create(token=token, corp=corp)
|
cs = CorpStats.objects.create(token=token, corp=corp)
|
||||||
try:
|
try:
|
||||||
|
@ -6,6 +6,9 @@ import json
|
|||||||
from bravado.exception import HTTPNotFound, HTTPUnprocessableEntity
|
from bravado.exception import HTTPNotFound, HTTPUnprocessableEntity
|
||||||
import evelink
|
import evelink
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -228,7 +231,7 @@ class EveProvider(object):
|
|||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class EveSwaggerProvider(EveProvider):
|
class EveSwaggerProvider(EveProvider):
|
||||||
def __init__(self, token=None, adapter=None):
|
def __init__(self, token=None, adapter=None):
|
||||||
self.client = esi_client_factory(token=token, Alliance='v2', Character='v4', Corporation='v2', Universe='v2')
|
self.client = esi_client_factory(token=token, spec_file=SWAGGER_SPEC_PATH)
|
||||||
self.adapter = adapter or self
|
self.adapter = adapter or self
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -237,7 +240,7 @@ class EveSwaggerProvider(EveProvider):
|
|||||||
def get_alliance(self, alliance_id):
|
def get_alliance(self, alliance_id):
|
||||||
try:
|
try:
|
||||||
data = self.client.Alliance.get_alliances_alliance_id(alliance_id=alliance_id).result()
|
data = self.client.Alliance.get_alliances_alliance_id(alliance_id=alliance_id).result()
|
||||||
corps = esi_client_factory(Alliance='v1').Alliance.get_alliances_alliance_id_corporations(alliance_id=alliance_id).result()
|
corps = self.client.Alliance.get_alliances_alliance_id_corporations(alliance_id=alliance_id).result()
|
||||||
model = Alliance(
|
model = Alliance(
|
||||||
self.adapter,
|
self.adapter,
|
||||||
alliance_id,
|
alliance_id,
|
||||||
|
1
eveonline/swagger.json
Normal file
1
eveonline/swagger.json
Normal file
File diff suppressed because one or more lines are too long
1
fleetactivitytracking/swagger.json
Normal file
1
fleetactivitytracking/swagger.json
Normal file
File diff suppressed because one or more lines are too long
@ -37,7 +37,7 @@
|
|||||||
<td class="text-center">{{ fat.user }}</td>
|
<td class="text-center">{{ fat.user }}</td>
|
||||||
<td class="text-center">{{ fat.character.character_name }}</td>
|
<td class="text-center">{{ fat.character.character_name }}</td>
|
||||||
{% if fat.station != "No Station" %}
|
{% if fat.station != "No Station" %}
|
||||||
<td class="text-center">{% blocktrans %}Docked in {{ fat.system }}{% endblocktrans %}</td>
|
<td class="text-center">{% blocktrans %}Docked in {% endblocktrans %}{{ fat.system }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="text-center">{{ fat.system }}</td>
|
<td class="text-center">{{ fat.system }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
<td class="text-center">{{ fat.fatlink.name }}</td>
|
<td class="text-center">{{ fat.fatlink.name }}</td>
|
||||||
<td class="text-center">{{ fat.character.character_name }}</td>
|
<td class="text-center">{{ fat.character.character_name }}</td>
|
||||||
{% if fat.station != "No Station" %}
|
{% if fat.station != "No Station" %}
|
||||||
<td class="text-center">{% blocktrans %}Docked in {{ fat.system }}{% endblocktrans %}</td>
|
<td class="text-center">{% blocktrans %}Docked in {% endblocktrans %}{{ fat.system }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="text-center">{{ fat.system }}</td>
|
<td class="text-center">{{ fat.system }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -16,16 +16,15 @@ from eveonline.managers import EveManager
|
|||||||
from authentication.models import AuthServicesInfo
|
from authentication.models import AuthServicesInfo
|
||||||
from fleetactivitytracking.forms import FatlinkForm
|
from fleetactivitytracking.forms import FatlinkForm
|
||||||
from fleetactivitytracking.models import Fatlink, Fat
|
from fleetactivitytracking.models import Fatlink, Fat
|
||||||
|
|
||||||
from esi.decorators import token_required
|
from esi.decorators import token_required
|
||||||
|
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
|
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -256,7 +255,7 @@ def click_fatlink_view(request, token, hash, fatname):
|
|||||||
|
|
||||||
if character:
|
if character:
|
||||||
# get data
|
# get data
|
||||||
c = token.get_esi_client(Location='v1', Universe='v2')
|
c = token.get_esi_client(spec_file=SWAGGER_SPEC_PATH)
|
||||||
location = c.Location.get_characters_character_id_location(character_id=token.character_id).result()
|
location = c.Location.get_characters_character_id_location(character_id=token.character_id).result()
|
||||||
ship = c.Location.get_characters_character_id_ship(character_id=token.character_id).result()
|
ship = c.Location.get_characters_character_id_ship(character_id=token.character_id).result()
|
||||||
location['solar_system_name'] = \
|
location['solar_system_name'] = \
|
||||||
@ -266,7 +265,6 @@ def click_fatlink_view(request, token, hash, fatname):
|
|||||||
location['station_name'] = \
|
location['station_name'] = \
|
||||||
c.Universe.get_universe_stations_station_id(station_id=location['station_id']).result()['name']
|
c.Universe.get_universe_stations_station_id(station_id=location['station_id']).result()['name']
|
||||||
elif location['structure_id']:
|
elif location['structure_id']:
|
||||||
c = token.get_esi_client(Universe='v1')
|
|
||||||
location['station_name'] = \
|
location['station_name'] = \
|
||||||
c.Universe.get_universe_structures_structure_id(structure_id=location['structure_id']).result()[
|
c.Universe.get_universe_structures_structure_id(structure_id=location['structure_id']).result()[
|
||||||
'name']
|
'name']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user