orionis 0.286.0__py3-none-any.whl → 0.287.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orionis/metadata/framework.py +1 -1
- orionis/services/environment/contracts/env.py +45 -50
- orionis/services/environment/dot_env.py +205 -181
- orionis/services/environment/env.py +68 -85
- orionis/services/environment/exceptions/environment_value_error.py +18 -0
- orionis/services/environment/exceptions/environment_value_exception.py +23 -0
- orionis/services/environment/type_hint.py +559 -0
- orionis/test/logs/history.py +3 -5
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/METADATA +1 -1
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/RECORD +56 -54
- tests/example/test_example.py +5 -2
- tests/foundation/config/app/test_app.py +13 -3
- tests/foundation/config/auth/test_auth.py +9 -4
- tests/foundation/config/cache/test_cache.py +60 -15
- tests/foundation/config/cache/test_cache_file.py +62 -14
- tests/foundation/config/cache/test_cache_stores.py +74 -14
- tests/foundation/config/cors/test_cors.py +102 -33
- tests/foundation/config/database/test_database.py +38 -14
- tests/foundation/config/database/test_database_connections.py +79 -5
- tests/foundation/config/database/test_database_mysql.py +138 -15
- tests/foundation/config/database/test_database_oracle.py +110 -26
- tests/foundation/config/database/test_database_pgsql.py +96 -26
- tests/foundation/config/database/test_database_sqlite.py +56 -2
- tests/foundation/config/exceptions/test_exceptions_integrity.py +44 -10
- tests/foundation/config/filesystems/test_filesystems.py +64 -14
- tests/foundation/config/filesystems/test_filesystems_aws.py +45 -7
- tests/foundation/config/filesystems/test_filesystems_disks.py +78 -8
- tests/foundation/config/filesystems/test_filesystems_local.py +66 -18
- tests/foundation/config/filesystems/test_filesystems_public.py +37 -0
- tests/foundation/config/logging/test_logging.py +75 -11
- tests/foundation/config/logging/test_logging_channels.py +79 -2
- tests/foundation/config/logging/test_logging_chunked.py +85 -12
- tests/foundation/config/logging/test_logging_daily.py +79 -12
- tests/foundation/config/logging/test_logging_hourly.py +68 -2
- tests/foundation/config/logging/test_logging_monthly.py +48 -2
- tests/foundation/config/logging/test_logging_stack.py +49 -14
- tests/foundation/config/logging/test_logging_weekly.py +92 -2
- tests/foundation/config/mail/test_mail.py +87 -15
- tests/foundation/config/mail/test_mail_file.py +40 -4
- tests/foundation/config/mail/test_mail_mailers.py +56 -8
- tests/foundation/config/mail/test_mail_smtp.py +58 -14
- tests/foundation/config/queue/test_queue.py +62 -9
- tests/foundation/config/queue/test_queue_brokers.py +27 -10
- tests/foundation/config/queue/test_queue_database.py +53 -15
- tests/foundation/config/root/test_root_paths.py +69 -2
- tests/foundation/config/session/test_session.py +30 -1
- tests/foundation/config/startup/test_config_startup.py +77 -7
- tests/foundation/config/testing/test_testing.py +68 -0
- tests/patterns/singleton/test_singleton.py +10 -1
- tests/services/environment/test_env.py +3 -4
- tests/testing/test_testing_result.py +56 -19
- tests/testing/test_testing_unit.py +93 -24
- orionis/services/environment/exceptions/value_exception.py +0 -27
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/WHEEL +0 -0
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/top_level.txt +0 -0
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/zip-safe +0 -0
@@ -1,114 +1,97 @@
|
|
1
1
|
from orionis.services.environment.contracts.env import IEnv
|
2
2
|
from orionis.services.environment.dot_env import DotEnv
|
3
|
-
from typing import Any,
|
3
|
+
from typing import Any, Dict
|
4
4
|
|
5
|
-
def env(key: str, default: Any = None
|
5
|
+
def env(key: str, default: Any = None) -> Any:
|
6
6
|
"""
|
7
|
-
Retrieve the value of an environment variable
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
Retrieve the value of an environment variable.
|
8
|
+
|
9
|
+
Parameters
|
10
|
+
----------
|
11
|
+
key : str
|
12
|
+
The name of the environment variable to retrieve.
|
13
|
+
default : Any, optional
|
14
|
+
The value to return if the environment variable is not found. Default is None.
|
15
|
+
|
16
|
+
Returns
|
17
|
+
-------
|
18
|
+
Any
|
19
|
+
The value of the environment variable if it exists, otherwise the default value.
|
16
20
|
"""
|
17
|
-
|
21
|
+
dotenv = DotEnv()
|
22
|
+
return dotenv.get(key, default)
|
18
23
|
|
19
24
|
class Env(IEnv):
|
20
|
-
"""
|
21
|
-
Env is a utility class that provides static methods for managing environment variables
|
22
|
-
using the DotEnv class. It allows getting, setting, unsetting, listing, destroying,
|
23
|
-
and serializing environment variables.
|
24
|
-
"""
|
25
|
-
|
26
|
-
_dotenv_instance: Optional[DotEnv] = None
|
27
|
-
|
28
|
-
@classmethod
|
29
|
-
def _dotenv(cls) -> DotEnv:
|
30
|
-
"""
|
31
|
-
Returns a singleton instance of the DotEnv class.
|
32
|
-
|
33
|
-
If the instance does not exist, it creates a new one and stores it in the class attribute.
|
34
|
-
Subsequent calls will return the same instance.
|
35
|
-
|
36
|
-
Returns:
|
37
|
-
DotEnv: The singleton instance of the DotEnv class.
|
38
|
-
"""
|
39
|
-
if cls._dotenv_instance is None:
|
40
|
-
cls._dotenv_instance = DotEnv()
|
41
|
-
return cls._dotenv_instance
|
42
25
|
|
43
26
|
@staticmethod
|
44
|
-
def get(key: str, default: Any = None
|
27
|
+
def get(key: str, default: Any = None) -> Any:
|
45
28
|
"""
|
46
|
-
Retrieve the value of an environment variable.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
29
|
+
Retrieve the value of an environment variable by key.
|
30
|
+
|
31
|
+
Parameters
|
32
|
+
----------
|
33
|
+
key : str
|
34
|
+
The name of the environment variable to retrieve.
|
35
|
+
default : Any, optional
|
36
|
+
The value to return if the key is not found. Default is None.
|
37
|
+
|
38
|
+
Returns
|
39
|
+
-------
|
40
|
+
Any
|
41
|
+
The value of the environment variable if found, otherwise the default value.
|
55
42
|
"""
|
56
|
-
|
43
|
+
dotenv = DotEnv()
|
44
|
+
return dotenv.get(key, default)
|
57
45
|
|
58
46
|
@staticmethod
|
59
|
-
def set(key: str, value: str,
|
47
|
+
def set(key: str, value: str, type_hint: str = None) -> bool:
|
60
48
|
"""
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
49
|
+
Set an environment variable in the .env file.
|
50
|
+
|
51
|
+
Parameters
|
52
|
+
----------
|
53
|
+
key : str
|
54
|
+
The name of the environment variable to set.
|
55
|
+
value : str
|
56
|
+
The value to assign to the environment variable.
|
57
|
+
type_hint : str, optional
|
58
|
+
The type of the environment variable (e.g., 'str', 'int'). Default is None.
|
59
|
+
|
60
|
+
Returns
|
61
|
+
-------
|
62
|
+
bool
|
63
|
+
True if the variable was set successfully, False otherwise.
|
70
64
|
"""
|
71
|
-
|
65
|
+
dotenv = DotEnv()
|
66
|
+
return dotenv.set(key, value, type_hint)
|
72
67
|
|
73
68
|
@staticmethod
|
74
69
|
def unset(key: str) -> bool:
|
75
70
|
"""
|
76
|
-
|
71
|
+
Remove the specified environment variable from the .env file.
|
77
72
|
|
78
|
-
|
79
|
-
|
73
|
+
Parameters
|
74
|
+
----------
|
75
|
+
key : str
|
76
|
+
The name of the environment variable to remove.
|
80
77
|
|
81
|
-
Returns
|
82
|
-
|
78
|
+
Returns
|
79
|
+
-------
|
80
|
+
bool
|
81
|
+
True if the variable was successfully removed, False otherwise.
|
83
82
|
"""
|
84
|
-
|
83
|
+
dotenv = DotEnv()
|
84
|
+
return dotenv.unset(key)
|
85
85
|
|
86
86
|
@staticmethod
|
87
87
|
def all() -> Dict[str, Any]:
|
88
88
|
"""
|
89
89
|
Retrieve all environment variables as a dictionary.
|
90
90
|
|
91
|
-
Returns
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
@staticmethod
|
97
|
-
def toJson() -> str:
|
98
|
-
"""
|
99
|
-
Serializes the environment variables managed by the Env class into a JSON-formatted string.
|
100
|
-
|
101
|
-
Returns:
|
102
|
-
str: A JSON string representation of the environment variables.
|
103
|
-
"""
|
104
|
-
return Env._dotenv().toJson()
|
105
|
-
|
106
|
-
@staticmethod
|
107
|
-
def toBase64() -> str:
|
108
|
-
"""
|
109
|
-
Converts the environment variables loaded by the dotenv instance to a Base64-encoded string.
|
110
|
-
|
111
|
-
Returns:
|
112
|
-
str: The Base64-encoded representation of the environment variables.
|
91
|
+
Returns
|
92
|
+
-------
|
93
|
+
dict of str to Any
|
94
|
+
A dictionary containing all environment variables loaded by DotEnv.
|
113
95
|
"""
|
114
|
-
|
96
|
+
dotenv = DotEnv()
|
97
|
+
return dotenv.all()
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class OrionisEnvironmentValueError(Exception):
|
2
|
+
|
3
|
+
def __init__(self, msg: str):
|
4
|
+
"""
|
5
|
+
Initializes the exception with a custom error message.
|
6
|
+
Args:
|
7
|
+
msg (str): The error message describing the exception.
|
8
|
+
"""
|
9
|
+
super().__init__(msg)
|
10
|
+
|
11
|
+
def __str__(self) -> str:
|
12
|
+
"""
|
13
|
+
Return a string representation of the exception, including the class name and the first argument.
|
14
|
+
|
15
|
+
Returns:
|
16
|
+
str: A formatted string with the exception class name and its first argument.
|
17
|
+
"""
|
18
|
+
return f"{self.__class__.__name__}: {self.args[0]}"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class OrionisEnvironmentValueException(Exception):
|
2
|
+
|
3
|
+
def __init__(self, msg: str):
|
4
|
+
"""
|
5
|
+
Exception raised for errors related to environment values.
|
6
|
+
|
7
|
+
Parameters
|
8
|
+
----------
|
9
|
+
msg : str
|
10
|
+
The error message describing the exception.
|
11
|
+
"""
|
12
|
+
super().__init__(msg)
|
13
|
+
|
14
|
+
def __str__(self) -> str:
|
15
|
+
"""
|
16
|
+
Returns a string representation of the exception.
|
17
|
+
|
18
|
+
Returns
|
19
|
+
-------
|
20
|
+
str
|
21
|
+
A formatted string with the exception class name and its first argument.
|
22
|
+
"""
|
23
|
+
return f"{self.__class__.__name__}: {self.args[0]}"
|