-
Notifications
You must be signed in to change notification settings - Fork 19
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
Added new APIv2 endpoints that allow advanced searches and included pagination functionality #47
Conversation
laceworksdk/api/cloud_activities.py
Outdated
@@ -29,49 +32,84 @@ def __init__(self, session): | |||
def get(self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea for paginated apis that get()
will always return "all" and that if you actually want to work with pagination you would use a raw get_pages()
? Meaning we're not actually exposing iterables at the api layer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of the things that I'm wrestling with on this update. My dream was to give any existing integrations all pages of data for the price of "on the house," but due to the lack of properly utilizing a generator, I realize that there may be some significant performance and resource consumption issues related to that. Would love some feedback on whether we should leave get
alone and simply introduce new get_pages
and items
/get_items
methods for pagination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand the backwards compatibility requirements as it pertains to whether or not we're adding paging to things we've already established that get()
would return everything...
One approach could be that get()
would be a generator and all()
would return everything. For things that aren't paginated we could just alias get->all.
Otherwise you could establish get()
as the thing that returns everything and for paginated resource introduce a get_pages()
which would also seem to align with the library.
|
||
logger.info(f"PATCH request to URI: {uri}") | ||
logger.debug(f"PATCH request data:\n{data}") | ||
def get_pages(self, uri, params=None, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any pagination request settings (i.e. max items per page) here that we would want to promote, or should this simply be part of params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for final documentation on this, but it looks like max items and payload size limits are "future features": https://docs.google.com/document/d/12z5Q7byMJQEoUFS-eLGspyPN-5eMC3jm/edit#heading=h.dfxjw4abp07x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, we can also add in a max_items
here and just have a simple counter.. that is not here, but in hte get_items
function, and then exit the generator once you reach that max number.
4b7f888
to
44a4c2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few comments
laceworksdk/http_session.py
Outdated
return response | ||
try: | ||
next_page = response.json()['paging']['urls']['nextPage'] | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a pretty broad exception handling here... can y8ou narrow that down?
also better to split this up a bit
at least to...
response_json = response.json()
next_page = response_json.get("paging", {}).get("urls", {}).get("nextPage")
That way you at least don't get KeyError there, etc. (also single vs double quote for consistency in the code base)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you marked this as resolved, yet I still see the same code, with a except Exception
here
(that is to say, you did adress part of the comment, just not all of it, and not the broad exception handling aspect of it)
|
||
logger.info(f"PATCH request to URI: {uri}") | ||
logger.debug(f"PATCH request data:\n{data}") | ||
def get_pages(self, uri, params=None, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, we can also add in a max_items
here and just have a simple counter.. that is not here, but in hte get_items
function, and then exit the generator once you reach that max number.
8475324
to
2148ae9
Compare
2148ae9
to
5145e53
Compare
1010920
to
b884556
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quite a large PR, sorry for taking so long
laceworksdk/http_session.py
Outdated
return response | ||
try: | ||
next_page = response.json()['paging']['urls']['nextPage'] | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you marked this as resolved, yet I still see the same code, with a except Exception
here
(that is to say, you did adress part of the comment, just not all of it, and not the broad exception handling aspect of it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nits, otherwise LGTM
No description provided.