Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination in get_logs not respecting until query parameter #392

Closed
cleavenworth opened this issue Mar 13, 2024 · 2 comments
Closed

Pagination in get_logs not respecting until query parameter #392

cleavenworth opened this issue Mar 13, 2024 · 2 comments

Comments

@cleavenworth
Copy link

cleavenworth commented Mar 13, 2024

I'm having a similar issue to #231, however from what I can tell I am following the requirements correctly to return a bounded response from the Logs endpoint.

Here is a snippet of my code where I am calling get_logs, same as the referenced issue the code will execute on a loop until there are no more results from the log. I am specifying both since and until in the log query. The results returned are correct, but resp always returns has_next as True, even after reaching the end of available logs.

async def main(app_id: str, days: int):
    today = datetime.now()
    window = today - timedelta(days=int(days))
    today = today.strftime("%Y-%m-%dT%H:%M:%SZ")
    window = window.strftime("%Y-%m-%dT%H:%M:%SZ")
    query = f'target.id eq "{app_id}" and target.type eq "AppInstance" and (eventType eq "user.authentication.sso" or eventType eq "user.authentication.verify")'
    log_lines = []
    while True:
        log_results, resp, err = await OktaClient.get_logs(
            query_params={
                "since": window,
                "until": today,
                "filter": query,
                "limit": "1000",
            }
        )
        for log in log_results:
            log_lines.append(log)
        if resp.has_next():
            log_results, err = await resp.next()
        else:
            break
@cleavenworth
Copy link
Author

User error. I put the log results within the while loop without assigning the initial response beforehand.

@sgregorioTC
Copy link

@cleavenworth, this was super helpful to me building a log call. Can you share what you mean by your user error comment, I'm fairly inexperience with coding and would love to see what it looks like after you discovered the issue to help understand it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants