From 457d03be24aaba64d8cbd1356a5b36d808264e49 Mon Sep 17 00:00:00 2001 From: Pradip Patil <234066+pradippatil@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:41:28 -0400 Subject: [PATCH] Add SSL Support to InfluxDB Connection (#45) --- README.md | 3 +++ .../lib/configuration/gh_configuration.py | 21 +++++++++++++++++++ .../lib/fixtures/grasshopper_constants.py | 2 ++ src/grasshopper/lib/grasshopper.py | 7 ++++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e933382..266c61d 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,9 @@ within that YAML file that corresponds to the scenario you wish to run. Defaults you must specify a host. E.g. `1.1.1.1`. Defaults to None. - `--influx_port`: Port for your `influx_host` in the case where it is non-default. +- `--influx_ssl`: If your influxdb is using SSL, set this to True. Defaults to False. +- `--influx_verify_ssl`: If your influxdb is using SSL, set this to True. Defaults to + False. - `--influx_user`: Username for your `influx_host`, if you have one. - `--influx_pwd`: Password for your `influx_host`, if you have one. - `--grafana_host`: If your grafana is a separate URL from the influxdb, you can diff --git a/src/grasshopper/lib/configuration/gh_configuration.py b/src/grasshopper/lib/configuration/gh_configuration.py index cd456be..e04153d 100644 --- a/src/grasshopper/lib/configuration/gh_configuration.py +++ b/src/grasshopper/lib/configuration/gh_configuration.py @@ -94,6 +94,27 @@ class ConfigurationConstants: "help": "Password to connect to the influx host.", }, }, + "influx_ssl": { + "opts": ["--influx_ssl"], + "attrs": { + "action": "store", + "type": bool, + "help": "Enable SSL for InfluxDB connection.", + }, + "typecast": typecast_bool, + "default": False, + }, + + "influx_verify_ssl": { + "opts": ["--influx_verify_ssl"], + "attrs": { + "action": "store", + "type": bool, + "help": "Enable SSL certificate verification for InfluxDB connection.", + }, + "typecast": typecast_bool, + "default": False, + }, "grafana_host": { "opts": ["--grafana_host"], "attrs": { diff --git a/src/grasshopper/lib/fixtures/grasshopper_constants.py b/src/grasshopper/lib/fixtures/grasshopper_constants.py index a2277f8..f6a5dd4 100644 --- a/src/grasshopper/lib/fixtures/grasshopper_constants.py +++ b/src/grasshopper/lib/fixtures/grasshopper_constants.py @@ -17,6 +17,8 @@ class GrasshopperConstants: "influx_port", "influx_user", "influx_pwd", + "influx_ssl", + "influx_verify_ssl", "grafana_host", "shape_instance", "scenario_delay", diff --git a/src/grasshopper/lib/grasshopper.py b/src/grasshopper/lib/grasshopper.py index d23f408..a03c7b3 100644 --- a/src/grasshopper/lib/grasshopper.py +++ b/src/grasshopper/lib/grasshopper.py @@ -40,7 +40,8 @@ def log(self) -> None: logger.info("--- /Grasshopper configuration ---") @property - def influx_configuration(self) -> dict[str, Optional[str]]: + def influx_configuration(self) -> dict[str, Optional[Union[bool, str]]]: + """Extract the influx related configuration items. The InfluxDbSettings object should only get keys if there is a @@ -67,6 +68,10 @@ def influx_configuration(self) -> dict[str, Optional[str]]: if pwd: configuration["pwd"] = pwd + configuration["ssl"] = self.global_configuration.get("influx_ssl", False) + + configuration["verify_ssl"] = self.global_configuration.get("influx_verify_ssl", False) + return configuration @property