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

Web DLP class/methods #152

Merged
merged 24 commits into from
Nov 18, 2022
Merged

Web DLP class/methods #152

merged 24 commits into from
Nov 18, 2022

Conversation

daxm
Copy link
Contributor

@daxm daxm commented Nov 10, 2022

Updated my "main" with Mitch's. Also merged in my web_dlp branch.

@daxm daxm temporarily deployed to test November 10, 2022 20:26 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:26 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:26 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:26 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:29 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:29 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:29 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:29 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:48 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:48 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:48 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:48 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:53 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:53 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:53 Inactive
@daxm daxm temporarily deployed to test November 10, 2022 20:53 Inactive
@mitchos mitchos changed the base branch from main to develop November 11, 2022 00:29
Copy link
Owner

@mitchos mitchos left a comment

Choose a reason for hiding this comment

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

Thanks for getting started on this @daxm, really appreciate it!

After addressing those review points we can merge into develop and add some additional work to round it off:

  • Docstrings complete with examples
  • Adding the docsrc RST files to ensure our readthedocs site will pick up the changes
  • Test coverage

Overall great quality pull request and thankyou thankyou thankyou!

@@ -210,3 +211,19 @@ def vips(self):

"""
return DataCenterVIPSAPI(self)

@property
Copy link
Owner

Choose a reason for hiding this comment

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

I think you may have accidentally duplicated this class attribute. We have the admin_and_role_management attribute defined on line 95.

Can you just remove lines 216->221 when you resubmit?

@@ -8,15 +8,13 @@ class AdminAndRoleManagementAPI(APIEndpoint):
def add_user(self, name: str, login_name: str, email: str, password: str, **kwargs) -> Box:
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure what was changed in this file, just looks like a blank line was removed somewhere. I think we can remove this from the pull request.



class WebDLP(APIEndpoint):
def get_all(self, **kwargs) -> BoxList:
Copy link
Owner

Choose a reason for hiding this comment

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

Are you happy if we rename these methods to align with the rest of the SDK?

I've taken the approach that Zscaler may add additional objects to some of these API endpoints, which would mean we need to be a bit more verbose about the verbs and what we're doing. So at the moment it appears that the web_dlp endpoint just has policy rules, but if they were to add anything else then just having zia.web_dlp.get_all() would be ambiguous.

So while it may seem a bit over the top, having a descriptive verb/noun for the methods ensures we don't need to go back and refactor if the API endpoints are expanded. You should see a module.attribute.verb_noun convention used across the SDK.

If we're returning a list of items then we should expect something like zia.web_dlp.list_rules()

"""
return self._get("webDlpRules")

def get_item(self, item_id: str) -> Box:
Copy link
Owner

Choose a reason for hiding this comment

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

Consider naming to get_rule()

"""
return self._get("webDlpRules/lite")

def post(self, payload: json) -> Box:
Copy link
Owner

Choose a reason for hiding this comment

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

Consider naming to add_rule()

"""
return self._post("webDlpRules", json=payload)

def put(self, item_id: str, payload: json) -> Box:
Copy link
Owner

Choose a reason for hiding this comment

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

Consider naming update_rule()

"""
return self._put(f"webDlpRules/{item_id}", json=payload)

def delete(self, item_id: str) -> requests.Response:
Copy link
Owner

Choose a reason for hiding this comment

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

Consider naming delete_rule()

Returns:
Requests.Response object.
"""
return self._delete(f"webDlpRules/{item_id}")
Copy link
Owner

Choose a reason for hiding this comment

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

Often I've found ZIA responses to DELETE to be inconsistent. I've opted to just return the status code instead, which gives us at least a uniform response to expect on a successful DELETE.

I'd recommend:
return self._delete(f"webDlpRules/{item_id}").status_code

"""
return self._put(f"webDlpRules/{item_id}", json=payload)

def delete(self, item_id: str) -> requests.Response:
Copy link
Owner

Choose a reason for hiding this comment

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

If we return the status code, just a reminder that the return type is Int.

@mitchos mitchos self-assigned this Nov 14, 2022
@daxm daxm temporarily deployed to test November 14, 2022 14:55 Inactive
@daxm daxm temporarily deployed to test November 14, 2022 14:55 Inactive
@daxm daxm temporarily deployed to test November 14, 2022 14:55 Inactive
@daxm daxm temporarily deployed to test November 14, 2022 14:55 Inactive
@sonarcloud
Copy link

sonarcloud bot commented Nov 14, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
3.6% 3.6% Duplication

@daxm
Copy link
Contributor Author

daxm commented Nov 14, 2022

I appreciate your detailed response. Let me try to give context to your notes:

  • Removed init.py duplication. This was a hangover from when I was out of sync with your current changes. Sorry about that!
  • I only modified the pyzscaler/zia/admin_and_role_management.py file because, my commit contained an old version and had merge conflicts with yours. This is why I deleted my first PR request. To fix the issue I just copy/pasted your version into my PR. The reason I did this is because I don't know how to cherry pick out those changes, as you are requesting.
  • I'm fine with renaming the the methods in the web_dlp.py. I'll give it a deeper look and try again.
  • I don't know how to do:
    - Adding the docsrc RST files to ensure our readthedocs site will pick up the changes. -- The syntax makes no sense to me of the existing rst files. I could use some help here.
    - Test coverage -- I've never learned (yet) how to write pytests. I could use some help here.

@mitchos mitchos changed the base branch from develop to feature/zia-web-dlp November 18, 2022 04:23
@mitchos
Copy link
Owner

mitchos commented Nov 18, 2022

Hey @daxm I've re-pointed this pull request to the feature branch so I'll approve the pull request and just submit another one for your latest changes and we can go from there. 👍

@mitchos mitchos merged commit 4b0e435 into mitchos:feature/zia-web-dlp Nov 18, 2022
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.

2 participants