-
Notifications
You must be signed in to change notification settings - Fork 174
feat: Support For Network ACL Endpoints #706
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any, List # List is being used as list is already a method. | ||
|
||
from ..rest import RestClient, RestClientOptions | ||
from ..types import TimeoutType | ||
|
||
|
||
class NetworkAcls: | ||
"""Auth0 Netwrok Acls endpoints | ||
|
||
Args: | ||
domain (str): Your Auth0 domain, e.g: 'username.auth0.com' | ||
|
||
token (str): Management API v2 Token | ||
|
||
telemetry (bool, optional): Enable or disable Telemetry | ||
(defaults to True) | ||
|
||
timeout (float or tuple, optional): Change the requests | ||
connect and read timeout. Pass a tuple to specify | ||
both values separately or a float to set both to it. | ||
(defaults to 5.0 for both) | ||
|
||
protocol (str, optional): Protocol to use when making requests. | ||
(defaults to "https") | ||
|
||
rest_options (RestClientOptions): Pass an instance of | ||
RestClientOptions to configure additional RestClient | ||
options, such as rate-limit retries. | ||
(defaults to None) | ||
""" | ||
|
||
def __init__( | ||
self, | ||
domain: str, | ||
token: str, | ||
telemetry: bool = True, | ||
timeout: TimeoutType = 5.0, | ||
protocol: str = "https", | ||
rest_options: RestClientOptions | None = None, | ||
) -> None: | ||
self.domain = domain | ||
self.protocol = protocol | ||
self.client = RestClient( | ||
jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options | ||
) | ||
|
||
def _url(self, id: str | None = None) -> str: | ||
url = f"{self.protocol}://{self.domain}/api/v2/network-acls" | ||
if id is not None: | ||
return f"{url}/{id}" | ||
return url | ||
|
||
def all( | ||
self, | ||
page: int = 0, | ||
per_page: int = 25, | ||
include_totals: bool = True, | ||
) -> List[dict[str, Any]]: | ||
"""List self-service profiles. | ||
|
||
Args: | ||
page (int, optional): The result's page number (zero based). By default, | ||
retrieves the first page of results. | ||
|
||
per_page (int, optional): The amount of entries per page. By default, | ||
retrieves 25 results per page. | ||
|
||
include_totals (bool, optional): True if the query summary is | ||
to be included in the result, False otherwise. Defaults to True. | ||
|
||
See: https://auth0.com/docs/api/management/v2/network-acls/get-network-acls | ||
""" | ||
|
||
params = { | ||
"page": page, | ||
"per_page": per_page, | ||
"include_totals": str(include_totals).lower(), | ||
} | ||
|
||
return self.client.get(self._url(), params=params) | ||
|
||
def create(self, body: dict[str, Any]) -> dict[str, Any]: | ||
"""Create a new self-service profile. | ||
|
||
Args: | ||
body (dict): Attributes for the new access control list. | ||
|
||
See: https://auth0.com/docs/api/management/v2/network-acls/post-network-acls | ||
""" | ||
|
||
return self.client.post(self._url(), data=body) | ||
|
||
def get(self, id: str) -> dict[str, Any]: | ||
"""Get a self-service profile. | ||
|
||
Args: | ||
id (str): The id of the access control list to retrieve. | ||
|
||
See: https://auth0.com/docs/api/management/v2/network-acls/get-network-acls-by-id | ||
""" | ||
|
||
return self.client.get(self._url(id)) | ||
|
||
def delete(self, id: str) -> None: | ||
"""Delete a self-service profile. | ||
|
||
Args: | ||
id (str): The id of the access control list to delete. | ||
|
||
See: https://auth0.com/docs/api/management/v2/network-acls/delete-network-acls-by-id | ||
""" | ||
|
||
self.client.delete(self._url(id)) | ||
|
||
def update(self, id: str, body: dict[str, Any]) -> dict[str, Any]: | ||
"""Update a access control list. | ||
|
||
Args: | ||
id (str): The id of the access control list to update. | ||
|
||
body (dict): Attributes of the access control list to modify. | ||
|
||
See: https://auth0.com/docs/api/management/v2/network-acls/put-network-acls-by-id | ||
""" | ||
|
||
return self.client.put(self._url(id), data=body) | ||
|
||
def update_partial(self, id: str, body: dict[str, Any]) -> dict[str, Any]: | ||
"""Update partially the access control list. | ||
|
||
See: https://auth0.com/docs/api/management/v2/network-acls/patch-network-acls-by-id | ||
""" | ||
|
||
return self.client.patch(self._url(id), data=body) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import unittest | ||
from unittest import mock | ||
|
||
from ...management.network_acls import NetworkAcls | ||
|
||
|
||
class TestNetworkAcls(unittest.TestCase): | ||
def test_init_with_optionals(self): | ||
t = NetworkAcls( | ||
domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2) | ||
) | ||
self.assertEqual(t.client.options.timeout, (10, 2)) | ||
telemetry_header = t.client.base_headers.get("Auth0-Client", None) | ||
self.assertEqual(telemetry_header, None) | ||
|
||
@mock.patch("auth0.management.network_acls.RestClient") | ||
def test_all(self, mock_rc): | ||
mock_instance = mock_rc.return_value | ||
|
||
s = NetworkAcls(domain="domain", token="jwttoken") | ||
s.all() | ||
|
||
mock_instance.get.assert_called_with( | ||
"https://domain/api/v2/network-acls", | ||
params={"page": 0, "per_page": 25, "include_totals": "true"}, | ||
) | ||
|
||
s.all(page=1, per_page=50, include_totals=False) | ||
|
||
mock_instance.get.assert_called_with( | ||
"https://domain/api/v2/network-acls", | ||
params={"page": 1, "per_page": 50, "include_totals": "false"}, | ||
) | ||
|
||
@mock.patch("auth0.management.network_acls.RestClient") | ||
def test_create(self, mock_rc): | ||
mock_instance = mock_rc.return_value | ||
|
||
s = NetworkAcls(domain="domain", token="jwttoken") | ||
s.create({"name": "test"}) | ||
|
||
mock_instance.post.assert_called_with( | ||
"https://domain/api/v2/network-acls", data={"name": "test"} | ||
) | ||
|
||
@mock.patch("auth0.management.network_acls.RestClient") | ||
def test_get(self, mock_rc): | ||
mock_instance = mock_rc.return_value | ||
|
||
s = NetworkAcls(domain="domain", token="jwttoken") | ||
s.get("an-id") | ||
|
||
mock_instance.get.assert_called_with( | ||
"https://domain/api/v2/network-acls/an-id" | ||
) | ||
|
||
@mock.patch("auth0.management.network_acls.RestClient") | ||
def test_delete(self, mock_rc): | ||
mock_instance = mock_rc.return_value | ||
|
||
s = NetworkAcls(domain="domain", token="jwttoken") | ||
s.delete("an-id") | ||
|
||
mock_instance.delete.assert_called_with( | ||
"https://domain/api/v2/network-acls/an-id" | ||
) | ||
|
||
@mock.patch("auth0.management.network_acls.RestClient") | ||
def test_update(self, mock_rc): | ||
mock_instance = mock_rc.return_value | ||
|
||
s = NetworkAcls(domain="domain", token="jwttoken") | ||
s.update("an-id", {"a": "b", "c": "d"}) | ||
|
||
mock_instance.put.assert_called_with( | ||
"https://domain/api/v2/network-acls/an-id", | ||
data={"a": "b", "c": "d"}, | ||
) | ||
|
||
@mock.patch("auth0.management.network_acls.RestClient") | ||
def test_update_partial(self, mock_rc): | ||
mock_instance = mock_rc.return_value | ||
|
||
s = NetworkAcls(domain="domain", token="jwttoken") | ||
s.update_partial("an-id", {"a": "b", "c": "d"}) | ||
|
||
mock_instance.patch.assert_called_with( | ||
"https://domain/api/v2/network-acls/an-id", | ||
data={"a": "b", "c": "d"}, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.