Skip to content

Commit 26389a2

Browse files
feat: Add team sync and public dashboard support (#52)
* feat: Add team sync support * feat: Add public dashboard support * feat: Add new unit and integration tests * docs: Add the documentation * feat: Adjust the GH action --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 6f3c530 commit 26389a2

File tree

17 files changed

+1106
-12
lines changed

17 files changed

+1106
-12
lines changed

Diff for: .github/workflows/integrationtest.yml

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
GRAFANA_PASSWORD: ${{ secrets.GRAFANA_PASSWORD }}
4141
HTTP2: "False"
4242

43+
- name: Wait 20 seconds
44+
run: sleep 20
45+
4346
- name: Execute the integrationtests (http2)
4447
run: python3 -m unittest discover tests/integrationtest
4548
env:

Diff for: .github/workflows/pull-request-checks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ jobs:
109109
with:
110110
github_token: ${{ secrets.GITHUB_TOKEN }}
111111
branch: ${{ github.head_ref }}
112+
atomic: false
112113

113114
pr-documentation:
114115
runs-on: ubuntu-latest

Diff for: README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ The core features that are implemented inside this library:
1313

1414
In general, my focus on this project is to implement and deliver old and new features from the Grafana API, to document all features and functionality clear,ly and to increase the overall test coverage of the project.
1515

16-
## TODO
17-
- [ ] [Team Sync](https://grafana.com/docs/grafana/latest/developers/http_api/team_sync/)
18-
- [ ] [Public Dashboard](https://grafana.com/docs/grafana/latest/developers/http_api/dashboard_public/)
19-
2016
## Currently, supported features
2117

2218
### Dashboard
@@ -33,6 +29,11 @@ In general, my focus on this project is to implement and deliver old and new fea
3329
- Restore a dashboard version of a specific dashboard
3430
- Restore a dashboard version of a specific dashboard by uid
3531
- Compare two dashboard versions and extract the diff between booth dashboards
32+
- Get public dashboards
33+
- Get public dashboard by uid
34+
- Create public dashboard
35+
- Update public dashboard
36+
- Delete public dashboard
3637

3738
### Folder
3839
- Get folder id by dashboard path
@@ -202,6 +203,9 @@ In general, my focus on this project is to implement and deliver old and new fea
202203
- Delete team member
203204
- Get team preferences
204205
- Update team preferences
206+
- Get external team groups
207+
- Add external team group
208+
- Delete external team group
205209

206210
### Legacy Playlist
207211
- Search playlist

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

+164
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
* [restore\_dashboard\_version](#dashboard.Dashboard.restore_dashboard_version)
2020
* [restore\_dashboard\_version\_by\_uid](#dashboard.Dashboard.restore_dashboard_version_by_uid)
2121
* [calculate\_dashboard\_diff](#dashboard.Dashboard.calculate_dashboard_diff)
22+
* [get\_public\_dashboards](#dashboard.Dashboard.get_public_dashboards)
23+
* [get\_public\_dashboard\_by\_uid](#dashboard.Dashboard.get_public_dashboard_by_uid)
24+
* [create\_public\_dashboard](#dashboard.Dashboard.create_public_dashboard)
25+
* [update\_public\_dashboard](#dashboard.Dashboard.update_public_dashboard)
26+
* [delete\_public\_dashboard](#dashboard.Dashboard.delete_public_dashboard)
2227

2328
<a id="dashboard"></a>
2429

@@ -476,3 +481,162 @@ The method includes a functionality to calculate the diff of specified versions
476481

477482
- `api_call` _str_ - Returns the difference of the two specified dashboards
478483

484+
<a id="dashboard.Dashboard.get_public_dashboards"></a>
485+
486+
#### get\_public\_dashboards
487+
488+
```python
489+
def get_public_dashboards(per_page: int = None, page: int = None) -> dict
490+
```
491+
492+
The method includes a functionality to get all public available dashboards
493+
494+
Required Permissions:
495+
Action: dashboards:read
496+
Scope: dashboards:uid:<dashboard UID>
497+
498+
**Arguments**:
499+
500+
- `per_page` _int_ - Specify the value per page size
501+
- `page` _int_ - Specify the page
502+
503+
504+
**Raises**:
505+
506+
- `Exception` - Unspecified error by executing the API call
507+
508+
509+
**Returns**:
510+
511+
- `api_call` _dict_ - Returns all public available dashboards
512+
513+
<a id="dashboard.Dashboard.get_public_dashboard_by_uid"></a>
514+
515+
#### get\_public\_dashboard\_by\_uid
516+
517+
```python
518+
def get_public_dashboard_by_uid(dashboard_uid: str) -> dict
519+
```
520+
521+
The method includes a functionality to get a public available dashboard specified by dashboard_uid
522+
523+
Required Permissions:
524+
Action: dashboards:read
525+
Scope: dashboards:uid:<dashboard UID>
526+
527+
**Arguments**:
528+
529+
- `dashboard_uid` _str_ - Specify the dashboard_uid
530+
531+
532+
**Raises**:
533+
534+
- `ValueError` - Missed specifying a necessary value
535+
- `Exception` - Unspecified error by executing the API call
536+
537+
538+
**Returns**:
539+
540+
- `api_call` _dict_ - Returns the corresponding public available dashboard
541+
542+
<a id="dashboard.Dashboard.create_public_dashboard"></a>
543+
544+
#### create\_public\_dashboard
545+
546+
```python
547+
def create_public_dashboard(
548+
dashboard_uid: str, public_dashboard: PublicDashboard = PublicDashboard()
549+
) -> dict
550+
```
551+
552+
The method includes a functionality to create a public available dashboard
553+
554+
Required Permissions:
555+
Action: dashboards.public:write
556+
Scope: dashboards:uid:<dashboard UID>
557+
558+
**Arguments**:
559+
560+
- `dashboard_uid` _str_ - Specify the dashboard_uid
561+
- `public_dashboard` _PublicDashboard_ - Specify the optional public dashboard object
562+
563+
564+
**Raises**:
565+
566+
- `ValueError` - Missed specifying a necessary value
567+
- `Exception` - Unspecified error by executing the API call
568+
569+
570+
**Returns**:
571+
572+
- `api_call` _dict_ - Returns the corresponding public available dashboard
573+
574+
<a id="dashboard.Dashboard.update_public_dashboard"></a>
575+
576+
#### update\_public\_dashboard
577+
578+
```python
579+
def update_public_dashboard(dashboard_uid: str,
580+
public_dashboard_uid: str,
581+
time_selection_enabled: bool = None,
582+
is_enabled: bool = None,
583+
annotations_enabled: bool = None,
584+
share: str = None) -> dict
585+
```
586+
587+
The method includes a functionality to update a public available dashboard
588+
589+
Required Permissions:
590+
Action: dashboards.public:write
591+
Scope: dashboards:uid:<dashboard UID>
592+
593+
**Arguments**:
594+
595+
- `dashboard_uid` _str_ - Specify the dashboard_uid
596+
- `public_dashboard_uid` _str_ - Specify the public_dashboard_uid
597+
- `time_selection_enabled` _bool_ - Specify the optional enablement of the time picker inside the public dashboard (default None)
598+
- `is_enabled` _bool_ - Specify the optional enablement of the public dashboard (default None)
599+
- `annotations_enabled` _bool_ - Specify the optional enablement of the annotations inside the public dashboard (default None)
600+
- `share` _str_ - Specify the optional share mode of the public dashboard (default None)
601+
602+
603+
**Raises**:
604+
605+
- `ValueError` - Missed specifying a necessary value
606+
- `Exception` - Unspecified error by executing the API call
607+
608+
609+
**Returns**:
610+
611+
- `api_call` _dict_ - Returns the corresponding public available dashboard
612+
613+
<a id="dashboard.Dashboard.delete_public_dashboard"></a>
614+
615+
#### delete\_public\_dashboard
616+
617+
```python
618+
def delete_public_dashboard(dashboard_uid: str, public_dashboard_uid: str)
619+
```
620+
621+
The method includes a functionality to delete a public available dashboard
622+
623+
Required Permissions:
624+
Action: dashboards.public:write
625+
Scope: dashboards:uid:<dashboard UID>
626+
627+
**Arguments**:
628+
629+
- `dashboard_uid` _str_ - Specify the dashboard_uid
630+
- `public_dashboard_uid` _str_ - Specify the public_dashboard_uid
631+
632+
633+
**Raises**:
634+
635+
- `ValueError` - Missed specifying a necessary value
636+
- `Exception` - Unspecified error by executing the API call
637+
638+
639+
**Returns**:
640+
641+
None
642+

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

+21
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* [RolePermission](#model.RolePermission)
3737
* [CustomRole](#model.CustomRole)
3838
* [DatasourceCache](#model.DatasourceCache)
39+
* [PublicDashboard](#model.PublicDashboard)
3940

4041
<a id="model"></a>
4142

@@ -705,3 +706,23 @@ The class includes all necessary variables to generate a datasource cache object
705706
- `ttl_queries_ms` _int_ - Specify the TTL to use for query caching, in milliseconds
706707
- `ttl_resources_ms` _int_ - Specify the TTL to use for resource caching, in milliseconds
707708

709+
<a id="model.PublicDashboard"></a>
710+
711+
## PublicDashboard Objects
712+
713+
```python
714+
@dataclass
715+
class PublicDashboard()
716+
```
717+
718+
The class includes all necessary variables to generate a public dashboard object
719+
720+
**Arguments**:
721+
722+
- `uid` _str_ - Specify the optional unique identifier when creating a public dashboard. If it’s none, it will generate a new uid (default None)
723+
- `access_token` _str_ - Specify the optional unique access token. If it’s none, it will generate a new access token (default None)
724+
- `time_selection_enabled` _bool_ - Specify the optional enablement of the time picker inside the public dashboard (default False)
725+
- `is_enabled` _bool_ - Specify the optional enablement of the public dashboard (default False)
726+
- `annotations_enabled` _bool_ - Specify the optional enablement of the annotations inside the public dashboard (default False)
727+
- `share` _str_ - Specify the optional share mode of the public dashboard (default public)
728+

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

+93-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* [delete\_team\_member](#team.Team.delete_team_member)
1313
* [get\_team\_preferences](#team.Team.get_team_preferences)
1414
* [update\_team\_preferences](#team.Team.update_team_preferences)
15+
* [get\_external\_groups](#team.Team.get_external_groups)
16+
* [add\_external\_group](#team.Team.add_external_group)
17+
* [remove\_external\_group](#team.Team.remove_external_group)
1518

1619
<a id="team"></a>
1720

@@ -25,7 +28,7 @@
2528
class Team()
2629
```
2730

28-
The class includes all necessary methods to access the Grafana team API endpoints. Be aware that all functionalities inside the class only working with the corresponding access rights, please check the following page for details: https://grafana.com/docs/grafana/latest/http_api/team/`team`-api
31+
The class includes all necessary methods to access the Grafana team API endpoints. Be aware that all functionalities inside the class only working with the corresponding access rights, please check the following page for details: https://grafana.com/docs/grafana/latest/http_api/team/`team`-api & https://grafana.com/docs/grafana/latest/developers/http_api/team_sync/`team`-sync-api
2932

3033
HINT: Note Grafana Enterprise API need required permissions if fine-grained access control is enabled
3134

@@ -339,6 +342,95 @@ Scope: teams:*
339342
- `Exception` - Unspecified error by executing the API call
340343

341344

345+
**Returns**:
346+
347+
None
348+
349+
<a id="team.Team.get_external_groups"></a>
350+
351+
#### get\_external\_groups
352+
353+
```python
354+
def get_external_groups(id: int) -> list
355+
```
356+
357+
The method includes a functionality to get the team groups specified by the team_id. The functionality is a Grafana ENTERPRISE feature
358+
359+
Required Permissions:
360+
Action: teams.permissions:read
361+
Scope: teams:*
362+
363+
**Arguments**:
364+
365+
- `id` _int_ - Specify the team id
366+
367+
368+
**Raises**:
369+
370+
- `ValueError` - Missed specifying a necessary value
371+
- `Exception` - Unspecified error by executing the API call
372+
373+
374+
**Returns**:
375+
376+
- `api_call` _list_ - Returns the organization team groups
377+
378+
<a id="team.Team.add_external_group"></a>
379+
380+
#### add\_external\_group
381+
382+
```python
383+
def add_external_group(id: int, team_group: str)
384+
```
385+
386+
The method includes a functionality to add a group to the team specified by the team_id and the team_group. The functionality is a Grafana ENTERPRISE feature
387+
388+
Required Permissions:
389+
Action: teams.permissions:write
390+
Scope: teams:*
391+
392+
**Arguments**:
393+
394+
- `id` _int_ - Specify the team id
395+
- `team_group` _str_ - Specify the team group
396+
397+
398+
**Raises**:
399+
400+
- `ValueError` - Missed specifying a necessary value
401+
- `Exception` - Unspecified error by executing the API call
402+
403+
404+
**Returns**:
405+
406+
None
407+
408+
<a id="team.Team.remove_external_group"></a>
409+
410+
#### remove\_external\_group
411+
412+
```python
413+
def remove_external_group(id: int, team_group: str)
414+
```
415+
416+
The method includes a functionality to remove a group from a team specified by the team_id and the team_group. The functionality is a Grafana ENTERPRISE feature
417+
418+
Required Permissions:
419+
Action: teams.permissions:write
420+
Scope: teams:*
421+
422+
**Arguments**:
423+
424+
- `id` _int_ - Specify the team id
425+
- `team_group` _str_ - Specify the team group
426+
427+
428+
**Raises**:
429+
430+
- `ValueError` - Missed specifying a necessary value
431+
- `Exception` - Unspecified error by executing the API call
432+
433+
342434
**Returns**:
343435

344436
None

Diff for: docs/content/index.md

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ The following list describes the currently supported features of the Grafana API
1818
- [x] [Alerting Notification Channels HTTP API](https://grafana.com/docs/grafana/latest/http_api/alerting_notification_channels/)
1919
- [x] [Annotations HTTP API](https://grafana.com/docs/grafana/latest/http_api/annotations/)
2020
- [x] [Authentication HTTP API](https://grafana.com/docs/grafana/latest/http_api/auth/)
21+
- [x] [Dashboard](https://grafana.com/docs/grafana/latest/developers/http_api/dashboard/)
22+
- [x] [Dashboard Permissions](https://grafana.com/docs/grafana/latest/developers/http_api/dashboard_permissions/)
23+
- [x] [Dashboard Versions](https://grafana.com/docs/grafana/latest/developers/http_api/dashboard_versions/)
24+
- [x] [Public Dashboard](https://grafana.com/docs/grafana/latest/developers/http_api/dashboard_public/)
2125
- [x] [Data source HTTP API](https://grafana.com/docs/grafana/latest/http_api/data_source/)
2226
- [x] [Datasource query and resource caching](https://grafana.com/docs/grafana/latest/developers/http_api/query_and_resource_caching/)
2327
- [x] [Datasource Permissions HTTP API](https://grafana.com/docs/grafana/latest/http_api/datasource_permissions/)
@@ -37,6 +41,7 @@ The following list describes the currently supported features of the Grafana API
3741
- [x] [Reporting API](https://grafana.com/docs/grafana/latest/http_api/reporting/)
3842
- [x] [Short URL HTTP API](https://grafana.com/docs/grafana/latest/http_api/short_url/)
3943
- [x] [Team HTTP API](https://grafana.com/docs/grafana/latest/http_api/team/)
44+
- [x] [Team Sync](https://grafana.com/docs/grafana/latest/developers/http_api/team_sync/)
4045
- [x] [User HTTP API](https://grafana.com/docs/grafana/latest/http_api/user/)
4146
- [x] [Service Account HTTP API](https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/)
4247
- [x] [RBAC HTTP API](https://grafana.com/docs/grafana/latest/http_api/access_control/)

0 commit comments

Comments
 (0)