Interators not working due to not having metadata populated
wisebaldone opened this issue · 5 comments
duo_client_python/duo_client/client.py
Line 499 in d08126e
The metadata is stored at response.metadata is it not?
The metadata
is stored alongside the response
. I tested this out by calling duo_client.Admin#get_users
and setting a breakpoint at the line you referenced. The data shape looks like:
{
'metadata': {
'total_objects': 12
},
'response': [{
<list of users>
}],
'stat': 'OK'
}
If there's a particular method/endpoint you find is not working properly, please provide a reduction of the problem as a script that we can run as well so we can investigate. Thank you!
Sorry for the delay
I was testing using the Trust Monitor event logs, I get a response like this:
{
"response": {
"events": [...],
"metadata": { "next_offset": "1211416" }
},
"stat": "OK"
}
The docs for this endpoint seems to confirm as well, also tested the user's endpoint and can confirm is as you said. So the error seems to be that admin/v1/trust_monitor/events doesn't conform to the standard.
@wisebaldone Thanks for this! I agree that the trust monitor response looks incorrect. Let me get in touch with the appropriate team and see what I can find out.
@wisebaldone After investigating further, I've confirmed this is a bug (no surprise there). Unfortunately, there are other endpoints outside of Trust Monitor Events endpoint affected by this as well, so it's not as simple as "fix one bad endpoint." We're discussing this internally and will fix this, although I cannot give an estimate on exactly when yet.
In the meantime, if you're okay with making some code modifications to get things working, the following patch should do the trick (Fair warning - I didn't test this super thoroughly):
diff --git a/duo_client/client.py b/duo_client/client.py
index 7ed6b32..a2a1f1f 100644
--- a/duo_client/client.py
+++ b/duo_client/client.py
@@ -583,7 +583,13 @@ class Client(object):
data = json.loads(data)
if data['stat'] != 'OK':
raise_error('Received error response: %s' % data)
- return (data['response'], data.get('metadata', {}))
+
+ response = data['response']
+ metadata = data.get('metadata', None)
+ if metadata is None:
+ metadata = response.get('metadata', {})
+
+ return response, metadata
except (ValueError, KeyError, TypeError):
raise_error('Received bad response: %s' % data)
@wisebaldone This bug is fixed with PR #214, which is now on master and will be included in the next release. I'll leave this issue open for now in case you'd like to test the changes on master yourself before the release. I'll close the issue with the next release unless you test and encounter a problem.
Thank you!