1+ from typing import Dict
2+ from typing import List
3+ from typing import Optional
4+
15from tagoio_sdk .common .Common_Type import GenericID
2- from tagoio_sdk .common .Common_Type import Query
6+ from tagoio_sdk .common .Common_Type import GenericToken
7+ from tagoio_sdk .common .Common_Type import TokenCreateResponse
8+ from tagoio_sdk .common .Common_Type import TokenData
39from tagoio_sdk .common .tagoio_module import TagoIOModule
10+ from tagoio_sdk .modules .Resources .IntegrationNetworkType import ListTokenQuery
11+ from tagoio_sdk .modules .Resources .IntegrationNetworkType import NetworkCreateInfo
412from tagoio_sdk .modules .Resources .IntegrationNetworkType import NetworkInfo
13+ from tagoio_sdk .modules .Resources .IntegrationNetworkType import NetworkQuery
14+ from tagoio_sdk .modules .Resources .IntegrationNetworkType import NetworkTokenInfo
15+ from tagoio_sdk .modules .Utils .dateParser import dateParser
16+ from tagoio_sdk .modules .Utils .dateParser import dateParserList
517
618
719class Networks (TagoIOModule ):
8- def listNetwork (self , queryObj : Query = None ) -> list [NetworkInfo ]:
20+ def listNetwork (self , queryObj : Optional [ NetworkQuery ] = None ) -> List [NetworkInfo ]:
921 """
10- Retrieves a list with all networks from the account
22+ @description:
23+ Retrieves a list of all networks from the account with pagination support.
24+ Use this to retrieve and manage networks in your application.
1125
12- :default :
13- fields: ["id", "name"]
26+ @see :
27+ https://docs.tago.io/docs/tagoio/integrations/general/creating-a-network-integration Network Integration
1428
15- :param fields Fields to be returned
29+ @example:
30+ If receive an error "Authorization Denied", check policy **Integration Network** / **Access** in Access Management.
31+ ```python
32+ resources = Resources()
33+ networks = resources.integration.networks.listNetwork({
34+ "page": 1,
35+ "fields": ["id", "name"],
36+ "amount": 20,
37+ "orderBy": ["name", "asc"]
38+ })
39+ print(networks) # [{'id': 'network-id-123', 'name': 'My Network', ...}]
40+ ```
1641 """
42+ queryObj = queryObj or {}
1743
18- if queryObj is None :
19- queryObj = {}
2044 if "orderBy" in queryObj :
21- firstArgument = queryObj ["orderBy" ][0 ]
22- secondArgument = queryObj ["orderBy" ][1 ]
23- orderBy = f"{ firstArgument } ,{ secondArgument } "
45+ orderBy = f"{ queryObj ['orderBy' ][0 ]} ,{ queryObj ['orderBy' ][1 ]} "
2446 else :
2547 orderBy = "name,asc"
2648
@@ -29,30 +51,36 @@ def listNetwork(self, queryObj: Query = None) -> list[NetworkInfo]:
2951 "path" : "/integration/network" ,
3052 "method" : "GET" ,
3153 "params" : {
32- "page" : queryObj .get ("page" ) or 1 ,
33- "fields" : queryObj .get ("fields" ) or ["id" , "name" ],
34- "filter" : queryObj .get ("filter" ) or {} ,
35- "amount" : queryObj .get ("amount" ) or 20 ,
54+ "page" : queryObj .get ("page" , 1 ) ,
55+ "fields" : queryObj .get ("fields" , ["id" , "name" ]) ,
56+ "filter" : queryObj .get ("filter" , {}) ,
57+ "amount" : queryObj .get ("amount" , 20 ) ,
3658 "orderBy" : orderBy ,
3759 },
3860 }
3961 )
4062
4163 return result
4264
43- def info (self , networkID : GenericID , fields : NetworkInfo = None ) -> NetworkInfo :
65+ def info (self , networkID : GenericID , fields : Optional [ List [ str ]] = None ) -> NetworkInfo :
4466 """
45- Retrieves the information of the network.
67+ @description:
68+ Retrieves detailed information about a specific network.
4669
47- :default :
48- fields: ["id", "name"]
70+ @see :
71+ https://docs.tago.io/docs/tagoio/integrations/general/creating-a-network-integration Network Integration
4972
50- :param networkID Network ID
51- :param fields Fields to be returned
73+ @example:
74+ If receive an error "Authorization Denied", check policy **Integration Network** / **Access** in Access Management.
75+ ```python
76+ resources = Resources()
77+ network_info = resources.integration.networks.info("network-id-123")
78+ print(network_info) # {'id': '...', 'name': 'My Network', ...}
79+ ```
5280 """
53-
5481 if fields is None :
5582 fields = ["id" , "name" ]
83+
5684 result = self .doRequest (
5785 {
5886 "path" : f"/integration/network/{ networkID } " ,
@@ -64,3 +92,186 @@ def info(self, networkID: GenericID, fields: NetworkInfo = None) -> NetworkInfo:
6492 )
6593
6694 return result
95+
96+ def create (self , networkObj : NetworkCreateInfo ) -> Dict [str , str ]:
97+ """
98+ @description:
99+ Creates a new integration network in the account.
100+
101+ @see:
102+ https://docs.tago.io/docs/tagoio/integrations/general/creating-a-network-integration#create-a-new-integration Creating a Network Integration
103+
104+ @example:
105+ If receive an error "Authorization Denied", check policy **Integration Network** / **Create** in Access Management.
106+ ```python
107+ resources = Resources()
108+ new_network = resources.integration.networks.create({
109+ "name": "My Custom Network",
110+ "description": "Custom integration network",
111+ "middleware_endpoint": "https://my-middleware.com/endpoint",
112+ "public": False
113+ })
114+ print(new_network) # {'network': 'network-id-123'}
115+ ```
116+ """
117+ result = self .doRequest (
118+ {
119+ "path" : "/integration/network" ,
120+ "method" : "POST" ,
121+ "body" : networkObj ,
122+ }
123+ )
124+
125+ return result
126+
127+ def edit (self , networkID : GenericID , networkObj : NetworkCreateInfo ) -> str :
128+ """
129+ @description:
130+ Modifies any property of an existing network.
131+
132+ @example:
133+ If receive an error "Authorization Denied", check policy **Integration Network** / **Edit** in Access Management.
134+ ```python
135+ resources = Resources()
136+ result = resources.integration.networks.edit("network-id-123", {
137+ "name": "Updated Network Name",
138+ "description": "Updated description",
139+ "public": True
140+ })
141+ print(result) # Successfully Updated
142+ ```
143+ """
144+ result = self .doRequest (
145+ {
146+ "path" : f"/integration/network/{ networkID } " ,
147+ "method" : "PUT" ,
148+ "body" : networkObj ,
149+ }
150+ )
151+
152+ return result
153+
154+ def delete (self , networkID : GenericID ) -> str :
155+ """
156+ @description:
157+ Permanently deletes a network from the account.
158+
159+ @example:
160+ If receive an error "Authorization Denied", check policy **Integration Network** / **Delete** in Access Management.
161+ ```python
162+ resources = Resources()
163+ result = resources.integration.networks.delete("network-id-123")
164+ print(result) # Successfully Removed
165+ ```
166+ """
167+ result = self .doRequest (
168+ {
169+ "path" : f"/integration/network/{ networkID } " ,
170+ "method" : "DELETE" ,
171+ }
172+ )
173+
174+ return result
175+
176+ def tokenList (self , networkID : GenericID , queryObj : Optional [ListTokenQuery ] = None ) -> List [NetworkTokenInfo ]:
177+ """
178+ @description:
179+ Retrieves a list of all authentication tokens for a network with optional filtering.
180+
181+ @see:
182+ https://docs.tago.io/docs/tagoio/integrations/general/creating-a-network-integration#tokens-and-getting-devices Tokens and Getting Devices
183+
184+ @example:
185+ If receive an error "Authorization Denied", check policy **Integration Network** / **Access** in Access Management.
186+ ```python
187+ resources = Resources()
188+ tokens = resources.integration.networks.tokenList("network-id-123", {
189+ "page": 1,
190+ "amount": 20,
191+ "fields": ["name", "token", "permission"],
192+ "orderBy": ["created_at", "desc"]
193+ })
194+ print(tokens) # [{'name': 'Default Token', 'token': '...', 'permission': 'full', ...}]
195+ ```
196+ """
197+ queryObj = queryObj or {}
198+
199+ if "orderBy" in queryObj :
200+ orderBy = f"{ queryObj ['orderBy' ][0 ]} ,{ queryObj ['orderBy' ][1 ]} "
201+ else :
202+ orderBy = "created_at,desc"
203+
204+ result = self .doRequest (
205+ {
206+ "path" : f"/integration/network/token/{ networkID } " ,
207+ "method" : "GET" ,
208+ "params" : {
209+ "page" : queryObj .get ("page" , 1 ),
210+ "fields" : queryObj .get ("fields" , ["name" , "token" , "permission" ]),
211+ "filter" : queryObj .get ("filter" , {}),
212+ "amount" : queryObj .get ("amount" , 20 ),
213+ "orderBy" : orderBy ,
214+ },
215+ }
216+ )
217+
218+ result = dateParserList (result , ["created_at" , "updated_at" ])
219+
220+ return result
221+
222+ def tokenCreate (self , networkID : GenericID , tokenParams : TokenData ) -> TokenCreateResponse :
223+ """
224+ @description:
225+ Generates and retrieves a new authentication token for a network.
226+
227+ @see:
228+ https://docs.tago.io/docs/tagoio/integrations/general/creating-a-network-integration#tokens-and-getting-devices Tokens and Getting Devices
229+
230+ @example:
231+ If receive an error "Authorization Denied", check policy **Integration Network** / **Create Token** in Access Management.
232+ ```python
233+ resources = Resources()
234+ result = resources.integration.networks.tokenCreate("network-id-123", {
235+ "name": "Production Token",
236+ "permission": "write",
237+ "expire_time": "never"
238+ })
239+ print(result) # {'token': 'new-token-value', 'expire_date': None}
240+ ```
241+ """
242+ result = self .doRequest (
243+ {
244+ "path" : "/integration/network/token" ,
245+ "method" : "POST" ,
246+ "body" : {"network" : networkID , ** tokenParams },
247+ }
248+ )
249+
250+ result = dateParser (result , ["expire_date" ])
251+
252+ return result
253+
254+ def tokenDelete (self , token : GenericToken ) -> str :
255+ """
256+ @description:
257+ Permanently deletes an authentication token.
258+
259+ @see:
260+ https://docs.tago.io/docs/tagoio/integrations/general/creating-a-network-integration#tokens-and-getting-devices Tokens and Getting Devices
261+
262+ @example:
263+ If receive an error "Authorization Denied", check policy **Integration Network** / **Delete Token** in Access Management.
264+ ```python
265+ resources = Resources()
266+ result = resources.integration.networks.tokenDelete("token-to-delete")
267+ print(result) # Successfully Removed
268+ ```
269+ """
270+ result = self .doRequest (
271+ {
272+ "path" : f"/integration/network/token/{ token } " ,
273+ "method" : "DELETE" ,
274+ }
275+ )
276+
277+ return result
0 commit comments