-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path__init__.py
More file actions
41 lines (33 loc) · 1.06 KB
/
__init__.py
File metadata and controls
41 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
from typing import Any
from dotenv import load_dotenv
from config.common import ConfigurationSource
from config.common.files import PathType
class EnvironmentVariables(ConfigurationSource):
def __init__(
self,
prefix: str | None = None,
strip_prefix: bool = True,
file: PathType | None = None,
) -> None:
super().__init__()
self.prefix = prefix
self.strip_prefix = strip_prefix
self._file = file
def get_values(self) -> dict[str, Any]:
if self._file:
load_dotenv(self._file)
values = {}
prefix = self.prefix
strip_prefix = self.strip_prefix
if prefix:
prefix = prefix.lower()
for key, value in os.environ.items():
key_lower = key.lower()
if prefix and not key_lower.startswith(prefix):
continue
if prefix and strip_prefix:
key_lower = key_lower[len(prefix) :]
values[key_lower] = value
return values
EnvVars = EnvironmentVariables