Skip to content

Conversation

@brandon-wada
Copy link
Collaborator

Combines some other PRs and allows:

Further SDK development should NOT follow this pattern. Bouncing back and forth between the two repos is clunky to test, but more importantly we probably want to move away from manually writing out the spec.

brandon and others added 30 commits February 27, 2024 14:55
auto-generated time is wrong, but I'll update the autogenerated code in a bit
… with dev environment and make the sdk code cleaner and nicer
Copy link
Contributor

@mjvogelsong mjvogelsong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

The main thing is that I don't think we should change the supported python versions to 3.10+ in this PR (it will break our github action test-comprehensive test matrix for 3.7-3.9)

pyproject.toml Outdated
requests = "^2.28.2"
urllib3 = "^1.26.9"
typer = "^0.9.0"
ipython = "^8.22.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to keep the package size small, so we probably don't want to include ipython. Or at least, we should move it to dev dependencies.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for catching that, this wasn't supposed to make it in. I wanted IPython for a bit of debugging at one point. I like the idea of adding it to dev dependencies.

pyproject.toml Outdated
pillow = ">=9.0.0" # TODO: We may want to mark pillow (and numpy) as extra (https://python-poetry.org/docs/master/pyproject#extras)
pydantic = ">=1.7.4,<3.0.0"
python = ">=3.7.0,<4.0"
python = ">=3.10.0,<4.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still are supporting older versions of python. Was there a dependency change that caused this update?

I don't think we should be supporting 3.7 anymore because it is past "end-of-life" (please ask avi/leo what they think), but I do think some people still use 3.8. If we bump to 3.8+, then we could remove the 3.7 part of the github action test matrix.

https://devguide.python.org/versions/

Suggested change
python = ">=3.10.0,<4.0"
python = ">=3.8,<4.0"

obj = self.rules_api.list_rules(page=page, page_size=page_size)
return PaginatedRuleList.parse_obj(obj.to_dict())

def delete_all_rules(self, detector: Union[None, str, Detector] = None) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, we may want a bulk delete endpoint.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have a request sitting around for bulk iq retrieval as well. As time permits, I'll look at adding that endpoint

Comment on lines 128 to 129
for page in range(1, (num_rules // 10) + 2):
for rule in self.list_rules(page=page, page_size=10).results:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use a larger page size, like 100. And I would put it in a common variable, so we don't accidentally introduce a bug.

obj = self.rules_api.list_rules(page=page, page_size=page_size)
return PaginatedRuleList.parse_obj(obj.to_dict())

def delete_all_rules(self, detector: Union[None, str, Detector] = None) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could return the number of deleted rules, if that's useful.

return ExperimentalApi()


def test_create_action(gl: ExperimentalApi):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_create_action(gl: ExperimentalApi):
def test_create_rule(gl: ExperimentalApi):

@brandon-wada
Copy link
Collaborator Author

Sorry for the extra emails, the github runner was behaving differently than my local machine and took a sec to debug. But this is ready now!

@@ -0,0 +1,173 @@
"""
experimental_t api.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
experimental_t api.py
experimental_api.py

snooze_time_unit: str = "SECONDS",
) -> Rule:
"""
Adds a notification action to the given detector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Adds a notification action to the given detector
Adds a notification rule to the given detector

Comment on lines 8 to 10
@pytest.fixture(name="gl")
def _gl() -> ExperimentalApi:
return ExperimentalApi()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can pull this into a common module.



def test_get_all_actions(gl: ExperimentalApi):
num_test_rules = 103 # needs to be larger than the default page size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be creating this many rules in unit tests -- instead, we should patch the default page size to something smaller.

Comment on lines 18 to 31
try:
notes = gl.get_notes(det)["gl"]
found_note = False
for i in range(len(notes)):
if notes[i].content == "test_note":
found_note = True
assert found_note
except (AssertionError, ApiAttributeError):
notes = gl.get_notes(det)["customer"]
found_note = False
for i in range(len(notes)):
if notes[i].content == "test_note":
found_note = True
assert found_note
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does something like this work?

Suggested change
try:
notes = gl.get_notes(det)["gl"]
found_note = False
for i in range(len(notes)):
if notes[i].content == "test_note":
found_note = True
assert found_note
except (AssertionError, ApiAttributeError):
notes = gl.get_notes(det)["customer"]
found_note = False
for i in range(len(notes)):
if notes[i].content == "test_note":
found_note = True
assert found_note
notes = (gl.get_notes(det).get("gl") or []) + (gl.get_notes(det).get("customer") or [])
found_note = False
for i in range(len(notes)):
if notes[i].content == "test_note":
found_note = True
assert found_note

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh, that's nice

@brandon-wada brandon-wada merged commit 233f837 into main Mar 28, 2024
@tyler-romero tyler-romero deleted the v0.15.0 branch April 1, 2024 18:51
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

Successfully merging this pull request may close these issues.

3 participants