Skip to content

Interators not working due to not having metadata populated #201

Closed

Description

@wisebaldone

return (data['response'], data.get('metadata', {}))

The metadata is stored at response.metadata is it not?

Activity

  1. spencermaxfield commented on Apr 5, 2023

    @spencermaxfield

    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!

  2. wisebaldone commented on Apr 20, 2023

    @wisebaldone
    Author

    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.

  3. spencermaxfield commented on Apr 20, 2023

    @spencermaxfield

    @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.

  4. spencermaxfield commented on Apr 21, 2023

    @spencermaxfield

    @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)
    
  5. spencermaxfield commented on Apr 27, 2023

    @spencermaxfield

    @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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions