Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test & Build

on:
push:
branches:
- '*'

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel

- name: Install Pytest
run: |
pip install pytest

- name: Build Package
run: |
python setup.py sdist

- name: Install Package
run: |
pip install dist/*

- name: Run Tests
run: |
pytest tests -vv -rEPW -o pytest_collection_order=alphabetical --cache-clear --color=yes
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Version History

- 0.1.0: Initial Release (latest)
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,53 @@
# pyconfigurationmanager
# `pyconfigurationmanager`
The pyconfigurationmanager package provides a set of utilities for managing configuration settings in Python applications. It includes classes and functions for loading configuration data from files, auditing configuration changes, and ensuring secure access to configuration files.

## Installation
Configuration Manager can be installed using pip:
```bash
pip install git+https://github.com/coldsofttech/pyconfigurationmanager.git
```

## Usage
````python
from pyconfigurationmanager import ConfigurationManager

# Load the configuration file
ConfigurationManager.load_config(file_path='config.json')

# Retrieve a string value
string_value = ConfigurationManager.get_config_value('sample_string')
print(string_value) # Output: 'string_of_sample'

# Retrieve an integer value
integer_value = ConfigurationManager.get_config_value('sample_integer')
print(integer_value) # Output: 100

# Retrieve a dictionary value
dict_value = ConfigurationManager.get_config_value('sample_others')
print(dict_value)
# Output:
# {'sample_boolean': True, 'sample_list': ['list_1', 'list_2']}

# Retrieve a boolean value
boolean_value = ConfigurationManager.get_config_value('sample_others.sample_boolean')
print(boolean_value) # Output: True

# Retrieve a list value
list_value = ConfigurationManager.get_config_value('sample_others.sample_list')
print(list_value) # Output: ['list_1', 'list_2']
````

# Documentation
## `pyconfigurationmanager`
### `ConfigurationManager`
The ConfigurationManager class is the heart of the package, offering a suite of functionalities for managing configuration settings.

#### Methods
- `load_config(file_path: Optional[str] = 'config.json', secure: Optional[bool] = True, audit: Optional[bool] = False, audit_file_path: Optional[str] = 'audit.log')`: Loads configuration settings from a file into memory, with options to enable secure mode and auditing. By default, secure mode is enabled, ensuring that the configuration file has only readable permissions for the user. If auditing is enabled, all configuration accesses are logged for future audit purposes.
- `get_config_value(key: Optional[str] = None)`: Retrieves the value of a specific configuration setting or the entire configuration if no key is provided. Hierarchical keys can be accessed by separating them with '.'.

### `ConfigurationManagerError`
This error class is employed to signal any issues or errors encountered during the execution of ConfigurationManager methods.

#### Methods
- `__init__(message: Optional[str])` - Initialize a ConfigurationManagerError
45 changes: 45 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2024 coldsofttech
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

def pytest_collection_modifyitems(config, items):
"""
Custom pytest hook to modify the collection of test items.
This function sorts test items to execute specific tests first.
"""
def test_order(test_name):
# Define the desired order of execution for specific test names
order_mapping = {
'test_get_config_value_invalid_no_config_set': 1,
'test_valid_no_params': 2,
'test_invalid_exposed_permissions': 3,
'test_valid_insecure': 4,
'test_invalid_file_not_found': 5,
'test_invalid_json': 6,
'test_get_config_value_valid_string': 7,
'test_get_config_value_valid_integer': 8,
'test_get_config_value_valid_dict': 9,
'test_get_config_value_valid_boolean': 10,
'test_get_config_value_valid_list': 11,
'test_get_config_value_valid_audit_all': 12,
'test_get_config_value_valid_audit_specific': 13
}
return order_mapping.get(test_name, float('inf')) # Default to infinity for tests not in the mapping

items.sort(key=lambda item: (test_order(item.nodeid.split("::")[-1]), item.fspath, item.originalname))
38 changes: 38 additions & 0 deletions pyconfigurationmanager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2024 coldsofttech
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

__all__ = [
"ConfigurationManager",
"ConfigurationManagerError",
"__author__",
"__description__",
"__name__",
"__version__"
]
__author__ = "coldsofttech"
__description__ = """
The pyconfigurationmanager package provides a set of utilities for managing configuration settings in
Python applications. It includes classes and functions for loading configuration data from files,
auditing configuration changes, and ensuring secure access to configuration files.
"""
__name__ = "pyconfigurationmanager"
__version__ = "0.1.0"

from pyconfigurationmanager.__main__ import ConfigurationManager, ConfigurationManagerError
Loading