Skip to content

Commit dfaa4bb

Browse files
authored
Refactor S3 Module (#5)
* Code Changes: Refactored Cedential Retrieval * refactored credentials and log modules * refactored s3 tests * added credentials tests, refactored test-lint.yaml * refactored failing tests * refactored failing tests
1 parent 5827c7d commit dfaa4bb

File tree

15 files changed

+198
-97
lines changed

15 files changed

+198
-97
lines changed

.github/workflows/test-lint.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ jobs:
2424
python -m pip install --upgrade pip
2525
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
2626
27-
- name: Set PYTHONPATH
28-
run: |
29-
echo "PYTHONPATH=$(pwd)/src/aws_resource_manager" >> $GITHUB_ENV
30-
3127
- name: Lint Python scripts with Ruff
3228
run: |
3329
python -m ruff check src/ tests/

Makefile

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AWS Resource Manager
22
![Python Version](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13-blue)
3-
![text_image_extractor](https://img.shields.io/badge/My%20Package-unreleased-yell)
3+
![aws_resource_manager](https://img.shields.io/badge/aws_resource_manager-unreleased-yellow)
44
![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)
55

66
**AWS Resource Manager** is a Python package designed to simplify and automate the management of AWS

env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ACCESS_KEY='Insert Here'
2-
ACCESS_SECRET='Insert Here'
3-
REGION='Insert Here'
1+
AWS_ACCESS_KEY_ID="Add Access Key"
2+
AWS_SECRET_ACCESS_KEY="Add Secret Key"
3+
REGION="Add Region"

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ classifiers = [
1616
"Development Status :: 2 - Pre-Alpha",
1717
"Intended Audience :: Developers",
1818
"Programming Language :: Python :: 3 :: Only",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
1921
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
2023
]
24+
2125
dependencies = [
2226
"boto3==1.36.11",
2327
"botocore==1.36.11",

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
markers =
3+
unit: marks test as unit tests
4+
integration: marks tests as integration tests

ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ignore = [
3333
"N806", # Variable name should be lowercase
3434
"N803", # Argument name should be lowercase
3535
"S101", # Use of assert detected
36-
36+
"S106", # Possible hardcoded password
3737
]
3838

3939
exclude = [
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Credentials Module for AWS Resource Manager"""
2+
3+
import os
4+
5+
from dotenv import load_dotenv
6+
7+
8+
def get_credentials():
9+
"""
10+
Retrieves AWS credentials from a hidden environment file.
11+
12+
This class method accesses the user's AWS secret and access
13+
keys stored in an environment file. If a region is specified,
14+
the methods within the S3Handler class will execute in that region.
15+
Otherwise, AWS will assign a default region.
16+
17+
:return: An instance of the S3Handler class initialized with
18+
the user's credentials and specified region
19+
"""
20+
aws_access_key_id = os.getenv("AWS_ACCESS_KEY_ID")
21+
aws_secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY")
22+
region = os.getenv("REGION")
23+
24+
if not all([aws_access_key_id, aws_secret_access_key, region]):
25+
load_dotenv()
26+
aws_access_key_id = os.getenv("AWS_ACCESS_KEY_ID")
27+
aws_secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY")
28+
region = os.getenv("REGION")
29+
30+
if not all([aws_access_key_id, aws_secret_access_key, region]):
31+
raise ValueError("All credentials not found in environment variables.")
32+
33+
return aws_access_key_id, aws_secret_access_key, region
34+
35+
36+
if __name__ == "__main__":
37+
get_credentials()

src/aws_resource_manager/ec2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import boto3
55
from botocore.exceptions import ClientError
66
from dotenv import load_dotenv
7-
from logger import configure_logger
87

9-
logger = configure_logger()
8+
from aws_resource_manager.logs import get_logger
9+
10+
logger = get_logger()
1011

1112

1213
class EC2Handler:
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,22 @@
33
import logging
44

55

6-
def configure_logger():
7-
# Create a logger
8-
configured_logger = logging.getLogger(__name__) # Or a specific name
9-
configured_logger.setLevel(logging.DEBUG) # Set the minimum level to log
6+
def get_logger():
7+
configured_logger = logging.getLogger(__name__)
8+
configured_logger.setLevel(logging.DEBUG)
109

11-
# Create a handler for console output (stderr by default)
1210
handler = logging.StreamHandler()
1311

14-
# Create a formatter
1512
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
1613
handler.setFormatter(formatter)
1714

18-
# Add the handler to the logger
1915
configured_logger.addHandler(handler)
2016

2117
return configured_logger
2218

2319

2420
if __name__ == "__main__":
25-
# Create Console Logger from Function
26-
logger = configure_logger()
27-
# Print Dummy Messages
21+
logger = get_logger()
2822
logger.debug("This is a debug message.")
2923
logger.info("This is an info message.")
3024
logger.warning("This is a warning message.")

0 commit comments

Comments
 (0)