Skip to content

Commit 49da078

Browse files
feat: Support For Network ACL Endpoints (#706)
### Changes - Added Support For `Network Acls` Endpoints Path | HTTP Method | Method Name | -- | -- | -- | | /network-acls | POST | create | | /network-acls/{id} | PUT | update | | /network-acls/{id} | DELETE | delete | | /network-acls | GET | getAll | | /network-acls/{id} | GET | get | | /network-acls/{id} | PATCH | patch | ### References - [Get Network Acls](https://auth0.com/docs/api/management/v2/network-acls/get-network-acls) - [Create Network Acls](https://auth0.com/docs/api/management/v2/network-acls/post-network-acls) - [Get Network Acls By Id](https://auth0.com/docs/api/management/v2/network-acls/get-network-acls-by-id) - [Partial Update Network Acls ](https://auth0.com/docs/api/management/v2/network-acls/patch-network-acls-by-id) - [Update Network Acls ](https://auth0.com/docs/api/management/v2/network-acls/put-network-acls-by-id) - [Delete Network Acls](https://auth0.com/docs/api/management/v2/network-acls/delete-network-acls-by-id) ### Testing - [x] This change adds unit test coverage - [x] This change adds integration test coverage - [x] This change has been tested on the latest version of the platform/language or why not ### Manual Verification (Flask test server) You can spin up a simple Flask app that exercises each of the new `network_acls` methods. : ``` from auth0.management import Auth0 domain = "<YOUR_DOMAIN>" mgmt_api_token = "<YOUR_MGMT_API_TOKEN>" auth0 = Auth0(domain, mgmt_api_token) app = Flask(__name__) app.secret_key = "super-secret-key" @app.route("/network-acls", methods=["POST"]) def create_network_acl(): try: result = auth0.network_acls.create(request.json) return jsonify(result), 201 except Exception as e: return jsonify({"error": str(e)}), 500 @app.route("/network-acls", methods=["GET"]) def get_network_acls(): try: result = auth0.network_acls.all( page=request.args.get("page", 0), per_page=request.args.get("per_page", 10), include_totals=request.args.get("include_totals", "false") ) return jsonify(result), 200 except Exception as e: return jsonify({"error": str(e)}), 500 @app.route("/network-acls/<acl_id>", methods=["PUT"]) def update_acl(acl_id): try: updated = auth0.network_acls.update(acl_id, body=request.json) return jsonify(updated), 200 except Exception as e: return jsonify({"error": str(e)}), 500 @app.route("/network-acls/<acl_id>", methods=["PATCH"]) def partial_update_acl(acl_id): try: patched = auth0.network_acls.update_partial(acl_id, body=request.json) return jsonify(patched), 200 except Exception as e: return jsonify({"error": str(e)}), 500 if __name__ == "__main__": app.run(debug=True, host="0.0.0.0", port=3000) ``` ### Checklist - [x] I have read the [Auth0 general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md) - [x] I have read the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md) - [x] All existing and new tests complete without errors
1 parent 288acf2 commit 49da078

File tree

8 files changed

+253
-8
lines changed

8 files changed

+253
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ For more code samples on how to integrate the auth0-python SDK in your Python ap
116116
- Jobs() ( `Auth0().jobs` )
117117
- LogStreams() ( `Auth0().log_streams` )
118118
- Logs() ( `Auth0().logs` )
119+
- NetworkAcls() ( `Auth0().network_acls` )
119120
- Organizations() ( `Auth0().organizations` )
120121
- Prompts() ( `Auth0().prompts` )
121122
- ResourceServers() (`Auth0().resource_servers` )

auth0/management/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .jobs import Jobs
1818
from .log_streams import LogStreams
1919
from .logs import Logs
20+
from .network_acls import NetworkAcls
2021
from .organizations import Organizations
2122
from .resource_servers import ResourceServers
2223
from .roles import Roles
@@ -55,6 +56,7 @@
5556
"Jobs",
5657
"LogStreams",
5758
"Logs",
59+
"NetworkAcls"
5860
"Organizations",
5961
"ResourceServers",
6062
"Roles",

auth0/management/auth0.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .jobs import Jobs
2121
from .log_streams import LogStreams
2222
from .logs import Logs
23+
from .network_acls import NetworkAcls
2324
from .organizations import Organizations
2425
from .prompts import Prompts
2526
from .resource_servers import ResourceServers
@@ -79,6 +80,7 @@ def __init__(
7980
self.jobs = Jobs(domain, token, rest_options=rest_options)
8081
self.log_streams = LogStreams(domain, token, rest_options=rest_options)
8182
self.logs = Logs(domain, token, rest_options=rest_options)
83+
self.network_acls = NetworkAcls(domain, token, rest_options=rest_options)
8284
self.organizations = Organizations(domain, token, rest_options=rest_options)
8385
self.prompts = Prompts(domain, token, rest_options=rest_options)
8486
self.resource_servers = ResourceServers(

auth0/management/network_acls.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
from __future__ import annotations
2+
3+
from typing import Any, List # List is being used as list is already a method.
4+
5+
from ..rest import RestClient, RestClientOptions
6+
from ..types import TimeoutType
7+
8+
9+
class NetworkAcls:
10+
"""Auth0 Netwrok Acls endpoints
11+
12+
Args:
13+
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
14+
15+
token (str): Management API v2 Token
16+
17+
telemetry (bool, optional): Enable or disable Telemetry
18+
(defaults to True)
19+
20+
timeout (float or tuple, optional): Change the requests
21+
connect and read timeout. Pass a tuple to specify
22+
both values separately or a float to set both to it.
23+
(defaults to 5.0 for both)
24+
25+
protocol (str, optional): Protocol to use when making requests.
26+
(defaults to "https")
27+
28+
rest_options (RestClientOptions): Pass an instance of
29+
RestClientOptions to configure additional RestClient
30+
options, such as rate-limit retries.
31+
(defaults to None)
32+
"""
33+
34+
def __init__(
35+
self,
36+
domain: str,
37+
token: str,
38+
telemetry: bool = True,
39+
timeout: TimeoutType = 5.0,
40+
protocol: str = "https",
41+
rest_options: RestClientOptions | None = None,
42+
) -> None:
43+
self.domain = domain
44+
self.protocol = protocol
45+
self.client = RestClient(
46+
jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options
47+
)
48+
49+
def _url(self, id: str | None = None) -> str:
50+
url = f"{self.protocol}://{self.domain}/api/v2/network-acls"
51+
if id is not None:
52+
return f"{url}/{id}"
53+
return url
54+
55+
def all(
56+
self,
57+
page: int = 0,
58+
per_page: int = 25,
59+
include_totals: bool = True,
60+
) -> List[dict[str, Any]]:
61+
"""List self-service profiles.
62+
63+
Args:
64+
page (int, optional): The result's page number (zero based). By default,
65+
retrieves the first page of results.
66+
67+
per_page (int, optional): The amount of entries per page. By default,
68+
retrieves 25 results per page.
69+
70+
include_totals (bool, optional): True if the query summary is
71+
to be included in the result, False otherwise. Defaults to True.
72+
73+
See: https://auth0.com/docs/api/management/v2/network-acls/get-network-acls
74+
"""
75+
76+
params = {
77+
"page": page,
78+
"per_page": per_page,
79+
"include_totals": str(include_totals).lower(),
80+
}
81+
82+
return self.client.get(self._url(), params=params)
83+
84+
def create(self, body: dict[str, Any]) -> dict[str, Any]:
85+
"""Create a new self-service profile.
86+
87+
Args:
88+
body (dict): Attributes for the new access control list.
89+
90+
See: https://auth0.com/docs/api/management/v2/network-acls/post-network-acls
91+
"""
92+
93+
return self.client.post(self._url(), data=body)
94+
95+
def get(self, id: str) -> dict[str, Any]:
96+
"""Get a self-service profile.
97+
98+
Args:
99+
id (str): The id of the access control list to retrieve.
100+
101+
See: https://auth0.com/docs/api/management/v2/network-acls/get-network-acls-by-id
102+
"""
103+
104+
return self.client.get(self._url(id))
105+
106+
def delete(self, id: str) -> None:
107+
"""Delete a self-service profile.
108+
109+
Args:
110+
id (str): The id of the access control list to delete.
111+
112+
See: https://auth0.com/docs/api/management/v2/network-acls/delete-network-acls-by-id
113+
"""
114+
115+
self.client.delete(self._url(id))
116+
117+
def update(self, id: str, body: dict[str, Any]) -> dict[str, Any]:
118+
"""Update a access control list.
119+
120+
Args:
121+
id (str): The id of the access control list to update.
122+
123+
body (dict): Attributes of the access control list to modify.
124+
125+
See: https://auth0.com/docs/api/management/v2/network-acls/put-network-acls-by-id
126+
"""
127+
128+
return self.client.put(self._url(id), data=body)
129+
130+
def update_partial(self, id: str, body: dict[str, Any]) -> dict[str, Any]:
131+
"""Update partially the access control list.
132+
133+
See: https://auth0.com/docs/api/management/v2/network-acls/patch-network-acls-by-id
134+
"""
135+
136+
return self.client.patch(self._url(id), data=body)
137+
138+

auth0/test/management/test_auth0.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ...management.jobs import Jobs
1919
from ...management.log_streams import LogStreams
2020
from ...management.logs import Logs
21+
from ...management.network_acls import NetworkAcls
2122
from ...management.organizations import Organizations
2223
from ...management.prompts import Prompts
2324
from ...management.resource_servers import ResourceServers
@@ -89,6 +90,9 @@ def test_log_streams(self):
8990

9091
def test_logs(self):
9192
self.assertIsInstance(self.a0.logs, Logs)
93+
94+
def test_network_acls(self):
95+
self.assertIsInstance(self.a0.network_acls, NetworkAcls)
9296

9397
def test_organizations(self):
9498
self.assertIsInstance(self.a0.organizations, Organizations)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import unittest
2+
from unittest import mock
3+
4+
from ...management.network_acls import NetworkAcls
5+
6+
7+
class TestNetworkAcls(unittest.TestCase):
8+
def test_init_with_optionals(self):
9+
t = NetworkAcls(
10+
domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2)
11+
)
12+
self.assertEqual(t.client.options.timeout, (10, 2))
13+
telemetry_header = t.client.base_headers.get("Auth0-Client", None)
14+
self.assertEqual(telemetry_header, None)
15+
16+
@mock.patch("auth0.management.network_acls.RestClient")
17+
def test_all(self, mock_rc):
18+
mock_instance = mock_rc.return_value
19+
20+
s = NetworkAcls(domain="domain", token="jwttoken")
21+
s.all()
22+
23+
mock_instance.get.assert_called_with(
24+
"https://domain/api/v2/network-acls",
25+
params={"page": 0, "per_page": 25, "include_totals": "true"},
26+
)
27+
28+
s.all(page=1, per_page=50, include_totals=False)
29+
30+
mock_instance.get.assert_called_with(
31+
"https://domain/api/v2/network-acls",
32+
params={"page": 1, "per_page": 50, "include_totals": "false"},
33+
)
34+
35+
@mock.patch("auth0.management.network_acls.RestClient")
36+
def test_create(self, mock_rc):
37+
mock_instance = mock_rc.return_value
38+
39+
s = NetworkAcls(domain="domain", token="jwttoken")
40+
s.create({"name": "test"})
41+
42+
mock_instance.post.assert_called_with(
43+
"https://domain/api/v2/network-acls", data={"name": "test"}
44+
)
45+
46+
@mock.patch("auth0.management.network_acls.RestClient")
47+
def test_get(self, mock_rc):
48+
mock_instance = mock_rc.return_value
49+
50+
s = NetworkAcls(domain="domain", token="jwttoken")
51+
s.get("an-id")
52+
53+
mock_instance.get.assert_called_with(
54+
"https://domain/api/v2/network-acls/an-id"
55+
)
56+
57+
@mock.patch("auth0.management.network_acls.RestClient")
58+
def test_delete(self, mock_rc):
59+
mock_instance = mock_rc.return_value
60+
61+
s = NetworkAcls(domain="domain", token="jwttoken")
62+
s.delete("an-id")
63+
64+
mock_instance.delete.assert_called_with(
65+
"https://domain/api/v2/network-acls/an-id"
66+
)
67+
68+
@mock.patch("auth0.management.network_acls.RestClient")
69+
def test_update(self, mock_rc):
70+
mock_instance = mock_rc.return_value
71+
72+
s = NetworkAcls(domain="domain", token="jwttoken")
73+
s.update("an-id", {"a": "b", "c": "d"})
74+
75+
mock_instance.put.assert_called_with(
76+
"https://domain/api/v2/network-acls/an-id",
77+
data={"a": "b", "c": "d"},
78+
)
79+
80+
@mock.patch("auth0.management.network_acls.RestClient")
81+
def test_update_partial(self, mock_rc):
82+
mock_instance = mock_rc.return_value
83+
84+
s = NetworkAcls(domain="domain", token="jwttoken")
85+
s.update_partial("an-id", {"a": "b", "c": "d"})
86+
87+
mock_instance.patch.assert_called_with(
88+
"https://domain/api/v2/network-acls/an-id",
89+
data={"a": "b", "c": "d"},
90+
)

docs/source/management.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ management.logs module
129129
:undoc-members:
130130
:show-inheritance:
131131

132+
management.network\_acls module
133+
-----------------------------------------
134+
135+
.. automodule:: auth0.management.network_acls
136+
:members:
137+
:undoc-members:
138+
:show-inheritance:
139+
132140
management.organizations module
133141
----------------------------------
134142

@@ -177,7 +185,7 @@ management.rules module
177185
:undoc-members:
178186
:show-inheritance:
179187

180-
management.self_service_profiles module
188+
management.self\_service\_profiles module
181189
-----------------------------------------
182190

183191
.. automodule:: auth0.management.self_service_profiles

requirements.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ asynctest==0.13.0 ; python_version >= "3.7" and python_version < "3.8"
77
attrs==23.1.0 ; python_version >= "3.7" and python_version < "4.0"
88
certifi==2025.1.31 ; python_version >= "3.7" and python_version < "4.0"
99
cffi==1.17.1 ; python_version >= "3.7" and python_version < "4.0"
10-
charset-normalizer==3.2.0 ; python_version >= "3.7" and python_version < "4.0"
10+
charset-normalizer==3.4.2 ; python_version >= "3.7" and python_version < "4.0"
1111
click==8.1.8 ; python_version >= "3.7" and python_version < "4.0"
1212
colorama==0.4.6 ; python_version >= "3.7" and python_version < "4.0" and sys_platform == "win32" or python_version >= "3.7" and python_version < "4.0" and platform_system == "Windows"
1313
coverage[toml]==7.2.7 ; python_version >= "3.7" and python_version < "4.0"
@@ -16,16 +16,16 @@ exceptiongroup==1.1.3 ; python_version >= "3.7" and python_version < "3.11"
1616
frozenlist==1.5.0 ; python_version >= "3.7" and python_version < "4.0"
1717
idna==3.10 ; python_version >= "3.7" and python_version < "4.0"
1818
importlib-metadata==6.7.0 ; python_version >= "3.7" and python_version < "3.8"
19-
iniconfig==2.0.0 ; python_version >= "3.7" and python_version < "4.0"
20-
mock==5.1.0 ; python_version >= "3.7" and python_version < "4.0"
19+
iniconfig==2.1.0 ; python_version >= "3.7" and python_version < "4.0"
20+
mock==5.2.0 ; python_version >= "3.7" and python_version < "4.0"
2121
multidict==6.0.4 ; python_version >= "3.7" and python_version < "4.0"
2222
packaging==23.1 ; python_version >= "3.7" and python_version < "4.0"
2323
pipx==1.2.0 ; python_version >= "3.7" and python_version < "4.0"
2424
pluggy==1.2.0 ; python_version >= "3.7" and python_version < "4.0"
2525
pycparser==2.21 ; python_version >= "3.7" and python_version < "4.0"
2626
pyjwt==2.9.0 ; python_version >= "3.7" and python_version < "4.0"
27-
pyopenssl==25.0.0 ; python_version >= "3.7" and python_version < "4.0"
28-
pytest-aiohttp==1.0.4 ; python_version >= "3.7" and python_version < "4.0"
27+
pyopenssl==25.1.0 ; python_version >= "3.7" and python_version < "4.0"
28+
pytest-aiohttp==1.0.5 ; python_version >= "3.7" and python_version < "4.0"
2929
pytest-asyncio==0.23.8 ; python_version >= "3.7" and python_version < "4.0"
3030
pytest-cov==4.1.0 ; python_version >= "3.7" and python_version < "4.0"
3131
pytest==7.4.0 ; python_version >= "3.7" and python_version < "4.0"
@@ -35,7 +35,7 @@ responses==0.23.3 ; python_version >= "3.7" and python_version < "4.0"
3535
tomli==2.0.1 ; python_version >= "3.7" and python_full_version <= "3.11.0a6"
3636
types-pyyaml==6.0.12.11 ; python_version >= "3.7" and python_version < "4.0"
3737
typing-extensions==4.7.1 ; python_version >= "3.7" and python_version < "3.8"
38-
urllib3==2.2.2 ; python_version >= "3.7" and python_version < "4.0"
39-
userpath==1.9.0 ; python_version >= "3.7" and python_version < "4.0"
38+
urllib3==2.5.0 ; python_version >= "3.7" and python_version < "4.0"
39+
userpath==1.9.2 ; python_version >= "3.7" and python_version < "4.0"
4040
yarl==1.20.0 ; python_version >= "3.7" and python_version < "4.0"
4141
zipp==3.19.1 ; python_version >= "3.7" and python_version < "3.8"

0 commit comments

Comments
 (0)