1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 15:57:14 +03:00

289 Commits

Author SHA1 Message Date
Athanasius
b40d3b889f
CAPI: Use CAPI-Live-<endpoint> game_version for market & shipyard 2022-12-01 16:42:05 +00:00
Athanasius
4b31b67042
CAPI: Only perform queries for Live galaxy.
* This is *temporary* pending properly implementing utilising the Legacy
  CAPI host.
* Check in the EDMarketConnector.EDApp.capi_request_data() function *and*
  also in some companion.session functions.  But not absolutely all possible
  entry points because we'll be undoing it when we implement Legacy support.

This *is* sufficient for the current core code entry points.  If any plugin
is invoking its own CAPI requests, well it shouldn't be.
2022-12-01 16:42:04 +00:00
Athanasius
bcabd97f4c
FDevIDs: Switch code to using FDevIDs/ files 2021-12-17 11:08:14 +00:00
Athanasius
4ab6d62926
user_agent: Set this once in config.py and use it everywhere
* Also flake8/mypy pass on timeout_session.py
2021-11-29 18:04:56 +00:00
Athanasius
b0b1ed589b
CAPI: Don't blindly dump r(equest.Response) on failure
Also explicitly logs the exception now.
2021-11-10 10:07:37 +00:00
Athanasius
6bec46be4e
CAPI: Implement a one-shot override of the Access Token
This allows you to force use of an expired token so as to test the code
paths for that without waiting up to 4 hours for the current one to
expire.

NB: The Access Token is *only* stored in the headers of the `requests`
object.
2021-11-06 10:41:33 +00:00
Athanasius
7a52ddd278
CAPI: Add retry of request after refreshing Access Token 2021-11-05 17:57:35 +00:00
Athanasius
8e32ecd216
CAPI: Actually try to use Refresh Token if CAPI says unauthorized
The refactor for threaded CAPI worker has inadvertently caused us to
always try *full* re-auth when the CAPI signals the Access Token is
expired.
2021-11-05 17:52:50 +00:00
Athanasius
1f7b0b7c0d
companion.py: Fix isort order complaint 2021-10-17 14:02:10 +01:00
A_D
5b68aad184
Remove protocol.protocolhandler singleton auto-init
In general, doing things like this on import is bad, but this was
changed specifically to remove a bug that causes
--force-localserver-auth to do nothing.

That is caused because while we were careful not to import protocol
until after we were done doing arg things, we did not check to make sure
something else didn't. Companion imports protocol, which thus always
instantiates WindowsProtocolHandler before we can modify some config
state to indicate that we want LinuxProtocolHandler.
2021-09-24 16:39:30 +02:00
Athanasius
796bb1f863
CAPI: Remove unuses Session.query/profile()
* Session.profile() was unused (used to be called from stats.py, but
  that uses cached data now).
* Session.query() was unused, other than by itself.  Normal calls will
  currently be via companion.Session.station().  Future CAPI queries
  like `/fleetcarrier` might add their own companion.Session function.
* And in doing so get --capi-pretend-down working again.
* Small tweak to EDMarketConnector to not throw extra exception if there
  was a CAPI query exception.
2021-08-31 14:08:15 +01:00
Athanasius
60379892ee
companion: DRY try/except of CAPI queries 2021-08-31 13:07:00 +01:00
Athanasius
af50a9f59d
companion: Make raw_data.__str__() a little less verbose
NB: We can't use a generator here to make a python object of the data,
to then use json.dumps() on because the raw_data is a *string* (decoded
from what we received from the CAPI service), and thus it will get
encoded as such, i.e.

  "raw_data": "{\"id\":322...

when we want:

  "raw_data": {"id":322...

We do not want to json.loads() that string only to then json.dumps() it
because the whole point is that this is the **raw** data to help
diagnose any issues with the CAPI service/data.  Such a conversion and
back could either throw an exception we don't want here (because we want
the raw data) or possibly distort things from what was actually
received.
2021-08-31 12:44:46 +01:00
Athanasius
bf33f88260
companion: Rename to capi_default_requests_timeout
So it doesn't even need a comment.
2021-08-31 12:10:59 +01:00
Athanasius
613a992ae9
companion: Change comments on CAPI cooldown/timeouts 2021-08-31 12:09:40 +01:00
Athanasius
67220fc96a
CAPI: Change CAPIDataRaw.__getitem__ to using __getitem__ itself
The only use of this is stats.py, and it explicitly checks for the key's
existence first.
2021-08-28 14:35:22 +01:00
Athanasius
74170da434
companion: Rename Session.session to requests_session
So as to avoid confusion with companion.session
2021-08-28 14:24:15 +01:00
Athanasius
6968cd6c69
companion: Rename Auth.session to requests_session
So as to not confuse with companion.session.
2021-08-28 14:18:49 +01:00
Athanasius
bc29891cc1
CAPI: Some notes in comments 2021-08-28 14:14:56 +01:00
Athanasius
12b1e9b7bc
CAPI: Add more trace_if('capi.worker', ...) to check timings
I keep observing it take 3-4s to update the UI after a manual CAPI
request.  This showed up as mostly *in*
AppWindow.capi_handle_response(), but the moment I ran it under PyCharm
profile that went down to 400ms.
2021-08-28 13:58:46 +01:00
Athanasius
206367505c
CAPI: Cleanup some (un)needed translations 2021-08-26 15:31:39 +01:00
Athanasius
ef32eb0140
CAPI: Remove un-needed check/setting of Session.retrying 2021-08-26 15:16:42 +01:00
Athanasius
cd6d22844b
CAPI: 'Need auth' is from 401 now, not a redirect 2021-08-26 15:15:36 +01:00
Athanasius
2179936d6f
CAPI: No need to handle HTTP 5xx specially
This will be handled by the `except HTTPError` above.
2021-08-26 15:14:52 +01:00
Athanasius
6c24d9291a
CAPI: EDMarketConnector: Don't Session.invalidate() on CredentialsError 2021-08-26 15:13:33 +01:00
Athanasius
0637873b91
CAPI: query error - Change JSON decode error message 2021-08-26 14:54:01 +01:00
Athanasius
a53858750c
CAPI: query errors: Continue taking auth-related reactions out 2021-08-26 14:52:47 +01:00
Athanasius
816384f16f
CAPI: Begin taking auth retries out of CAPI queries
* Only set/use retrying as companion.session.retrying (untested).
* Don't call Session.login() from CAPI query code, raise
  CredentialsError instead.
* Also don't Session.close() in CAPI query code.
2021-08-26 14:44:43 +01:00
Athanasius
303df05f2c
CAPI: Adjust 'requests.ConnectionError' logging
It was specifically implying DNS resolution issues, but this is far more
general than that.
2021-08-25 14:57:08 +01:00
Athanasius
baac45f5fe
CAPI: Some extra comments for fail/auth mess 2021-08-25 14:54:53 +01:00
Athanasius
2065721dd9
CAPI: Store request retrying in companion.session.retrying
The code was already referencing the latter, just we weren't setting it
from the request yet.
2021-08-25 14:47:15 +01:00
Athanasius
05a95fbac4
companion: Update WTF comment about login/beta
This is probably a left-over from the days of email+password login, not
wanting to send that to anything but live CAPI server ?
2021-08-25 14:23:14 +01:00
Athanasius
120414ac59
CAPI: Convert StatsDialog.showstats() to using cached CAPI data
This will just bail if no data has yet been received for /profile, but
that's the same behaviour as if we don't yet have `monitor.cmdr`.
2021-08-25 14:08:36 +01:00
Athanasius
7e1e35fd48
companion: Don't self.capi_response_queue.put() a tuple 2021-08-25 13:49:25 +01:00
Athanasius
6089dc6b0e
companion: Optional[bool], not Union & minor if formatting 2021-08-25 13:48:32 +01:00
Athanasius
a48c33eda8
companion: Change record_endpoint() query_time to mandatory
This *does* need to be generated as close as possible to where the data
was received, and not rely on an actually not dynamic default.
2021-08-25 13:45:42 +01:00
Athanasius
40a8a19ce4
CAPI: Use special EDMCCAPIRequest endpoint, not 'None' for worker shutdown 2021-08-25 12:14:33 +01:00
Athanasius
503658bf4e
companion: Correct Session.profile(query_time) default 2021-08-25 12:04:13 +01:00
Athanasius
26caf76cf4
CAPI: Declare request/response queue member types 2021-08-25 11:56:32 +01:00
Athanasius
027455984b
CAPI: EDMCCAPIFailedRequest itself, not inside a tuple
* Also str(e.args) when setting the message.
2021-08-25 11:53:04 +01:00
Athanasius
e1c6a0e9f8
CAPI: Create response queue in companion.Session
No need to create in callers and then use setter.
2021-08-25 11:50:56 +01:00
Athanasius
69d0d03b9b
CAPI: Rename to EDMCCAPIFailedRequest & comment queues
* The 'EDMC' prefix on all these classes is to make it clear they're for
  internal passing around of requests/responses, rather than holding the
  literal raw CAPI request and response.

* The request and response queues are now commented, including the
  detail that the response queue is created by the caller and then set
  'here' by Session.set_capi_response_queue().
2021-08-25 11:42:53 +01:00
Athanasius
2e27a2ba00
CAPIData: Make JSON encodable, and use that elsewhere
* It's no use `dict(CAPIData)` if that contains other `CAPIData`.  So,
  rather than write something to do that recursively just implement a
  simple JSON Encoder class and specify its use.
2021-08-24 13:22:13 +01:00
Athanasius
332d4cf975
CAPI: EDMC - converted to the queue request/response format 2021-08-24 12:56:12 +01:00
Athanasius
1dcefafc73
CAPI: Pass tk_response_event in Request to optionally use in response
EDMC.py will also need to make CAPI queries using the new threaded
method, but it has no tkinter, thus we need to pass in the event name
when we expect one to be generated, and only generate it if this is not
None.
2021-08-24 12:41:02 +01:00
Athanasius
1c93c3a9fa
CAPI: 'Save Raw Data' now using cached copy
It will write a file containing JSON that has a top level dict with a
key per endpoint we have data for, and within each of those a dict with
keys for query_time and the raw_data.

Everything from the opening `{` in that raw_data value until the
matching closing `}` is the raw data from the CAPI service.

The whole file happily goes through `jq -S -C '.'` to examine the
output.
2021-08-23 18:29:37 +01:00
Athanasius
c71fe042cd
companion: Saw *raw* copies of CAPI data
* Using global dict on class CAPIDataRaw as there should only ever be
  one of these.  *Any* querying of CAPI should record the response data
  in this single place.

* But as there'll be multiple endpoints recorded, class
  CAPIDataRawEndpoint uses instance variables.

* It is the raw string from
  `requests.Response.content.decode(encoding='utf-8')` that is recorded,
  not the result of JSON decoding.

* The recording happens in the worker capi_single_query() so it's as
  close as possible to where the data came back.  The query_time is
  allowed to take on the default utc_now() value, rather than matching
  the nominal query_time of the request as passed in.
2021-08-23 18:29:36 +01:00
Athanasius
d53b567fca
CAPI: s/querytime/query_time/ in variable names
But not in the config setting, as that would require a migration.
2021-08-23 18:29:36 +01:00
Athanasius
f80623e025
CAPI: Convert full Update flow to class passing
* Base the following on common EDMCCAPIReturn: EDMCFailedrequest,
  EDMCCAPIRequest, EDMCCAPIResponse.  This saves repeating a bunch of
  variable types and comments.
* Use the above throughout the 'Update' button flow.
* Still need to address 'Save Raw Data', i.e. AppWindow.save_raw().
2021-08-23 18:29:36 +01:00
Athanasius
c6f93bd3c6
companion: Update "close down" check for using EDMCAPIRequest 2021-08-23 18:29:36 +01:00