Commit Graph
3979 Commits
Author SHA1 Message Date
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 885745197c CAPI: EDMarketConnector: Set status text on ServerConnectionError 2021-08-26 15:00:16 +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 0456996cdd EDMarketConnector: Save querytime to config *before* triggering API 2021-08-25 11:36:39 +01:00
Athanasius dad2f95f64 EDMarketConnector: Correct arg to tk overrideredirect to bool 2021-08-25 11:34:51 +01:00
Athanasius 5710f3fd61 CAPI: Only import queue in EDMarketConnector.py 2021-08-25 11:33:52 +01:00
Athanasius 030d79c9da EDMC: De-indent CAPI response checks 2021-08-25 11:31:08 +01:00
Athanasius 4397acc6fb CAPI: Status text when aborting due to CQC (& en.template updated) 2021-08-24 14:06:12 +01:00
Athanasius c9d478222a EDMC: Provide EDDN Odyssey flag from monitor state
This should have been set from the latest Journal file, and the
key/value is in LoadGame in Odyssey.  It's only documented as:

	"Whether the sending Cmdr has an Odyssey expansion."

in the current EDDN Journal schema.  Thus sending this as False if the
Cmdr last logged into Horizons/base game should be OK.
2021-08-24 13:52:48 +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 f12b8be74c EDMC: Fix -d file export of CAPI data 2021-08-24 13:04:25 +01:00
Athanasius 332d4cf975 CAPI: EDMC - converted to the queue request/response format 2021-08-24 12:56:12 +01:00
Athanasius 3df688ecd4 CAPI: Pass in that tk_response_event from AppWindow.capi_request_data() 2021-08-24 12:43:33 +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
Athanasius dc705b92e5 companion: Convert to EDMCCAPIRequest class, not bare tuple 2021-08-23 18:29:36 +01:00
Athanasius 92e3ce9f4b CAPI: Notes/dummy classes for using them to encapsulate requests/responses 2021-08-23 18:29:35 +01:00
Athanasius 8d7072fda4 stats.py: TODO: Use cached /profile CAPI data when available 2021-08-23 18:29:35 +01:00
Athanasius 3f817c0fc0 companion: TODO: store /profile data for use elsewhere 2021-08-23 18:29:35 +01:00
Athanasius e5d200311e companion: mypy pass
* Still need to change stats.py to use a cached copy of CAPI data,
  rather than it querying that itself.  That means actually storing that
  cached copy whilst in the capi worker.
2021-08-23 18:29:35 +01:00
Athanasius 62b1f0dd0d companion: flake8 pass 2021-08-23 18:29:35 +01:00
Athanasius c1deb9113e CAPI: 'station' query going via work queue
* Defined inner functions in the worker function to handle the actual
  queries.  This allows for *them* to simply return data or raise
  exceptions to be caught by the main worker function.  *IT* then
  handles returning any error appropriately via the queue to AppWindow.

* Due to the coupling between AppWindow and these queries there are
  several extra parameters passed into the queue worker and then back
  out.  This is largely due to having to split AppWindow.getandsend()
  into two functions: capi_request_data() and capi_handle_response().

  This might get changed to use a class to encapsulate those values,
  rather than the bare tuple currently being used.

* No full flake8 & mypy pass done yet.

* Some companion.py globals renamed so their use is more obvious.
2021-08-23 18:29:34 +01:00
Athanasius 3fe097a955 companion: Start moving CAPI 'station' query into thread worker 2021-08-23 18:29:34 +01:00
Athanasius 305ba157ec companion: s/URL_SHIPYARD/Session.FRONTIER_CAPI_PATH_SHIPYARD/g 2021-08-23 18:29:34 +01:00
Athanasius 58ea0abd5e companion: s/URL_MARKET/Session.FRONTIER_CAPI_PATH_MARKET/g 2021-08-23 18:29:34 +01:00
Athanasius 6f9f71d699 companion: s/FRONTIER_PATH/FRONTIER_AUTH_PATH/g
This is so as to keep Frontier *auth* separate from Frontier *CAPI*.
2021-08-23 18:29:34 +01:00
Athanasius 661ffb100b companion: URL_DECODE -> Auth.FRONTIER_PATH_DECODE 2021-08-23 18:29:33 +01:00
Athanasius 52a6eeb82a companion: URL_TOKEN -> Auth.FRONTIER_PATH_TOKEN
Also, rename FRONTIER_AUTH_PATH to FRONTIER_PATH_AUTH.
2021-08-23 18:29:33 +01:00