Linted code iwht black tool
This commit is contained in:
@@ -11,6 +11,7 @@ from templates import html_templates
|
||||
from wordlists import get_wordlists
|
||||
from config import get_config
|
||||
|
||||
|
||||
def random_username() -> str:
|
||||
"""Generate random username"""
|
||||
wl = get_wordlists()
|
||||
@@ -21,10 +22,10 @@ def random_password() -> str:
|
||||
"""Generate random password"""
|
||||
wl = get_wordlists()
|
||||
templates = [
|
||||
lambda: ''.join(random.choices(string.ascii_letters + string.digits, k=12)),
|
||||
lambda: "".join(random.choices(string.ascii_letters + string.digits, k=12)),
|
||||
lambda: f"{random.choice(wl.password_prefixes)}{random.randint(100, 999)}!",
|
||||
lambda: f"{random.choice(wl.simple_passwords)}{random.randint(1000, 9999)}",
|
||||
lambda: ''.join(random.choices(string.ascii_lowercase, k=8)),
|
||||
lambda: "".join(random.choices(string.ascii_lowercase, k=8)),
|
||||
]
|
||||
return random.choice(templates)()
|
||||
|
||||
@@ -36,6 +37,7 @@ def random_email(username: str = None) -> str:
|
||||
username = random_username()
|
||||
return f"{username}@{random.choice(wl.email_domains)}"
|
||||
|
||||
|
||||
def random_server_header() -> str:
|
||||
"""Generate random server header from wordlists"""
|
||||
config = get_config()
|
||||
@@ -44,10 +46,11 @@ def random_server_header() -> str:
|
||||
wl = get_wordlists()
|
||||
return random.choice(wl.server_headers)
|
||||
|
||||
|
||||
def random_api_key() -> str:
|
||||
"""Generate random API key"""
|
||||
wl = get_wordlists()
|
||||
key = ''.join(random.choices(string.ascii_letters + string.digits, k=32))
|
||||
key = "".join(random.choices(string.ascii_letters + string.digits, k=32))
|
||||
return random.choice(wl.api_key_prefixes) + key
|
||||
|
||||
|
||||
@@ -87,14 +90,16 @@ def users_json() -> str:
|
||||
users = []
|
||||
for i in range(random.randint(3, 8)):
|
||||
username = random_username()
|
||||
users.append({
|
||||
"id": i + 1,
|
||||
"username": username,
|
||||
"email": random_email(username),
|
||||
"password": random_password(),
|
||||
"role": random.choice(wl.user_roles),
|
||||
"api_token": random_api_key()
|
||||
})
|
||||
users.append(
|
||||
{
|
||||
"id": i + 1,
|
||||
"username": username,
|
||||
"email": random_email(username),
|
||||
"password": random_password(),
|
||||
"role": random.choice(wl.user_roles),
|
||||
"api_token": random_api_key(),
|
||||
}
|
||||
)
|
||||
return json.dumps({"users": users}, indent=2)
|
||||
|
||||
|
||||
@@ -102,20 +107,28 @@ def api_keys_json() -> str:
|
||||
"""Generate fake api_keys.json with random data"""
|
||||
keys = {
|
||||
"stripe": {
|
||||
"public_key": "pk_live_" + ''.join(random.choices(string.ascii_letters + string.digits, k=24)),
|
||||
"secret_key": random_api_key()
|
||||
"public_key": "pk_live_"
|
||||
+ "".join(random.choices(string.ascii_letters + string.digits, k=24)),
|
||||
"secret_key": random_api_key(),
|
||||
},
|
||||
"aws": {
|
||||
"access_key_id": "AKIA" + ''.join(random.choices(string.ascii_uppercase + string.digits, k=16)),
|
||||
"secret_access_key": ''.join(random.choices(string.ascii_letters + string.digits + '+/', k=40))
|
||||
"access_key_id": "AKIA"
|
||||
+ "".join(random.choices(string.ascii_uppercase + string.digits, k=16)),
|
||||
"secret_access_key": "".join(
|
||||
random.choices(string.ascii_letters + string.digits + "+/", k=40)
|
||||
),
|
||||
},
|
||||
"sendgrid": {
|
||||
"api_key": "SG." + ''.join(random.choices(string.ascii_letters + string.digits, k=48))
|
||||
"api_key": "SG."
|
||||
+ "".join(random.choices(string.ascii_letters + string.digits, k=48))
|
||||
},
|
||||
"twilio": {
|
||||
"account_sid": "AC" + ''.join(random.choices(string.ascii_lowercase + string.digits, k=32)),
|
||||
"auth_token": ''.join(random.choices(string.ascii_lowercase + string.digits, k=32))
|
||||
}
|
||||
"account_sid": "AC"
|
||||
+ "".join(random.choices(string.ascii_lowercase + string.digits, k=32)),
|
||||
"auth_token": "".join(
|
||||
random.choices(string.ascii_lowercase + string.digits, k=32)
|
||||
),
|
||||
},
|
||||
}
|
||||
return json.dumps(keys, indent=2)
|
||||
|
||||
@@ -123,51 +136,70 @@ def api_keys_json() -> str:
|
||||
def api_response(path: str) -> str:
|
||||
"""Generate fake API JSON responses with random data"""
|
||||
wl = get_wordlists()
|
||||
|
||||
|
||||
def random_users(count: int = 3):
|
||||
users = []
|
||||
for i in range(count):
|
||||
username = random_username()
|
||||
users.append({
|
||||
"id": i + 1,
|
||||
"username": username,
|
||||
"email": random_email(username),
|
||||
"role": random.choice(wl.user_roles)
|
||||
})
|
||||
users.append(
|
||||
{
|
||||
"id": i + 1,
|
||||
"username": username,
|
||||
"email": random_email(username),
|
||||
"role": random.choice(wl.user_roles),
|
||||
}
|
||||
)
|
||||
return users
|
||||
|
||||
|
||||
responses = {
|
||||
'/api/users': json.dumps({
|
||||
"users": random_users(random.randint(2, 5)),
|
||||
"total": random.randint(50, 500)
|
||||
}, indent=2),
|
||||
'/api/v1/users': json.dumps({
|
||||
"status": "success",
|
||||
"data": [{
|
||||
"id": random.randint(1, 100),
|
||||
"name": random_username(),
|
||||
"api_key": random_api_key()
|
||||
}]
|
||||
}, indent=2),
|
||||
'/api/v2/secrets': json.dumps({
|
||||
"database": {
|
||||
"host": random.choice(wl.database_hosts),
|
||||
"username": random_username(),
|
||||
"password": random_password(),
|
||||
"database": random_database_name()
|
||||
"/api/users": json.dumps(
|
||||
{
|
||||
"users": random_users(random.randint(2, 5)),
|
||||
"total": random.randint(50, 500),
|
||||
},
|
||||
"api_keys": {
|
||||
"stripe": random_api_key(),
|
||||
"aws": 'AKIA' + ''.join(random.choices(string.ascii_uppercase + string.digits, k=16))
|
||||
}
|
||||
}, indent=2),
|
||||
'/api/config': json.dumps({
|
||||
"app_name": random.choice(wl.application_names),
|
||||
"debug": random.choice([True, False]),
|
||||
"secret_key": random_api_key(),
|
||||
"database_url": f"postgresql://{random_username()}:{random_password()}@localhost/{random_database_name()}"
|
||||
}, indent=2),
|
||||
'/.env': f"""APP_NAME={random.choice(wl.application_names)}
|
||||
indent=2,
|
||||
),
|
||||
"/api/v1/users": json.dumps(
|
||||
{
|
||||
"status": "success",
|
||||
"data": [
|
||||
{
|
||||
"id": random.randint(1, 100),
|
||||
"name": random_username(),
|
||||
"api_key": random_api_key(),
|
||||
}
|
||||
],
|
||||
},
|
||||
indent=2,
|
||||
),
|
||||
"/api/v2/secrets": json.dumps(
|
||||
{
|
||||
"database": {
|
||||
"host": random.choice(wl.database_hosts),
|
||||
"username": random_username(),
|
||||
"password": random_password(),
|
||||
"database": random_database_name(),
|
||||
},
|
||||
"api_keys": {
|
||||
"stripe": random_api_key(),
|
||||
"aws": "AKIA"
|
||||
+ "".join(
|
||||
random.choices(string.ascii_uppercase + string.digits, k=16)
|
||||
),
|
||||
},
|
||||
},
|
||||
indent=2,
|
||||
),
|
||||
"/api/config": json.dumps(
|
||||
{
|
||||
"app_name": random.choice(wl.application_names),
|
||||
"debug": random.choice([True, False]),
|
||||
"secret_key": random_api_key(),
|
||||
"database_url": f"postgresql://{random_username()}:{random_password()}@localhost/{random_database_name()}",
|
||||
},
|
||||
indent=2,
|
||||
),
|
||||
"/.env": f"""APP_NAME={random.choice(wl.application_names)}
|
||||
DEBUG={random.choice(['true', 'false'])}
|
||||
APP_KEY=base64:{''.join(random.choices(string.ascii_letters + string.digits, k=32))}=
|
||||
DB_CONNECTION=mysql
|
||||
@@ -179,7 +211,7 @@ DB_PASSWORD={random_password()}
|
||||
AWS_ACCESS_KEY_ID=AKIA{''.join(random.choices(string.ascii_uppercase + string.digits, k=16))}
|
||||
AWS_SECRET_ACCESS_KEY={''.join(random.choices(string.ascii_letters + string.digits + '+/', k=40))}
|
||||
STRIPE_SECRET={random_api_key()}
|
||||
"""
|
||||
""",
|
||||
}
|
||||
return responses.get(path, json.dumps({"error": "Not found"}, indent=2))
|
||||
|
||||
@@ -187,11 +219,13 @@ STRIPE_SECRET={random_api_key()}
|
||||
def directory_listing(path: str) -> str:
|
||||
"""Generate fake directory listing using wordlists"""
|
||||
wl = get_wordlists()
|
||||
|
||||
|
||||
files = wl.directory_files
|
||||
dirs = wl.directory_dirs
|
||||
|
||||
selected_files = [(f, random.randint(1024, 1024*1024))
|
||||
for f in random.sample(files, min(6, len(files)))]
|
||||
|
||||
|
||||
selected_files = [
|
||||
(f, random.randint(1024, 1024 * 1024))
|
||||
for f in random.sample(files, min(6, len(files)))
|
||||
]
|
||||
|
||||
return html_templates.directory_listing(path, dirs, selected_files)
|
||||
|
||||
Reference in New Issue
Block a user