mirror of
https://github.com/tiqi-group/pydase_service_base.git
synced 2026-07-31 15:53:43 +02:00
Implement from_env method for InfluxDBv3Session
Add class method to create InfluxDBv3Session from environment variables.
This commit is contained in:
@@ -120,3 +120,32 @@ class InfluxDBv3Session:
|
||||
token=_config.token.get_secret_value(),
|
||||
verify_ssl=_config.verify_ssl,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_env(cls, path: str | PathLike | None = None) -> "InfluxDBv3Session":
|
||||
"""Create InfluxDBv3Session from environment variables.
|
||||
The variables should be prefixed by 'INFLUXDBV3_' and should reflect the
|
||||
attribute names of the Influxdbv3Config class.
|
||||
|
||||
Examples:
|
||||
INFLUXDBV3_URL=<influx server url>
|
||||
INFLUXDBV3_BUCKET=bucket
|
||||
etc...
|
||||
|
||||
Args:
|
||||
path (str | PathLike | None): Path to the configuration file.
|
||||
If None, variables are read from the environment. Otherwise,
|
||||
variables are read from the file but environment takes precedence.
|
||||
See https://confz.readthedocs.io/en/latest/reference/sources.html#confz.EnvSource
|
||||
|
||||
Returns:
|
||||
InfluxDBv3Session: An instance of InfluxDBv3Session.
|
||||
"""
|
||||
config = InfluxDBv3Config(config_sources=EnvSource(file=path, allow_all=True, prefix="INFLUXDBV3_"))
|
||||
return cls(
|
||||
host=config.url,
|
||||
org=config.org,
|
||||
bucket=config.bucket,
|
||||
token=config.token.get_secret_value(),
|
||||
verify_ssl=config.verify_ssl,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user