@@ -23,6 +23,10 @@ def __init__(self, grafana_api_model: APIModel):
23
23
def get_folders (self ) -> list :
24
24
"""The method includes a functionality to extract all folders inside the organization
25
25
26
+ Required Permissions:
27
+ Action: folders:read
28
+ Scope: folders:*
29
+
26
30
Raises:
27
31
Exception: Unspecified error by executing the API call
28
32
@@ -46,6 +50,10 @@ def get_folder_by_uid(self, uid: str) -> dict:
46
50
Args:
47
51
uid (str): Specify the uid of the folder
48
52
53
+ Required Permissions:
54
+ Action: folders:read
55
+ Scope: folders:*
56
+
49
57
Raises:
50
58
ValueError: Missed specifying a necessary value
51
59
Exception: Unspecified error by executing the API call
@@ -74,6 +82,10 @@ def get_folder_by_id(self, id: int) -> dict:
74
82
Args:
75
83
id (int): Specify the id of the folder
76
84
85
+ Required Permissions:
86
+ Action: folders:read
87
+ Scope: folders:*
88
+
77
89
Raises:
78
90
ValueError: Missed specifying a necessary value
79
91
Exception: Unspecified error by executing the API call
@@ -96,12 +108,17 @@ def get_folder_by_id(self, id: int) -> dict:
96
108
logging .error ("There is no folder id defined." )
97
109
raise ValueError
98
110
99
- def create_folder (self , title : str , uid : str = None ) -> dict :
111
+ def create_folder (self , title : str , uid : str = None , parent_uid : str = None ) -> dict :
100
112
"""The method includes a functionality to create a new folder inside the organization specified by the defined title and the optional uid
101
113
102
114
Args:
103
115
title (str): Specify the title of the folder
104
116
uid (str): Specify the uid of the folder (default None)
117
+ parent_uid (str): Specify the parent_uid of the folder (default None)
118
+
119
+ Required Permissions:
120
+ Action: folders:create, folders:write
121
+ Scope: folders:*
105
122
106
123
Raises:
107
124
ValueError: Missed specifying a necessary value
@@ -118,6 +135,9 @@ def create_folder(self, title: str, uid: str = None) -> dict:
118
135
if uid is not None and len (uid ) != 0 :
119
136
folder_information .update ({"uid" : uid })
120
137
138
+ if parent_uid is not None and len (parent_uid ) != 0 :
139
+ folder_information .update ({"parentUid" : parent_uid })
140
+
121
141
api_call : dict = Api (self .grafana_api_model ).call_the_api (
122
142
APIEndpoints .FOLDERS .value ,
123
143
RequestsMethods .POST ,
@@ -144,6 +164,10 @@ def update_folder(
144
164
version (int): Specify the version of the folder (default 0)
145
165
overwrite (bool): Should the already existing folder information be overwritten (default False)
146
166
167
+ Required Permissions:
168
+ Action: folders:write
169
+ Scope: folders:*
170
+
147
171
Raises:
148
172
ValueError: Missed specifying a necessary value
149
173
Exception: Unspecified error by executing the API call
@@ -179,12 +203,57 @@ def update_folder(
179
203
logging .error ("There is no folder title, version or uid defined." )
180
204
raise ValueError
181
205
206
+ def move_folder (self , uid : str , parent_uid : str = None ):
207
+ """The method includes a functionality to move a folder inside the organization specified by the defined uid. This feature is only relevant if nested folders are enabled
208
+
209
+ Args:
210
+ uid (str): Specify the uid of the folder
211
+ parent_uid (str): Specify the parent_uid of the folder. If the value is None, then the folder is moved under the root (default None)
212
+
213
+ Required Permissions:
214
+ Action: folders:create, folders:write
215
+ Scope: folders:*, folders:uid:<destination folder UID>
216
+
217
+ Raises:
218
+ ValueError: Missed specifying a necessary value
219
+ Exception: Unspecified error by executing the API call
220
+
221
+ Returns:
222
+ api_call (dict): Returns the moved folder
223
+ """
224
+
225
+ if len (uid ) != 0 :
226
+ folder_information : dict = dict ()
227
+
228
+ if parent_uid is not None and len (parent_uid ) != 0 :
229
+ folder_information .update ({"parentUid" : parent_uid })
230
+
231
+ api_call = Api (self .grafana_api_model ).call_the_api (
232
+ f"{ APIEndpoints .FOLDERS .value } /{ uid } /move" ,
233
+ RequestsMethods .POST ,
234
+ json .dumps (folder_information ),
235
+ )
236
+
237
+ if api_call == dict () or api_call .get ("id" ) is None :
238
+ logging .error (f"Please, check the error: { api_call } ." )
239
+ raise Exception
240
+ else :
241
+ return api_call
242
+ else :
243
+ logging .error ("There is no folder uid defined." )
244
+ raise ValueError
245
+
246
+
182
247
def delete_folder (self , uid : str ):
183
248
"""The method includes a functionality to delete a folder inside the organization specified by the defined uid
184
249
185
250
Args:
186
251
uid (str): Specify the uid of the folder
187
252
253
+ Required Permissions:
254
+ Action: folders:delete
255
+ Scope: folders:*
256
+
188
257
Raises:
189
258
ValueError: Missed specifying a necessary value
190
259
Exception: Unspecified error by executing the API call
@@ -220,6 +289,10 @@ def get_folder_permissions(self, uid: str) -> list:
220
289
Args:
221
290
uid (str): Specify the uid of the folder
222
291
292
+ Required Permissions:
293
+ Action: folders.permissions:read
294
+ Scope: folders:*
295
+
223
296
Raises:
224
297
ValueError: Missed specifying a necessary value
225
298
Exception: Unspecified error by executing the API call
@@ -250,6 +323,10 @@ def update_folder_permissions(self, uid: str, permission_json: dict):
250
323
uid (str): Specify the uid of the folder
251
324
permission_json (dict): Specify the inserted permissions as dict
252
325
326
+ Required Permissions:
327
+ Action: folders.permissions:write
328
+ Scope: folders:*
329
+
253
330
Raises:
254
331
ValueError: Missed specifying a necessary value
255
332
Exception: Unspecified error by executing the API call
0 commit comments