mirror of
https://github.com/tiqi-group/pydase_service_base.git
synced 2025-06-08 21:40:41 +02:00
feat: adds support for headers to InfluxDBv1Session and InfluxDBSession
This commit is contained in:
parent
854fc49c75
commit
9dc0b23a3f
@ -29,6 +29,7 @@ class InfluxDBConfig(BaseConfig): # type: ignore
|
|||||||
url: str
|
url: str
|
||||||
org: str
|
org: str
|
||||||
token: SecretStr
|
token: SecretStr
|
||||||
|
headers: dict[str, str] = {} # noqa: RUF012
|
||||||
|
|
||||||
|
|
||||||
class InfluxDBv1Config(BaseConfig): # type: ignore
|
class InfluxDBv1Config(BaseConfig): # type: ignore
|
||||||
@ -39,3 +40,4 @@ class InfluxDBv1Config(BaseConfig): # type: ignore
|
|||||||
database: str
|
database: str
|
||||||
ssl: bool = True
|
ssl: bool = True
|
||||||
verify_ssl: bool = True
|
verify_ssl: bool = True
|
||||||
|
headers: dict[str, str] = {} # noqa: RUF012
|
||||||
|
@ -80,12 +80,17 @@ class InfluxDBSession:
|
|||||||
self.url = self._config.url
|
self.url = self._config.url
|
||||||
self.token = self._config.token.get_secret_value()
|
self.token = self._config.token.get_secret_value()
|
||||||
self.org = self._config.org
|
self.org = self._config.org
|
||||||
|
self.headers = self._config.headers
|
||||||
self._client: InfluxDBClient
|
self._client: InfluxDBClient
|
||||||
self._write_api: WriteApi
|
self._write_api: WriteApi
|
||||||
self._buckets_api: BucketsApi
|
self._buckets_api: BucketsApi
|
||||||
|
|
||||||
def __enter__(self) -> Self:
|
def __enter__(self) -> Self:
|
||||||
self._client = InfluxDBClient(url=self.url, token=self.token, org=self.org)
|
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
|
self._write_api = self._client.write_api(write_options=SYNCHRONOUS) # type: ignore
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ class InfluxDBv1Session:
|
|||||||
self._database = self._config.database
|
self._database = self._config.database
|
||||||
self._ssl = self._config.ssl
|
self._ssl = self._config.ssl
|
||||||
self._verify_ssl = self._config.verify_ssl
|
self._verify_ssl = self._config.verify_ssl
|
||||||
|
self._headers = self._config.headers
|
||||||
|
|
||||||
def __enter__(self) -> Self:
|
def __enter__(self) -> Self:
|
||||||
self._client = influxdb.InfluxDBClient(
|
self._client = influxdb.InfluxDBClient(
|
||||||
@ -75,6 +76,7 @@ class InfluxDBv1Session:
|
|||||||
database=self._database,
|
database=self._database,
|
||||||
ssl=self._ssl,
|
ssl=self._ssl,
|
||||||
verify_ssl=self._verify_ssl,
|
verify_ssl=self._verify_ssl,
|
||||||
|
headers=self._headers,
|
||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user