Skip to content

Commit

Permalink
refactor: allow auto gen rsa key
Browse files Browse the repository at this point in the history
  • Loading branch information
dpr-0 committed Dec 5, 2023
1 parent be191a0 commit 42fec9d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/settings.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
from functools import cached_property

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from pydantic import PostgresDsn, RedisDsn, SecretStr, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict

private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
public_key = private_key.public_key()


class AppSettings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", frozen=True)

DATABASE_DSN: PostgresDsn
REDIS_DSN: RedisDsn
PUBLIC_KEY: SecretStr
PRIVATE_KEY: SecretStr
PUBLIC_KEY: SecretStr = SecretStr(
public_key.public_bytes(
serialization.Encoding.PEM,
serialization.PublicFormat.SubjectPublicKeyInfo,
).decode()
)
PRIVATE_KEY: SecretStr = SecretStr(
private_key.private_bytes(
serialization.Encoding.PEM,
serialization.PrivateFormat.TraditionalOpenSSL,
serialization.NoEncryption(),
).decode()
)
MAX_MATCHING_TIMEOUT: float = 6.7
JWT_LIFETIME: int = 3600

Expand Down

0 comments on commit 42fec9d

Please sign in to comment.