feat: adds support for headers to InfluxDBv1Session and InfluxDBSession

This commit is contained in:
Mose Mueller 2025-05-05 11:34:53 +02:00
parent 854fc49c75
commit 9dc0b23a3f
3 changed files with 9 additions and 0 deletions

View File

@ -29,6 +29,7 @@ class InfluxDBConfig(BaseConfig): # type: ignore
url: str
org: str
token: SecretStr
headers: dict[str, str] = {} # noqa: RUF012
class InfluxDBv1Config(BaseConfig): # type: ignore
@ -39,3 +40,4 @@ class InfluxDBv1Config(BaseConfig): # type: ignore
database: str
ssl: bool = True
verify_ssl: bool = True
headers: dict[str, str] = {} # noqa: RUF012

View File

@ -80,12 +80,17 @@ class InfluxDBSession:
self.url = self._config.url
self.token = self._config.token.get_secret_value()
self.org = self._config.org
self.headers = self._config.headers
self._client: InfluxDBClient
self._write_api: WriteApi
self._buckets_api: BucketsApi
def __enter__(self) -> Self:
self._client = InfluxDBClient(url=self.url, token=self.token, org=self.org)
for header_name, header_value in self.headers.items():
self._client.api_client.set_default_header(header_name, header_value)
self._write_api = self._client.write_api(write_options=SYNCHRONOUS) # type: ignore
return self

View File

@ -65,6 +65,7 @@ class InfluxDBv1Session:
self._database = self._config.database
self._ssl = self._config.ssl
self._verify_ssl = self._config.verify_ssl
self._headers = self._config.headers
def __enter__(self) -> Self:
self._client = influxdb.InfluxDBClient(
@ -75,6 +76,7 @@ class InfluxDBv1Session:
database=self._database,
ssl=self._ssl,
verify_ssl=self._verify_ssl,
headers=self._headers,
)
return self