-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(github): add github integration
- Loading branch information
1 parent
cb15726
commit 0fd9c62
Showing
35 changed files
with
2,111 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ betamax-serializers==0.2.1 | |
pytest==8.3.3 | ||
pytest-asyncio==0.24.0 | ||
pytest-cov==6.0.0 | ||
pytest-mock==3.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# standard imports | ||
import os | ||
|
||
# lib imports | ||
from cryptography import x509 | ||
from cryptography.hazmat.backends import default_backend | ||
from cryptography.hazmat.primitives import hashes | ||
from cryptography.hazmat.primitives.asymmetric import rsa | ||
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption | ||
from datetime import datetime, timedelta, UTC | ||
|
||
# local imports | ||
from src.common import common | ||
|
||
CERT_FILE = os.path.join(common.data_dir, "cert.pem") | ||
KEY_FILE = os.path.join(common.data_dir, "key.pem") | ||
|
||
|
||
def check_expiration(cert_path: str) -> int: | ||
with open(cert_path, "rb") as cert_file: | ||
cert_data = cert_file.read() | ||
cert = x509.load_pem_x509_certificate(cert_data, default_backend()) | ||
expiry_date = cert.not_valid_after_utc | ||
return (expiry_date - datetime.now(UTC)).days | ||
|
||
|
||
def generate_certificate(): | ||
private_key = rsa.generate_private_key( | ||
public_exponent=65537, | ||
key_size=4096, | ||
) | ||
subject = issuer = x509.Name([ | ||
x509.NameAttribute(x509.NameOID.COMMON_NAME, u"localhost"), | ||
]) | ||
cert = x509.CertificateBuilder().subject_name( | ||
subject | ||
).issuer_name( | ||
issuer | ||
).public_key( | ||
private_key.public_key() | ||
).serial_number( | ||
x509.random_serial_number() | ||
).not_valid_before( | ||
datetime.now(UTC) | ||
).not_valid_after( | ||
datetime.now(UTC) + timedelta(days=365) | ||
).sign(private_key, hashes.SHA256()) | ||
|
||
with open(KEY_FILE, "wb") as f: | ||
f.write(private_key.private_bytes( | ||
encoding=Encoding.PEM, | ||
format=PrivateFormat.TraditionalOpenSSL, | ||
encryption_algorithm=NoEncryption(), | ||
)) | ||
|
||
with open(CERT_FILE, "wb") as f: | ||
f.write(cert.public_bytes(Encoding.PEM)) | ||
|
||
|
||
def initialize_certificate() -> tuple[str, str]: | ||
print("Initializing SSL certificate") | ||
if os.path.exists(CERT_FILE) and os.path.exists(KEY_FILE): | ||
cert_expires_in = check_expiration(CERT_FILE) | ||
print(f"Certificate expires in {cert_expires_in} days.") | ||
if cert_expires_in >= 90: | ||
return CERT_FILE, KEY_FILE | ||
print("Generating new certificate") | ||
generate_certificate() | ||
return CERT_FILE, KEY_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# standard imports | ||
import shelve | ||
import threading | ||
|
||
|
||
class Database: | ||
def __init__(self, db_path): | ||
self.db_path = db_path | ||
self.lock = threading.Lock() | ||
|
||
def __enter__(self): | ||
self.lock.acquire() | ||
self.db = shelve.open(self.db_path, writeback=True) | ||
return self.db | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.sync() | ||
self.db.close() | ||
self.lock.release() | ||
|
||
def sync(self): | ||
self.db.sync() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DISCORD_BOT = None | ||
REDDIT_BOT = None |
Oops, something went wrong.