Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: address suggestions from SonarCloud #54

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b58cc9f
add devsecops_pipeline.py
meleksabit Aug 28, 2024
8c039b1
add devsecops-pipeline workflow
meleksabit Aug 29, 2024
6fe591f
Merge branch 'main' into dev
meleksabit Aug 29, 2024
d3e5daf
replace sonarqube with bandit
meleksabit Aug 29, 2024
bfc3f90
edit cron job
meleksabit Sep 5, 2024
80ec32c
add comment for the cron job
meleksabit Sep 8, 2024
4719684
Merge branch 'main' into dev
meleksabit Sep 8, 2024
b57b3ca
add Git Guardian workflow
meleksabit Sep 11, 2024
6f43c71
Merge branch 'main' into dev
meleksabit Sep 11, 2024
0e76968
edit Git Guardian workflow
meleksabit Sep 11, 2024
b96d528
edit Git Guardian workflow
meleksabit Sep 11, 2024
da6d3fd
edit Git Guardian workflow
meleksabit Sep 11, 2024
e436b3f
edit Git Guardian workflow
meleksabit Sep 11, 2024
caf63b1
edit Git Guardian workflow
meleksabit Sep 11, 2024
54081f3
edit Git Guardian workflow
meleksabit Sep 11, 2024
6a283a0
edit Git Guardian workflow
meleksabit Sep 11, 2024
1392fd1
edit Git Guardian workflow
meleksabit Sep 11, 2024
7b1f5a0
edit Git Guardian workflow
meleksabit Sep 11, 2024
b047d2f
edit README file
meleksabit Sep 14, 2024
846feeb
Merge branch 'main' into dev
meleksabit Sep 14, 2024
aa79a35
edit DevSecOps pipeline
meleksabit Sep 26, 2024
0bf5315
edit release badge
meleksabit Oct 7, 2024
76cf414
Merge branch 'main' into dev
meleksabit Oct 7, 2024
a297c87
add .gitignore file
meleksabit Oct 8, 2024
ed02de5
Merge branch 'main' into dev
meleksabit Oct 8, 2024
73401cd
add PR Title Linter
meleksabit Nov 17, 2024
819522f
Merge branch 'main' into dev
meleksabit Nov 17, 2024
e95ba0b
add status badge for PR Linter
meleksabit Nov 17, 2024
e612e23
Merge branch 'main' into dev
meleksabit Nov 17, 2024
0f06241
add SonarCloud implementation
meleksabit Nov 28, 2024
bfe67f2
edit sonar-project.properties
meleksabit Nov 28, 2024
240ddca
Merge branch 'main' into dev
meleksabit Nov 28, 2024
eadc76d
add SonarCloud badge
meleksabit Nov 28, 2024
144bce5
address suggestions from SonarCloud
meleksabit Nov 28, 2024
b062b91
Merge branch 'main' into dev
meleksabit Nov 28, 2024
d86fb9e
add secrets module in strong_passgen_for_prod.py
meleksabit Nov 28, 2024
fb607b9
edit strong_passgen_for_prod.py
meleksabit Nov 28, 2024
22ee82d
edit strong_passgen_for_prod.py
meleksabit Nov 28, 2024
e2f3b42
edit strong_passgen_for_prod.py
meleksabit Nov 28, 2024
74c22cd
edit strong_passgen_for_prod.py
meleksabit Nov 28, 2024
560bfae
edit strong_passgen_for_prod.py
meleksabit Nov 28, 2024
e4dead0
edit strong_passgen_for_prod.py
meleksabit Nov 29, 2024
4a27c24
edit strong_passgen_for_prod.py
meleksabit Nov 29, 2024
b6b5b70
edit strong_passgen_for_prod.py
meleksabit Nov 29, 2024
da0116d
edit crypto_passgen_for_prod.py script
meleksabit Nov 29, 2024
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
4 changes: 2 additions & 2 deletions Tesla.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Parameters and Arguments example
def checkDriverAge(age=0):
def check_driver_age(age=0):
if int(age) < 18:
print("Sorry, you are too young to drive this car. Powering off 😟")
elif int(age) > 18:
Expand All @@ -8,4 +8,4 @@ def checkDriverAge(age=0):
print("Congratulations on your first year of driving. Enjoy the ride! 🚀")


checkDriverAge()
check_driver_age()
66 changes: 66 additions & 0 deletions crypto_passgen_for_prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import string
import secrets
from cryptography.fernet import Fernet
import os

# Step 1: Generate or retrieve a secure encryption key
key = os.environ.get('FERNET_KEY')
if not key:
print("Encryption key is missing. Please set the 'FERNET_KEY' environment variable.")
exit(1)
cipher_suite = Fernet(key)

# Step 2: Define all character sets for password generation
s1 = list(string.ascii_lowercase) # Lowercase letters
s2 = list(string.ascii_uppercase) # Uppercase letters
s3 = list(string.digits) # Digits
s4 = list(string.punctuation) # Special characters

# Step 3: Ask user for password length
while True:
try:
characters_number = int(input("How many characters do you want in your password? "))
if 8 <= characters_number <= 128:
break
print("Please choose a number between 8 and 128.")
except ValueError:
print("Invalid input. Please enter a valid number.")

# Step 4: Securely shuffle the character lists using secrets.SystemRandom()
secure_random = secrets.SystemRandom()
s1 = secure_random.sample(s1, len(s1)) # Securely shuffle lowercase letters
s2 = secure_random.sample(s2, len(s2)) # Securely shuffle uppercase letters
s3 = secure_random.sample(s3, len(s3)) # Securely shuffle digits
s4 = secure_random.sample(s4, len(s4)) # Securely shuffle punctuation

# Step 5: Create the password
# Ensure at least one character from each set is included
result = [
secrets.choice(s1),
secrets.choice(s2),
secrets.choice(s3),
secrets.choice(s4)
]

# Fill the remaining slots randomly
remaining_characters = characters_number - len(result)
result.extend(secrets.choice(s1 + s2 + s3 + s4) for _ in range(remaining_characters))

# Secure final shuffle
result = secure_random.sample(result, len(result))

# Step 6: Join and encrypt the password
password = "".join(result)
encrypted_password = cipher_suite.encrypt(password.encode())

# Step 7: Store the encrypted password securely
try:
with open("password_storage.txt", "wb") as file:
file.write(encrypted_password)
print("Your password has been securely generated and encrypted.")
print("The encrypted password has been saved in 'password_storage.txt'.")
print("Ensure your encryption key is securely stored to decrypt the password.")
except IOError as e:
print(f"File operation failed: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
7 changes: 2 additions & 5 deletions find_duplicates.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Shows the duplicate strings
my_list = ['a', 'b', 'c', 'd', 'd', 'm', 'm', 'n', 'o', 'z', 'z']

duplicates = []
for value in my_list:
if my_list.count(value) > 1:
if value not in duplicates:
duplicates.append(value)

if my_list.count(value) > 1 and value not in duplicates:
duplicates.append(value)
print(duplicates)
13 changes: 6 additions & 7 deletions performance_decorator.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Performance decorator
from time import time


# Decorator to measure performance
def performance(fn):
def wrapper(*args, **kwargs):
t1 = time()
result = fn(*args, **kwargs)
t2 = time()
print(f'took {t2-t1} seconds')
print(f'took {t2 - t1} seconds')
return result
return wrapper


@performance
def long_time():
for i in range(10000000):
i*5

"""Benchmarking function to test performance."""
for _ in range(10_000_000):
pass # Empty loop for benchmarking the decorator

# Execute the benchmark
long_time()
53 changes: 0 additions & 53 deletions strong_passgen_for_prod.py

This file was deleted.

Loading