Skip to content

Commit 7f55514

Browse files
authored
feat: Add the parent folder uid functionality and adjust the docs (#105)
* feat: Add the parent folder uid functionality and adjust the documentation
1 parent ca148ea commit 7f55514

File tree

11 files changed

+327
-48
lines changed

11 files changed

+327
-48
lines changed

Diff for: docs/content/grafana_api/folder.md

+65-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [get\_folder\_by\_id](#folder.Folder.get_folder_by_id)
88
* [create\_folder](#folder.Folder.create_folder)
99
* [update\_folder](#folder.Folder.update_folder)
10+
* [move\_folder](#folder.Folder.move_folder)
1011
* [delete\_folder](#folder.Folder.delete_folder)
1112
* [get\_folder\_permissions](#folder.Folder.get_folder_permissions)
1213
* [update\_folder\_permissions](#folder.Folder.update_folder_permissions)
@@ -46,6 +47,10 @@ def get_folders() -> list
4647

4748
The method includes a functionality to extract all folders inside the organization
4849

50+
Required Permissions:
51+
Action: folders:read
52+
Scope: folders:*
53+
4954
**Raises**:
5055

5156
- `Exception` - Unspecified error by executing the API call
@@ -69,6 +74,10 @@ The method includes a functionality to extract all folder information specified
6974

7075
- `uid` _str_ - Specify the uid of the folder
7176

77+
Required Permissions:
78+
- `Action` - folders:read
79+
- `Scope` - folders:*
80+
7281

7382
**Raises**:
7483

@@ -94,6 +103,10 @@ The method includes a functionality to extract all folder information specified
94103

95104
- `id` _int_ - Specify the id of the folder
96105

106+
Required Permissions:
107+
- `Action` - folders:read
108+
- `Scope` - folders:*
109+
97110

98111
**Raises**:
99112

@@ -110,7 +123,7 @@ The method includes a functionality to extract all folder information specified
110123
#### create\_folder
111124

112125
```python
113-
def create_folder(title: str, uid: str = None) -> dict
126+
def create_folder(title: str, uid: str = None, parent_uid: str = None) -> dict
114127
```
115128

116129
The method includes a functionality to create a new folder inside the organization specified by the defined title and the optional uid
@@ -119,6 +132,11 @@ The method includes a functionality to create a new folder inside the organizati
119132

120133
- `title` _str_ - Specify the title of the folder
121134
- `uid` _str_ - Specify the uid of the folder (default None)
135+
- `parent_uid` _str_ - Specify the parent_uid of the folder (default None)
136+
137+
Required Permissions:
138+
- `Action` - folders:create, folders:write
139+
- `Scope` - folders:*
122140

123141

124142
**Raises**:
@@ -151,6 +169,10 @@ The method includes a functionality to update a folder information inside the or
151169
- `version` _int_ - Specify the version of the folder (default 0)
152170
- `overwrite` _bool_ - Should the already existing folder information be overwritten (default False)
153171

172+
Required Permissions:
173+
- `Action` - folders:write
174+
- `Scope` - folders:*
175+
154176

155177
**Raises**:
156178

@@ -162,6 +184,36 @@ The method includes a functionality to update a folder information inside the or
162184

163185
- `api_call` _dict_ - Returns an updated folder
164186

187+
<a id="folder.Folder.move_folder"></a>
188+
189+
#### move\_folder
190+
191+
```python
192+
def move_folder(uid: str, parent_uid: str = None)
193+
```
194+
195+
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
196+
197+
**Arguments**:
198+
199+
- `uid` _str_ - Specify the uid of the folder
200+
- `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)
201+
202+
Required Permissions:
203+
- `Action` - folders:create, folders:write
204+
- `Scope` - folders:*, folders:uid:<destination folder UID>
205+
206+
207+
**Raises**:
208+
209+
- `ValueError` - Missed specifying a necessary value
210+
- `Exception` - Unspecified error by executing the API call
211+
212+
213+
**Returns**:
214+
215+
- `api_call` _dict_ - Returns the moved folder
216+
165217
<a id="folder.Folder.delete_folder"></a>
166218

167219
#### delete\_folder
@@ -176,6 +228,10 @@ The method includes a functionality to delete a folder inside the organization s
176228

177229
- `uid` _str_ - Specify the uid of the folder
178230

231+
Required Permissions:
232+
- `Action` - folders:delete
233+
- `Scope` - folders:*
234+
179235

180236
**Raises**:
181237

@@ -201,6 +257,10 @@ The method includes a functionality to extract the folder permissions inside the
201257

202258
- `uid` _str_ - Specify the uid of the folder
203259

260+
Required Permissions:
261+
- `Action` - folders.permissions:read
262+
- `Scope` - folders:*
263+
204264

205265
**Raises**:
206266

@@ -227,6 +287,10 @@ The method includes a functionality to update the folder permissions based on th
227287
- `uid` _str_ - Specify the uid of the folder
228288
- `permission_json` _dict_ - Specify the inserted permissions as dict
229289

290+
Required Permissions:
291+
- `Action` - folders.permissions:write
292+
- `Scope` - folders:*
293+
230294

231295
**Raises**:
232296

Diff for: docs/coverage.svg

+2-2
Loading

Diff for: grafana_api/alerting.py

+31-15
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ def delete_alertmanager_silence_by_id(
151151
RequestsMethods.DELETE,
152152
)
153153

154-
if (
155-
api_call == dict()
156-
or api_call.get("message")
157-
!= "silence deleted"
158-
):
154+
if api_call == dict() or api_call.get("message") != "silence deleted":
159155
logging.error(f"Please, check the error: {api_call}.")
160156
raise Exception
161157
else:
@@ -258,7 +254,9 @@ def create_or_update_alertmanager_silence(
258254
json.dumps(silence_json_dict),
259255
)
260256

261-
if api_call == dict() or (api_call.get("id") is None and api_call.get("silenceID") is None):
257+
if api_call == dict() or (
258+
api_call.get("id") is None and api_call.get("silenceID") is None
259+
):
262260
logging.error(f"Check the error: {api_call}.")
263261
raise Exception
264262
else:
@@ -661,7 +659,12 @@ def create_or_update_ruler_group_by_namespace(
661659
None
662660
"""
663661

664-
if len(datasource_uid) != 0 and len(namespace) != 0 and len(group_name) != 0 and rules != list():
662+
if (
663+
len(datasource_uid) != 0
664+
and len(namespace) != 0
665+
and len(group_name) != 0
666+
and rules != list()
667+
):
665668
rules_json_list: list = list()
666669

667670
for rule in rules:
@@ -696,7 +699,9 @@ def create_or_update_ruler_group_by_namespace(
696699
else:
697700
logging.info("You successfully created an ruler group.")
698701
else:
699-
logging.error("There is no datasource_uid, namespace, name or rules defined.")
702+
logging.error(
703+
"There is no datasource_uid, namespace, name or rules defined."
704+
)
700705
raise ValueError
701706

702707
def delete_ruler_group(
@@ -729,7 +734,9 @@ def delete_ruler_group(
729734
else:
730735
logging.info("You successfully deleted a ruler group.")
731736
else:
732-
logging.error("There is no datasource_uid, namespace or group_name defined.")
737+
logging.error(
738+
"There is no datasource_uid, namespace or group_name defined."
739+
)
733740
raise ValueError
734741

735742
def get_ruler_group(
@@ -761,7 +768,9 @@ def get_ruler_group(
761768
else:
762769
return api_call
763770
else:
764-
logging.error("There is no datasource_uid, namespace or group_name defined.")
771+
logging.error(
772+
"There is no datasource_uid, namespace or group_name defined."
773+
)
765774
raise ValueError
766775

767776
def test_rule(self, data_query: list) -> dict:
@@ -823,7 +832,11 @@ def test_rule(self, data_query: list) -> dict:
823832
raise ValueError
824833

825834
def test_datasource_uid_rule(
826-
self, expr: str, condition: str, data_query: list, datasource_uid: str = "grafana"
835+
self,
836+
expr: str,
837+
condition: str,
838+
data_query: list,
839+
datasource_uid: str = "grafana",
827840
) -> dict:
828841
"""The method includes a functionality to test a datasource uid rule specified by the expr, the condition, a list of data queries and the datasource_uid
829842
@@ -841,7 +854,12 @@ def test_datasource_uid_rule(
841854
api_call (dict): Returns the result of the specified datasource_uid rule
842855
"""
843856

844-
if len(datasource_uid) != 0 and len(expr) != 0 and len(condition) != 0 and data_query != list():
857+
if (
858+
len(datasource_uid) != 0
859+
and len(expr) != 0
860+
and len(condition) != 0
861+
and data_query != list()
862+
):
845863
datasource_rule_query_objects_json: list = list()
846864
datasource_rule_query_object_json: dict = dict()
847865

@@ -1045,9 +1063,7 @@ def create_or_update_ngalert_organization_configuration(
10451063
"You successfully created an NGAlert organization configuration."
10461064
)
10471065
else:
1048-
logging.error(
1049-
"There is no alert_managers or alertmanagers_choice defined."
1050-
)
1066+
logging.error("There is no alert_managers or alertmanagers_choice defined.")
10511067
raise ValueError
10521068

10531069
def get_ngalert_alertmanagers_by_organization(self) -> dict:

0 commit comments

Comments
 (0)