mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-29 02:32:05 +00:00
Multi select upstream providers to send spots to #95
This commit is contained in:
@@ -116,6 +116,8 @@ class V2APISpotHandler(V2CompatibilityWrapper, RequestCompatibilityWrapper, APIS
|
||||
def translate(body):
|
||||
if isinstance(body, dict) and isinstance(body.get("spot"), dict):
|
||||
body["spot"] = self._translate_v2_spot(body["spot"])
|
||||
if isinstance(body, dict) and isinstance(body.get("handling"), dict):
|
||||
body["handling"] = self._translate_v2_handling(body["handling"])
|
||||
return body
|
||||
|
||||
translate_json_body(self.request, translate)
|
||||
@@ -141,6 +143,21 @@ class V2APISpotHandler(V2CompatibilityWrapper, RequestCompatibilityWrapper, APIS
|
||||
spot_data["activity_refs"] = refs
|
||||
return spot_data
|
||||
|
||||
@staticmethod
|
||||
def _translate_v2_handling(handling):
|
||||
"""Translate the "handling" object provided by a client calling the add spot method in v2 format into v3
|
||||
format. v2 had a "submit_upstream" flag with a single "upstream_provider" and its credentials, whereas v3 has
|
||||
a list of "upstream_providers" and a map of provider name to credentials."""
|
||||
|
||||
handling = dict(handling)
|
||||
submit_upstream = handling.pop("submit_upstream", False)
|
||||
provider_name = handling.pop("upstream_provider", None)
|
||||
credentials = handling.pop("upstream_credentials", None) or {}
|
||||
if submit_upstream and provider_name:
|
||||
handling["upstream_providers"] = [provider_name]
|
||||
handling["upstream_credentials"] = {provider_name: credentials}
|
||||
return handling
|
||||
|
||||
|
||||
def collapse_activities(obj):
|
||||
"""Utility method to replace the "activities" list in a spot or alert JSON object with a single "activity" value,
|
||||
|
||||
Reference in New Issue
Block a user