Skip to content

Commit c90bd0a

Browse files
author
Tom Reitz
committed
robustness to older Ed-Fi API versions that do not report identity
1 parent 3357ccf commit c90bd0a

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

lightbeam/api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self, lightbeam=None):
2121
self.lightbeam = lightbeam
2222
self.logger = self.lightbeam.logger
2323
self.config = None
24+
self.reports_identity = False
2425

2526
# prepares this API object by fetching some of its metadata and
2627
# setting up data and objects for further use
@@ -239,6 +240,9 @@ def load_swagger_docs(self):
239240
if not response.ok:
240241
raise Exception("OpenAPI metadata URL returned status {0} ({1})".format(response.status_code, (response.content[:75] + "...") if len(response.content)>75 else response.content))
241242
swagger = response.json()
243+
if '"x-Ed-Fi-isIdentity":' in response.text:
244+
self.reports_identity = True
245+
print("reports identity!!")
242246

243247
except Exception as e:
244248
self.logger.critical(f"Unable to load {endpoint_type} Swagger from API... terminating. Check API connectivity.")
@@ -365,7 +369,7 @@ def get_identity_params_from_swagger(self, swagger, definition, prefix=""):
365369
schema = util.resolve_swagger_ref(swagger, definition)
366370
if not schema:
367371
self.logger.critical(f"Swagger contains neither `definitions` nor `components.schemas` - check that the Swagger is valid.")
368-
372+
print(definition, schema)
369373
for prop in schema["properties"]:
370374
if prop.endswith("Reference") and "required" in schema.keys() and prop in schema['required'] and "$ref" in schema["properties"][prop].keys():
371375
sub_definition = schema["properties"][prop]["$ref"]

lightbeam/delete.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ async def do_deletes(self, endpoint):
5454
tasks = []
5555

5656
# determine the fields that uniquely define a record for this endpoint
57-
params_structure = self.lightbeam.api.get_params_for_endpoint(endpoint, type='identity')
58-
57+
interpolation_type = 'required'
58+
if self.lightbeam.api.reports_identity: interpolation_type = 'identity'
59+
params_structure = self.lightbeam.api.get_params_for_endpoint(endpoint, type=interpolation_type)
60+
print(params_structure)
61+
5962
# for Descriptors, we need to fetch all Descriptor values first, then we can look up the ID for deletion
6063
if endpoint.endswith('Descriptors'):
6164
self.logger.info("fetching current descriptors from endpoint {0} ...".format(endpoint))
@@ -82,6 +85,7 @@ async def do_deletes(self, endpoint):
8285
# (so we can search for matching records in the API)
8386
payload = json.loads(data)
8487
params = util.interpolate_params(params_structure, payload)
88+
print(params)
8589

8690
# check if we've posted this data before
8791
data_hash = hashlog.get_hash(data)

0 commit comments

Comments
 (0)