From e4f0415dfd3cb302bae23123b102355442187b66 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:42:43 -0800 Subject: [PATCH] chore: address comments Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- .../_internal/configuration/__init__.py | 8 +------ .../_internal/configuration/containers.py | 21 +++++++++++------ .../_internal/configuration/v1/__init__.py | 23 ++++++++----------- .../v1/default_configuration.yaml | 14 +++++------ 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/bentoml/_internal/configuration/__init__.py b/src/bentoml/_internal/configuration/__init__.py index a67f68407a9..84304ec14b2 100644 --- a/src/bentoml/_internal/configuration/__init__.py +++ b/src/bentoml/_internal/configuration/__init__.py @@ -13,18 +13,12 @@ from ..._version import __version__ from ..._version import __version_tuple__ except ImportError: -<<<<<<< HEAD # Since we aren't VCS _version.py, which is generated by setuptools_scm # BentoML uses setuptools_scm 'post-release' for version scheme from setuptools_scm import get_version __version__ = get_version(version_scheme="post-release") __version_tuple__ = (0, 0, 0, "dirty") -======= - # broken installation. - __version__ = "unknown" - __version_tuple__ = (0, 0, 0, "unknown") ->>>>>>> efb2b979 (revert: unrelated change) # Note this file is loaded prior to logging being configured, thus logger is only @@ -164,7 +158,7 @@ def load_config(bentoml_config_file: str | None = None): ) -def save_global_config(config_file_handle: t.IO[t.Any]): +def save_config(config_file_handle: t.IO[t.Any]): import yaml from ..configuration.containers import BentoMLContainer diff --git a/src/bentoml/_internal/configuration/containers.py b/src/bentoml/_internal/configuration/containers.py index b0205b61ca0..79d5367bb54 100644 --- a/src/bentoml/_internal/configuration/containers.py +++ b/src/bentoml/_internal/configuration/containers.py @@ -228,13 +228,20 @@ def serve_info() -> ServeInfo: @providers.SingletonFactory @staticmethod def access_control_options( - allow_origin: str | None = Provide[cors.allow_origin], - allow_origin_regex: str | None = Provide[cors.allow_origin_regex], - allow_credentials: bool | None = Provide[cors.allow_credentials], - allow_methods: list[str] | str | None = Provide[cors.allow_methods], - allow_headers: list[str] | str | None = Provide[cors.allow_headers], - max_age: int | None = Provide[cors.max_age], - expose_headers: list[str] | str | None = Provide[cors.expose_headers], + allow_origin: str | None = Provide[cors.access_control_allow_origin], + allow_origin_regex: str + | None = Provide[cors.access_control_allow_origin_regex], + allow_credentials: bool | None = Provide[cors.access_control_allow_credentials], + allow_methods: list[str] + | str + | None = Provide[cors.access_control_allow_methods], + allow_headers: list[str] + | str + | None = Provide[cors.access_control_allow_headers], + max_age: int | None = Provide[cors.access_control_max_age], + expose_headers: list[str] + | str + | None = Provide[cors.access_control_expose_headers], ) -> dict[str, list[str] | str | int]: return { k: v diff --git a/src/bentoml/_internal/configuration/v1/__init__.py b/src/bentoml/_internal/configuration/v1/__init__.py index ee6720e53f4..b054e93411b 100644 --- a/src/bentoml/_internal/configuration/v1/__init__.py +++ b/src/bentoml/_internal/configuration/v1/__init__.py @@ -96,13 +96,15 @@ "port": s.And(int, ensure_larger_than_zero), "cors": { "enabled": bool, - "allow_origin": s.Or(str, None), - "allow_origin_regex": s.Or(s.And(str, s.Use(re.compile)), None), - "allow_credentials": s.Or(bool, None), - "allow_headers": s.Or([str], str, None), - "allow_methods": s.Or([str], str, None), - "max_age": s.Or(int, None), - "expose_headers": s.Or([str], str, None), + "access_control_allow_origin": s.Or(str, None), + "access_control_allow_origin_regex": s.Or( + s.And(str, s.Use(re.compile)), None + ), + "access_control_allow_credentials": s.Or(bool, None), + "access_control_allow_headers": s.Or([str], str, None), + "access_control_allow_methods": s.Or([str], str, None), + "access_control_max_age": s.Or(int, None), + "access_control_expose_headers": s.Or([str], str, None), }, }, "grpc": { @@ -216,12 +218,7 @@ def migration(*, override_config: dict[str, t.Any]): rename_fields( override_config, current=f"api_server.cors.access_control_{f}", - replace_with=f"api_server.http.cors.{f}", - ) - rename_fields( - override_config, - current=f"api_server.http.cors.access_control_{f}", - replace_with=f"api_server.http.cors.{f}", + replace_with=f"api_server.http.cors.access_control_{f}", ) # 4. if ssl is present, in version 2 we introduce a api_server.ssl.enabled field to determine diff --git a/src/bentoml/_internal/configuration/v1/default_configuration.yaml b/src/bentoml/_internal/configuration/v1/default_configuration.yaml index 6d735424ed9..662730884c4 100644 --- a/src/bentoml/_internal/configuration/v1/default_configuration.yaml +++ b/src/bentoml/_internal/configuration/v1/default_configuration.yaml @@ -52,13 +52,13 @@ api_server: port: 3000 cors: enabled: false - allow_origin: ~ - allow_credentials: ~ - allow_methods: ~ - allow_headers: ~ - allow_origin_regex: ~ - max_age: ~ - expose_headers: ~ + access_control_allow_origin: ~ + access_control_allow_credentials: ~ + access_control_allow_methods: ~ + access_control_allow_headers: ~ + access_control_allow_origin_regex: ~ + access_control_max_age: ~ + access_control_expose_headers: ~ grpc: host: 0.0.0.0 port: 3000