@@ -84,22 +84,31 @@ exercises could be useful for others, don't hesitate to share them back.
84
84
85
85
## Authentication
86
86
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.
89
88
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.
92
96
93
97
``` 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
+ )
95
104
96
- # Use Grafana API token.
105
+ # 2. Use Grafana API token.
97
106
grafana = GrafanaApi.from_url(
98
107
url = " https://daq.example.org/grafana/" ,
99
- credential = " eyJrIjoiWHg...dGJpZCI6MX0=" ,
108
+ credential = TokenAuth( token = " eyJrIjoiWHg...dGJpZCI6MX0=" ) ,
100
109
)
101
110
102
- # Use HTTP basic authentication.
111
+ # 3. Use HTTP basic authentication.
103
112
grafana = GrafanaApi.from_url(
104
113
url = " https://username:[email protected] /grafana/" ,
105
114
)
@@ -108,6 +117,12 @@ grafana = GrafanaApi.from_url(
108
117
credential = (" username" , " password" )
109
118
)
110
119
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
+
111
126
# Optionally turn off TLS certificate verification.
112
127
grafana = GrafanaApi.from_url(
113
128
url = " https://username:[email protected] /grafana/?verify=false" ,
@@ -117,6 +132,10 @@ grafana = GrafanaApi.from_url(
117
132
grafana = GrafanaApi.from_env()
118
133
```
119
134
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
+
120
139
## Proxy
121
140
122
141
The underlying ` requests ` library honors the ` HTTP_PROXY ` and ` HTTPS_PROXY `
@@ -265,6 +284,6 @@ poe test
265
284
[ examples folder ] : https://github.com/panodata/grafana-client/tree/main/examples
266
285
[ future maintenance of `grafana_api` ] : https://github.com/m0nhawk/grafana_api/issues/88
267
286
[ 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/
269
288
[ Grafana HTTP API reference ] : https://grafana.com/docs/grafana/latest/http_api/
270
289
[ LICENSE ] : https://github.com/panodata/grafana-client/blob/main/LICENSE
0 commit comments