@@ -73,7 +73,8 @@ def delete(
7373 - `<Response [404]>` Object not found in the Fortigate.
7474 :rtype: Response
7575 """
76- _ = kwargs # noqa todo extract uid key from kwargs (if uid not specified)
76+ if not uid :
77+ uid = str (kwargs .get (self .uid ) or "" )
7778 h .check_uid_filter (uid , filter )
7879 if filter :
7980 return self ._delete_by_filter (filter )
@@ -101,25 +102,6 @@ def get(self, **kwargs) -> LDAny:
101102 items = [item ]
102103 return items
103104
104- def update (self , data : DAny ) -> Response :
105- """Update fortigate-object on the Fortigate.
106-
107- :param dict data: Data of the fortigate-object to update.
108- More details can be found at https://fndn.fortinet.net for related ``PUT`` method.
109-
110- :return: Session response.
111-
112- - `<Response [200]>` Object successfully updated,
113- - `<Response [404]>` Object has not been updated.
114- :rtype: Response
115- """
116- uid = str (data [self .uid ])
117- uid = h .quote (uid )
118- if not uid :
119- raise ValueError (f"{ self .uid } value is required." )
120- url = f"{ self .url } /{ uid } "
121- return self .fortigate .put (url = url , data = data )
122-
123105 def is_exist (self , uid : StrInt ) -> bool :
124106 """Check if a fortigate-object exists in the Fortigate.
125107
@@ -136,7 +118,21 @@ def is_exist(self, uid: StrInt) -> bool:
136118 response = self .fortigate .exist (url )
137119 return response .ok
138120
139- # =========================== helpers ===========================
121+ def update (self , data : DAny ) -> Response :
122+ """Update fortigate-object on the Fortigate.
123+
124+ :param dict data: Data of the fortigate-object to update.
125+ More details can be found at https://fndn.fortinet.net for related ``PUT`` method.
126+
127+ :return: Session response.
128+
129+ - `<Response [200]>` Object successfully updated,
130+ - `<Response [404]>` Object has not been updated.
131+ :rtype: Response
132+ """
133+ uid : str = self ._get_uid (data )
134+ url = f"{ self .url } /{ uid } " .rstrip ("/" )
135+ return self .fortigate .put (url = url , data = data )
140136
141137 # noinspection PyShadowingBuiltins
142138 def _delete_by_filter (self , filter : UStr ) -> Response : # pylint: disable=redefined-builtin
@@ -161,3 +157,18 @@ def _delete_by_filter(self, filter: UStr) -> Response: # pylint: disable=redefi
161157 response = self .fortigate .delete (url = url )
162158 responses .append (response )
163159 return h .highest_response (responses )
160+
161+ def _get_uid (self , data ) -> str :
162+ """Get UID value based on the UID key
163+
164+ :param data: A dictionary containing the UID value.
165+ :return: The UID value extracted from the data.
166+ :raises ValueError: If the UID is required but not present in the data.
167+ """
168+ if not self .uid :
169+ return ""
170+ if self .uid not in data :
171+ raise ValueError (f"{ self .uid } value is required." )
172+ uid = str (data [self .uid ])
173+ uid = h .quote (uid )
174+ return uid
0 commit comments