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 #48

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 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
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()
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: 30 additions & 23 deletions strong_passgen_for_prod.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# import modules
import string
import random
import secrets

# store all characters in lists
# Store all characters in lists
s1 = list(string.ascii_lowercase)
s2 = list(string.ascii_uppercase)
s3 = list(string.digits)
Expand All @@ -11,43 +11,50 @@
# Ask user about the number of characters
user_input = input("How many characters do you want in your password? ")

# check this input is it number? is it more than 8?
# Check if the input is a valid number and greater than or equal to 8
while True:
try:
characters_number = int(user_input)
if characters_number < 8:
print("Your password must be at least 8 characters long")
user_input = input("Please, Enter your number again: ")
print("Your password must be at least 8 characters long.")
user_input = input("Please, enter your number again: ")
else:
break
except:
print("Please, Enter a number")
user_input = input("Please, Enter your number again: ")
except ValueError: # Catch invalid inputs
print("Invalid input. Please enter a valid number.")
user_input = input("Please, enter your number again: ")

# shuffle all lists
random.shuffle(s1)
random.shuffle(s2)
random.shuffle(s3)
random.shuffle(s4)
# Securely shuffle all character lists
s1 = secrets.SystemRandom().sample(s1, len(s1))
s2 = secrets.SystemRandom().sample(s2, len(s2))
s3 = secrets.SystemRandom().sample(s3, len(s3))
s4 = secrets.SystemRandom().sample(s4, len(s4))

# calculate 30% & 20% of number of characters
part1 = round(characters_number * (30 / 100))
part2 = round(characters_number * (20 / 100))
# Calculate portions of the password
part1 = round(characters_number * 0.3) # 30% lowercase and uppercase letters
part2 = round(characters_number * 0.2) # 20% digits and punctuations

# generation of the password (60% letters and 40% digits & punctuations)
# Generate the password
result = []

for x in range(part1):
result.append(s1[x])
result.append(s2[x])

for x in range(part2):
result.append(s3[x])
result.append(s4[x])

# shuffle the result
random.shuffle(result)
# Ensure the result has the exact number of characters requested
while len(result) < characters_number:
result.append(secrets.choice(s1 + s2 + s3 + s4))

# Shuffle the final password securely
secrets.SystemRandom().shuffle(result) # Cryptographically secure shuffling

# join the result
# Join the result to form the password
password = "".join(result)
print("Strong Password: ", password)

# Mask the password except for the last 4 characters
masked_password = '*' * (len(password) - 4) + password[-4:]

# Output the masked password
print("Generated password:", masked_password)
Loading