@@ -84,22 +84,31 @@ exercises could be useful for others, don't hesitate to share them back.
8484
8585## Authentication
8686
87- There are two ways to authenticate to the Grafana API. Either use an API token,
88- or HTTP basic auth.
87+ There are several ways to authenticate to the Grafana HTTP API.
8988
90- To use the admin API, you need to use HTTP Basic Authentication, as stated at
91- the [ Grafana Admin API documentation] .
89+ 1 . Anonymous access
90+ 2 . Grafana API token
91+ 3 . HTTP Basic Authentication
92+ 4 . HTTP Header Authentication
93+
94+ The [ Grafana Admin API] is a subset of the Grafana API. For accessing those API
95+ resources, you will need to use HTTP Basic Authentication.
9296
9397``` python
94- from grafana_client import GrafanaApi
98+ from grafana_client import GrafanaApi, HeaderAuth, TokenAuth
99+
100+ # 1. Anonymous access
101+ grafana = GrafanaApi.from_url(
102+ url = " https://daq.example.org/grafana/" ,
103+ )
95104
96- # Use Grafana API token.
105+ # 2. Use Grafana API token.
97106grafana = GrafanaApi.from_url(
98107 url = " https://daq.example.org/grafana/" ,
99- credential = " eyJrIjoiWHg...dGJpZCI6MX0=" ,
108+ credential = TokenAuth( token = " eyJrIjoiWHg...dGJpZCI6MX0=" ) ,
100109)
101110
102- # Use HTTP basic authentication.
111+ # 3. Use HTTP basic authentication.
103112grafana = GrafanaApi.from_url(
104113 url = " https://username:[email protected] /grafana/" ,
105114)
@@ -108,6 +117,12 @@ grafana = GrafanaApi.from_url(
108117 credential = (" username" , " password" )
109118)
110119
120+ # 4. Use HTTP Header authentication.
121+ grafana = GrafanaApi.from_url(
122+ url = " https://daq.example.org/grafana/" ,
123+ credential = HeaderAuth(name = " X-WEBAUTH-USER" , value = " foobar" ),
124+ )
125+
111126# Optionally turn off TLS certificate verification.
112127grafana = GrafanaApi.from_url(
113128 url = " https://username:[email protected] /grafana/?verify=false" ,
@@ -117,6 +132,10 @@ grafana = GrafanaApi.from_url(
117132grafana = GrafanaApi.from_env()
118133```
119134
135+ Please note that, on top of the specific examples above, the object obtained by
136+ ` credential ` can be an arbitrary ` requests.auth.AuthBase ` instance.
137+
138+
120139## Proxy
121140
122141The underlying ` requests ` library honors the ` HTTP_PROXY ` and ` HTTPS_PROXY `
@@ -265,6 +284,6 @@ poe test
265284[ examples folder ] : https://github.com/panodata/grafana-client/tree/main/examples
266285[ future maintenance of `grafana_api` ] : https://github.com/m0nhawk/grafana_api/issues/88
267286[ grafana_api ] : https://github.com/m0nhawk/grafana_api
268- [ Grafana Admin API documentation ] : https://grafana.com/docs/grafana/latest/http_api/admin/
287+ [ Grafana Admin API ] : https://grafana.com/docs/grafana/latest/http_api/admin/
269288[ Grafana HTTP API reference ] : https://grafana.com/docs/grafana/latest/http_api/
270289[ LICENSE ] : https://github.com/panodata/grafana-client/blob/main/LICENSE
0 commit comments