Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
bucket_constants.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: bucket_constants.py
14# CREATION DATE: 18-11-2025
15# LAST Modified: 14:42:10 19-12-2025
16# DESCRIPTION:
17# This is the backend server in charge of making the actual website work.
18# /STOP
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: File in charge of containing the constants required for the bucket wrapper.
21# // AR
22# +==== END CatFeeder =================+
23"""
24
25import os
26from typing import Optional, Dict
27
28import dotenv
29from display_tty import Disp, initialise_logger
30IDISP: Disp = initialise_logger("Bucket Constants", False)
31
32# Environement initialisation
33dotenv.load_dotenv(".env")
34_DOTENV = dict(dotenv.dotenv_values())
35_OS_ENV = dict(os.environ)
36ENV = {}
37ENV.update(_OS_ENV)
38ENV.update(_DOTENV)
39
40
41def _get_environement_variable(environement: Dict[str, Optional[str]], variable_name: str, required: bool = True) -> str:
42 """_summary_
43 Get the content of an environement variable.
44
45 Args:
46 variable_name (str): _description_
47 required (bool): If False, return empty string if variable not found. Defaults to True.
48
49 Returns:
50 str: _description_: the value of that variable, otherwise an exception is raised.
51 """
52 if environement is None:
53 raise ValueError(
54 "No environement file loaded."
55 )
56 data = environement.get(variable_name, None)
57 if data is None:
58 if not required:
59 return ""
60 raise ValueError(
61 f"Variable {variable_name} not found in the environement"
62 )
63 return data
64
65
66# S3 resource type - this never changes for S3-compatible services
67BUCKET_RESSOURCE_TYPE: str = "s3"
68
69# S3 signature version - configurable for edge cases, defaults to modern s3v4
70BUCKET_SIGNATURE_VERSION: str = _get_environement_variable(
71 ENV, "BUCKET_SIGNATURE_VERSION", required=False) or "s3v4"
72
73BUCKET_HOST: str = _get_environement_variable(ENV, "BUCKET_HOST")
74BUCKET_PORT: str = _get_environement_variable(
75 ENV, "BUCKET_PORT", required=False)
76BUCKET_USER: str = _get_environement_variable(ENV, "BUCKET_USER")
77BUCKET_PASSWORD: str = _get_environement_variable(
78 ENV,
79 "BUCKET_PASSWORD"
80)
str _get_environement_variable(Dict[str, Optional[str]] environement, str variable_name, bool required=True)