Skip to content

Commit 4da9451

Browse files
feat: Adjust the TLS/ mTLS documentation (#27)
* feat: Adjust the TLS/ mTLS documentation * docs: Add coverage badge and documentation --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 916a54d commit 4da9451

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,43 @@ with open("/tmp/test/test.json") as file:
349349
dashboard.create_or_update_dashboard(message="Create a new test dashboard", dashboard_json=json_dashboard, dashboard_path="test")
350350
```
351351

352+
## TLS/ mTLS
353+
354+
It is possible to pass a custom ssl_context to the underlying library to perform the requests to the HTTP API. For this step and to support custom TLS/ mTLS, there is an option to inject the Python ssl_context. More information can be found [here](https://docs.python.org/3/library/ssl.html#ssl.create_default_context) and a dummy TLS/ mTLS implementation below.
355+
356+
### TLS
357+
358+
```python
359+
import ssl
360+
361+
from grafana_api.model import APIModel
362+
363+
ssl_ctx = ssl.create_default_context(
364+
ssl.Purpose.SERVER_AUTH,
365+
cafile="/test/path/ca.crt"
366+
)
367+
ssl_ctx.verify_mode = ssl.CERT_REQUIRED
368+
369+
model: APIModel = APIModel(host="test", token="test", ssl_context=ssl_ctx)
370+
```
371+
372+
### mTLS
373+
374+
```python
375+
import ssl
376+
377+
from grafana_api.model import APIModel
378+
379+
ssl_ctx = ssl.create_default_context(
380+
ssl.Purpose.SERVER_AUTH,
381+
cafile="/test/path/ca.crt",
382+
)
383+
ssl_ctx.verify_mode = ssl.CERT_REQUIRED
384+
ssl_ctx.load_cert_chain(certfile="/test/path/client.crt", keyfile="/test/path/client.key",)
385+
386+
model: APIModel = APIModel(host="test", token="test", ssl_context=ssl_ctx)
387+
```
388+
352389
## Templating
353390
If you want to template your JSON document based on a predefined folder structure you can check out one of my other [project](https://github.com/ZPascal/grafana_dashboard_templater) and integrate the functionality inside your code.
354391

docs/content/index.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,42 @@ with open("/tmp/test/test.json") as file:
5757
dashboard.create_or_update_dashboard(message="Create a new test dashboard", dashboard_json=json_dashboard, dashboard_path="test")
5858
```
5959

60+
## TLS/ mTLS
61+
62+
It is possible to pass a custom ssl_context to the underlying library to perform the requests to the HTTP API. For this step and to support custom TLS/ mTLS, there is an option to inject the Python ssl_context. More information can be found [here](https://docs.python.org/3/library/ssl.html#ssl.create_default_context) and a dummy TLS/ mTLS implementation below.
63+
64+
### TLS
65+
66+
```python
67+
import ssl
68+
69+
from grafana_api.model import APIModel
70+
71+
ssl_ctx = ssl.create_default_context(
72+
ssl.Purpose.SERVER_AUTH,
73+
cafile="/test/path/ca.crt"
74+
)
75+
ssl_ctx.verify_mode = ssl.CERT_REQUIRED
76+
77+
model: APIModel = APIModel(host="test", token="test", ssl_context=ssl_ctx)
78+
```
79+
80+
### mTLS
81+
82+
```python
83+
import ssl
84+
85+
from grafana_api.model import APIModel
86+
87+
ssl_ctx = ssl.create_default_context(
88+
ssl.Purpose.SERVER_AUTH,
89+
cafile="/test/path/ca.crt",
90+
)
91+
ssl_ctx.verify_mode = ssl.CERT_REQUIRED
92+
ssl_ctx.load_cert_chain(certfile="/test/path/client.crt", keyfile="/test/path/client.key",)
93+
94+
model: APIModel = APIModel(host="test", token="test", ssl_context=ssl_ctx)
95+
```
96+
6097
## Templating
6198
If you want to template your JSON document based on a predefined folder structure you can check out one of my other [project](https://github.com/ZPascal/grafana_dashboard_templater) and integrate the functionality inside your code.

docs/grafana_api_sdk.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,42 @@ with open("/tmp/test/test.json") as file:
5757
dashboard.create_or_update_dashboard(message="Create a new test dashboard", dashboard_json=json_dashboard, dashboard_path="test")
5858
```
5959

60+
## TLS/ mTLS
61+
62+
It is possible to pass a custom ssl_context to the underlying library to perform the requests to the HTTP API. For this step and to support custom TLS/ mTLS, there is an option to inject the Python ssl_context. More information can be found [here](https://docs.python.org/3/library/ssl.html#ssl.create_default_context) and a dummy TLS/ mTLS implementation below.
63+
64+
### TLS
65+
66+
```python
67+
import ssl
68+
69+
from grafana_api.model import APIModel
70+
71+
ssl_ctx = ssl.create_default_context(
72+
ssl.Purpose.SERVER_AUTH,
73+
cafile="/test/path/ca.crt"
74+
)
75+
ssl_ctx.verify_mode = ssl.CERT_REQUIRED
76+
77+
model: APIModel = APIModel(host="test", token="test", ssl_context=ssl_ctx)
78+
```
79+
80+
### mTLS
81+
82+
```python
83+
import ssl
84+
85+
from grafana_api.model import APIModel
86+
87+
ssl_ctx = ssl.create_default_context(
88+
ssl.Purpose.SERVER_AUTH,
89+
cafile="/test/path/ca.crt",
90+
)
91+
ssl_ctx.verify_mode = ssl.CERT_REQUIRED
92+
ssl_ctx.load_cert_chain(certfile="/test/path/client.crt", keyfile="/test/path/client.key",)
93+
94+
model: APIModel = APIModel(host="test", token="test", ssl_context=ssl_ctx)
95+
```
96+
6097
## Templating
6198
If you want to template your JSON document based on a predefined folder structure you can check out one of my other [project](https://github.com/ZPascal/grafana_dashboard_templater) and integrate the functionality inside your code.

0 commit comments

Comments
 (0)