add flag to disable api auth (#5399)

This commit is contained in:
montezdesousa
2023-09-02 12:00:19 +01:00
committed by GitHub
parent 1468084a00
commit 55e507366c
3 changed files with 26 additions and 15 deletions

View File

@@ -353,9 +353,10 @@ To apply an environment variable use one of the following:
The variables we use are:
- `OPENBB_DEBUG_MODE`: enable/disable debug mode
- `OPENBB_DEVELOP_MODE`: enable/disable develop mode
- `OPENBB_AUTO_BUILD`: enable/disable automatic build for python package
- `OPENBB_DEBUG_MODE`: enables verbosity while running the program
- `OPENBB_DEVELOP_MODE`: points hub service to .co or .dev
- `OPENBB_AUTO_BUILD`: enables automatic SDK package build on import
- `OPENBB_API_AUTH`: enables commands authentication in FastAPI
## 4.2 Dynamic version

View File

@@ -13,6 +13,7 @@ from openbb_core.app.model.user_settings import UserSettings
from openbb_core.app.router import RouterLoader
from openbb_core.app.service.system_service import SystemService
from openbb_core.app.service.user_service import UserService
from openbb_core.env import Env
from pydantic import BaseModel
from typing_extensions import Annotated, ParamSpec
@@ -64,14 +65,15 @@ def build_new_signature(func):
)
)
new_parameter_list.append(
Parameter(
"__authenticated_user_settings",
kind=Parameter.POSITIONAL_OR_KEYWORD,
default=UserSettings(),
annotation=Annotated[UserSettings, Depends(get_user)],
if Env().API_AUTH:
new_parameter_list.append(
Parameter(
"__authenticated_user_settings",
kind=Parameter.POSITIONAL_OR_KEYWORD,
default=UserSettings(),
annotation=Annotated[UserSettings, Depends(get_user)],
)
)
)
return Signature(
parameters=new_parameter_list,

View File

@@ -17,20 +17,28 @@ class Env(metaclass=SingletonMeta):
@property
def DEBUG_MODE(self) -> bool:
return self.str_to_bool(self._environ.get("OPENBB_DEBUG_MODE", False))
"""Debug mode: enables verbosity while running the program"""
return self.str2bool(self._environ.get("OPENBB_DEBUG_MODE", False))
@property
def DEV_MODE(self) -> bool:
"""Develop mode: points hub service to .co or .dev"""
# TODO: Change default to false when ready to deploy
return self.str_to_bool(self._environ.get("OPENBB_DEV_MODE", True))
return self.str2bool(self._environ.get("OPENBB_DEV_MODE", True))
@property
def AUTO_BUILD(self) -> bool:
return self.str_to_bool(self._environ.get("OPENBB_AUTO_BUILD", True))
"""Automatic build: enables automatic SDK package build on import"""
return self.str2bool(self._environ.get("OPENBB_AUTO_BUILD", True))
@property
def API_AUTH(self) -> bool:
"""API authentication: enables commands authentication in FastAPI"""
return self.str2bool(self._environ.get("OPENBB_API_AUTH", True))
@staticmethod
def str_to_bool(value) -> bool:
"""Match a string to a boolean value."""
def str2bool(value) -> bool:
"""Match a value to its boolean correspondent."""
if isinstance(value, bool):
return value
if value.lower() in {"false", "f", "0", "no", "n"}: