Skip to content

Commit 6886856

Browse files
Merge pull request #12 from sebastienrousseauhsbc/main
Add modules documentation
2 parents 3746f08 + e79d852 commit 6886856

File tree

4 files changed

+298
-0
lines changed

4 files changed

+298
-0
lines changed

encryption_helper/common/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!-- markdownlint-disable MD033 MD041 -->
2+
<p align="center">
3+
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
4+
</p>
5+
6+
<h1 align="center">Encryption Helper Python</h1>
7+
8+
<p align="center">
9+
<img src="../../assets/banner.jpg" alt="Encryption Helper Banner">
10+
</p>
11+
12+
<h2 align="center">Strings Module</h2>
13+
14+
<p align="center">
15+
<strong>Strings module for the encryption_helper package.</strong>
16+
</p>
17+
18+
<p align="center">
19+
<a href="#attributes">Attributes</a> •
20+
<a href="#usage">Usage</a> •
21+
<a href="#license">License</a>
22+
</p>
23+
<!-- markdownlint-enable MD033 MD041 -->
24+
25+
## Attributes
26+
27+
The `strings.py` module provides a collection of string constants used throughout the `encryption_helper` package. These constants include file suffixes for various key and encrypted file types.
28+
29+
- **private_key_suffix**: The file suffix for private key files.
30+
- **public_key_suffix**: The file suffix for public key files.
31+
- **encrypted_file_suffix**: The file suffix for encrypted files.
32+
33+
## Usage
34+
35+
This module defines string constants for use in the `encryption_helper` package. These constants help standardize file naming conventions across the package.
36+
37+
### Example
38+
39+
```python
40+
from encryption_helper.common.strings import private_key_suffix, public_key_suffix, encrypted_file_suffix
41+
42+
print(private_key_suffix) # Output: private-key.pem
43+
print(public_key_suffix) # Output: public_key.pem
44+
print(encrypted_file_suffix) # Output: .bin
45+
```
46+
47+
## License
48+
49+
This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for details.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!-- markdownlint-disable MD033 MD041 -->
2+
<p align="center">
3+
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
4+
</p>
5+
6+
<h1 align="center">Encryption Helper Python</h1>
7+
8+
<p align="center">
9+
<img src="../../assets/banner.jpg" alt="Encryption Helper Banner">
10+
</p>
11+
12+
<h2 align="center">Context Module</h2>
13+
14+
<p align="center">
15+
<strong>Context module for the encryption_helper package.</strong>
16+
</p>
17+
18+
<p align="center">
19+
<a href="#classes">Classes</a> •
20+
<a href="#usage">Usage</a> •
21+
<a href="#license">License</a>
22+
</p>
23+
<!-- markdownlint-enable MD033 MD041 -->
24+
25+
## Classes
26+
27+
The `context.py` module provides a `Context` class for managing application-wide settings and logging. It implements the Singleton pattern to ensure only one instance of the context exists.
28+
29+
### Context
30+
31+
A singleton class for managing application context and logging.
32+
33+
#### Attributes
34+
35+
- **_instance** (Optional[Context]): The singleton instance of the Context class.
36+
- **name** (str): The name of the application context, used for logging.
37+
- **log_level** (int): The current logging level.
38+
- **logger** (Optional[logging.Logger]): The logger instance for the context.
39+
40+
### Methods
41+
42+
- `__new__(cls) -> Context`: Creates and returns the singleton instance of the Context class.
43+
- `get_instance(cls) -> Context`: Gets the singleton instance of the Context class.
44+
- `set_name(self, name: str) -> None`: Sets the name of the context.
45+
- `set_log_level(self, log_level: Optional[str]) -> None`: Sets the logging level for the context.
46+
- `init_logging(self) -> None`: Initializes the logger for the context.
47+
- `get_logger(self) -> logging.Logger`: Gets the logger for the context, initializing it if necessary.
48+
49+
## Usage
50+
51+
This module defines a `Context` class for managing application-wide settings and logging.
52+
53+
### Example
54+
55+
```python
56+
from encryption_helper.context.context import Context
57+
58+
# Get the singleton instance of the Context class
59+
context = Context.get_instance()
60+
61+
# Set the name and logging level of the context
62+
context.set_name('my_app')
63+
context.set_log_level('DEBUG')
64+
65+
# Get the logger instance and log a message
66+
logger = context.get_logger()
67+
logger.debug('This is a debug message')
68+
```
69+
70+
## License
71+
72+
This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for details.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!-- markdownlint-disable MD033 MD041 -->
2+
<p align="center">
3+
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
4+
</p>
5+
6+
<h1 align="center">Encryption Helper Python</h1>
7+
8+
<p align="center">
9+
<img src="../../../assets/banner.jpg" alt="Encryption Helper Banner">
10+
</p>
11+
12+
<h2 align="center">Checks Module</h2>
13+
14+
<p align="center">
15+
<strong>Checks module for the encryption_helper package.</strong>
16+
</p>
17+
18+
<p align="center">
19+
<a href="#functions">Functions</a> •
20+
<a href="#usage">Usage</a> •
21+
<a href="#license">License</a>
22+
</p>
23+
<!-- markdownlint-enable MD033 MD041 -->
24+
25+
## Functions
26+
27+
The `checks.py` module provides utility functions for input validation.
28+
29+
### str_none_or_empty
30+
31+
Check if one or more input strings are `None` or empty.
32+
33+
#### Args
34+
35+
- **argv (str)**: A variable number of string arguments to be checked.
36+
37+
#### Returns
38+
39+
- **bool**: `True` if any of the input strings is `None` or empty; otherwise `False`.
40+
41+
#### Examples
42+
43+
```python
44+
from encryption_helper.utils.checks import str_none_or_empty
45+
46+
print(str_none_or_empty('test', 'hello', 'world')) # Output: False
47+
print(str_none_or_empty('test', None, 'world')) # Output: True
48+
print(str_none_or_empty('test', '', 'world')) # Output: True
49+
print(str_none_or_empty('test', ' ', 'world')) # Output: True
50+
print(str_none_or_empty()) # Output: False
51+
```
52+
53+
## License
54+
55+
This project is licensed under the MIT License. See the [LICENSE](../../../LICENSE) file for details.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<!-- markdownlint-disable MD033 MD041 -->
2+
<p align="center">
3+
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
4+
</p>
5+
6+
<h1 align="center">Encryption Helper Python</h1>
7+
8+
<p align="center">
9+
<img src="../../../assets/banner.jpg" alt="Encryption Helper Banner">
10+
</p>
11+
12+
<h2 align="center">I/O Modules</h2>
13+
14+
<p align="center">
15+
<strong>I/O modules for the encryption_helper package.</strong>
16+
</p>
17+
18+
<p align="center">
19+
<a href="#read-file-functions">Read File Functions</a> •
20+
<a href="#write-file-functions">Write File Functions</a> •
21+
<a href="#usage">Usage</a> •
22+
<a href="#license">License</a>
23+
</p>
24+
<!-- markdownlint-enable MD033 MD041 -->
25+
26+
## Read File Functions
27+
28+
The `read_file.py` module provides functions for reading text files in binary mode.
29+
30+
### read_text_in_binary_mode
31+
32+
Read text from a file in binary mode given a directory and file name.
33+
34+
#### Args
35+
36+
- **directory (str)**: The directory where the file is located.
37+
- **file_name (str)**: The name of the file to be read.
38+
39+
#### Returns
40+
41+
- **bytes**: The content of the file read in binary mode.
42+
43+
#### Raises
44+
45+
- **Exception**: If one or more arguments are empty.
46+
- **OSError**: If there is an error reading the file.
47+
48+
### read_text_in_binary_mode_abs
49+
50+
Read text from a file in binary mode given an absolute file path.
51+
52+
#### Args
53+
54+
- **absolute_file_path (str)**: The absolute path to the file to be read.
55+
56+
#### Returns
57+
58+
- **bytes**: The content of the file read in binary mode.
59+
60+
#### Raises
61+
62+
- **Exception**: If one or more arguments are empty.
63+
- **OSError**: If there is an error reading the file.
64+
65+
## Write File Functions
66+
67+
The `write_file.py` module provides functions for writing text files in binary mode.
68+
69+
### write_text_in_binary_mode
70+
71+
Write text to a file in binary mode given a directory and file name.
72+
73+
#### Args
74+
75+
- **directory (str)**: The directory where the file will be written.
76+
- **file_name (str)**: The name of the file to be written.
77+
- **text (bytes)**: The text to be written to the file.
78+
79+
#### Returns
80+
81+
- **str**: The absolute file path of the written file.
82+
83+
#### Raises
84+
85+
- **Exception**: If one or more arguments are empty.
86+
- **OSError**: If there is an error writing to the file.
87+
88+
### write_text_in_binary_mode_abs
89+
90+
Write text to a file in binary mode given an absolute file path.
91+
92+
#### Args
93+
94+
- **absolute_file_path (str)**: The absolute path to the file to be written.
95+
- **text (bytes)**: The text to be written to the file.
96+
97+
#### Returns
98+
99+
- **str**: The absolute file path of the written file.
100+
101+
#### Raises
102+
103+
- **Exception**: If one or more arguments are empty.
104+
- **OSError**: If there is an error writing to the file.
105+
106+
## Usage
107+
108+
```python
109+
from encryption_helper.utils.io import read_file, write_file
110+
111+
# Read file example
112+
content = read_file.read_text_in_binary_mode('/path/to/directory', 'file.txt')
113+
print(content)
114+
115+
# Write file example
116+
path = write_file.write_text_in_binary_mode('/path/to/directory', 'file.txt', b'test data')
117+
print(path)
118+
```
119+
120+
## License
121+
122+
This project is licensed under the MIT License. See the [LICENSE](../../../LICENSE) file for details.

0 commit comments

Comments
 (0)