Skip to content

Using json_api_call for bulk operations? #300

@jasongabler

Description

@jasongabler

I went down the rabbit hole of trying to use duo_client to implement bulk user operations.

def bulk_update_users(updates):
    params = []
    for update in updates:
        params.append({
            "method": "POST",
            "path": f"/admin/v1/users/{update['user_id']}",
            "body": update['changes']
        })

    r = client.json_api_call('POST', '/admin/v1/bulk', params)

Where update['changes'] is a dict of modification string key-value pairs as described in the API docs.

But I was foiled by client.py's canon_json() that expects the params to be a dict. As you can see, my params is an array of modify dicts, which violates that isinstance():

    def canon_json(cls, params):
        if not isinstance(params, dict):
            raise ValueError('JSON request must be an object.')
        return json.dumps(params, sort_keys=True, separators=(',', ':'))

Am I missing something here? Or is this not possible with duo_client?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions