Skip to content

Commit

Permalink
expose httpx option to skip validation of server https cert
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-vince committed Dec 28, 2023
1 parent ed8e153 commit 9855c63
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ docker run grafana-dashboard-manager \
##  Notes

- The scheme is `https` and port is 443 by default. If your Grafana is not hosted with https on 443, the scheme and port needs to be specified using the `--scheme` and `--port` options respectively.
- If you use self signed certs on the Grafana server or otherwise don't want to validate an HTTPS connection, use `--skip-verify` although this is not recommended.
- The `version` of the dashboard is removed of the json files in order to allow overwriting and creation of dashboards as new.
- URL encoding of strings is handled by httpx and so characters such as `/` in folder names is supported.
- When uploading, setting the home dashboard from the `home.json` file can be disabled with the option `--skip-home`.
Expand Down
20 changes: 12 additions & 8 deletions grafana_dashboard_manager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def app():
parent_parser.add_argument(
"--skip-home", default=False, action=argparse.BooleanOptionalAction, help="Do not set the home dashboard"
)
parent_parser.add_argument(
"--skip-verify", default=False, action=argparse.BooleanOptionalAction, help="Skip HTTPS server cert validation"
)

# Add subcommands
sub_parsers = parser.add_subparsers(title="Commands", required=True, help="Read/Write Dashboard JSONs:")
Expand Down Expand Up @@ -76,14 +79,15 @@ def app():

# API Client
client = GrafanaApi(
config.scheme,
config.host,
config.port,
config.username,
config.password,
config.token,
config.org,
args.verbose > 0,
scheme=config.scheme,
host=config.host,
port=config.port,
username=config.username,
password=config.password,
token=config.token,
org=config.org,
skip_verify=config.skip_verify,
verbose=args.verbose > 0,
)

# Run the desired command
Expand Down
5 changes: 3 additions & 2 deletions grafana_dashboard_manager/api/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
class RestClient:
"""Provides RESTful calls"""

def __init__(self, headers, auth, base_url, verbose):
def __init__(self, headers, auth, base_url, skip_verify, verbose):
"""
Wrapper on the httpx client to centralise request level exception handling
Args:
headers: common headers to apply to all requests
auth: an httpx auth object
base_url: url host
skip_verify: set to true to skip verification of https connection certs
verbose: increased logging output
"""
self.client = httpx.Client(headers=headers, auth=auth, base_url=base_url)
self.client = httpx.Client(headers=headers, auth=auth, base_url=base_url, verify=skip_verify)
self.verbose = verbose

def get(self, resource: str) -> httpx.Response:
Expand Down
2 changes: 2 additions & 0 deletions grafana_dashboard_manager/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class GlobalConfig(BaseModel):
password: str | None = None
token: str | None = None
org: int | None = None
skip_verify: bool = False

non_interactive: bool = False
skip_home: bool = False

Expand Down
2 changes: 2 additions & 0 deletions grafana_dashboard_manager/grafana/grafana_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(
password: str | None = None,
token: str | None = None,
org: int | None = None,
skip_verify: bool = False,
verbose: bool = False,
) -> None:
"""Wrapper object to interact with Grafana entities like Folders and Dashboards via the HTTP API"""
Expand All @@ -45,6 +46,7 @@ def __init__(
self.CLIENT_HEADERS,
self._init_auth(token, username, password),
f"{self.host}/api/",
skip_verify,
verbose,
)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "grafana_dashboard_manager"
version = "0.2.4"
version = "0.2.5"
description = "A cli utility that uses Grafana's HTTP API to easily save and restore dashboards."
authors = ["Vince Chan <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 9855c63

Please sign in to comment.