def get_settings_override(): configFile = configparser.ConfigParser() configFile.read("src/test/test_data/test.config") Image, Confidence, Data = configFile['IMAGE'], configFile['CONFIDENCE'], configFile["DATA"] w, h, r, R = int(Image["width in px"]), int(Image["height in px"]), float( Image["ratio in px/m"]), float(Image["Radius in m"]) data_path, static_path = Data["data_path"], Data["static_path"] model_path = Confidence["model_path"] loaded_model = pickle.load(open(Confidence["model_path"], 'rb')) return config.Settings(w=w, h=h, r=r, R=R, data_path=data_path, static_path=static_path, loaded_model=loaded_model)
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None): from app import config settings = config.Settings() to_encode = data.copy() if expires_delta: expire = datetime.utcnow() + expires_delta else: expire = datetime.utcnow() + timedelta(minutes=15) to_encode.update({"exp": expire}) encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM) return encoded_jwt
async def login_for_access_token( form_data: OAuth2PasswordRequestForm = Depends()): from app import config settings = config.Settings() user = authenticate_user(fake_users_db, form_data.username, form_data.password) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, ) access_token_expires = timedelta( minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES) access_token = create_access_token(data={"sub": user.username}, expires_delta=access_token_expires) return {"access_token": access_token, "token_type": "bearer"}
async def get_current_user(token: str = Depends(oauth2_scheme)): from app import config settings = config.Settings() credentials_exception = HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Could not validate credentials", headers={"WWW-Authenticate": "Bearer"}, ) try: payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]) username: str = payload.get("sub") if username is None: raise credentials_exception token_data = TokenData(username=username) except JWTError: raise credentials_exception user = get_user(fake_users_db, username=token_data.username) if user is None: raise credentials_exception return user
def get_settings(): return config.Settings()
def get_postgres_settings(): return config.Settings().postgres
def init_settings(self): settings = config.Settings(self.app.organizationName(), self.app.applicationName()) log.info(f"Configuration file: {settings.fileName()}") config.state.load(settings)
def get_keycloak_settings(): return config.Settings().keycloak
import asyncio from fastapi import FastAPI from app import rabbit_events from app.routes import devices from app import config from app import mongo_connection app = FastAPI() settings = config.Settings() # Iniciamos la cola de eventos de RabbitMQ @app.on_event("startup") async def startup_event(): asyncio.create_task(rabbit_events.start(settings)) asyncio.create_task(mongo_connection.start(settings)) # Agregamos las rutas de dispositivos app.include_router(devices.router)
def get_celery_settings(): return config.Settings().celery