def auth_token( config: Config, logger: Logger, ) -> Generator[Dict[str, str], None, None]: retailer_repository = RetailerRepository(config, logger) auth_service = AuthService(config, logger, retailer_repository) reatailer_model = RetailerModel( full_name="Authenticated User", document="99899899899", email=EmailStr("*****@*****.**"), password="******", ) retailer_repository.insert_retailer(reatailer_model) retailer = retailer_repository.get_retailer_by_email("*****@*****.**") auth_token = auth_service.generate_access_token( {"sub": "*****@*****.**"}, expires_delta=timedelta( minutes=int(config.get_config("ACCESS_TOKEN_EXPIRE_MINUTES")) ), ) yield {"Authorization": f"Bearer {auth_token}"} if retailer: retailer_repository.delete_retailer(retailer.id)
def expected_config_value(self, config: Config, config_key: str) -> Any: return config.get_config(config_key)
def expires_delta(self, config: Config) -> timedelta: return timedelta(minutes=int(config.get_config("ACCESS_TOKEN_EXPIRE_MINUTES")))
from logging.config import fileConfig from sqlalchemy import engine_from_config from sqlalchemy import pool from alembic import context from project.config import Config # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config app_config = Config() host = app_config.get_config("DB_HOST") port = app_config.get_config("DB_PORT") user = app_config.get_config("DB_USER") password = app_config.get_config("DB_PASSWORD") database = app_config.get_config("DB_DATABASE") database_url = f"mysql+mysqldb://{user}:{password}@{host}:{port}/{database}" config.set_main_option("sqlalchemy.url", database_url) # Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata