diff --git a/src/bentoml/_internal/cloud/config.py b/src/bentoml/_internal/cloud/config.py index 04d8bd61147..440f1f8518a 100644 --- a/src/bentoml/_internal/cloud/config.py +++ b/src/bentoml/_internal/cloud/config.py @@ -41,7 +41,7 @@ def get_email(self) -> str: "Unable to get current user from yatai server" ) self.email = user.email - add_context(self, ignore_warning=True) + _ = add_context(self, ignore_warning=True) return self.email @@ -116,7 +116,9 @@ def get_config( return bentoml_cattr.structure(yaml_content, cls) -def add_context(context: CloudClientContext, *, ignore_warning: bool = False) -> None: +def add_context( + context: CloudClientContext, *, ignore_warning: bool = False +) -> CloudClientConfig: config = CloudClientConfig.get_config() for idx, ctx in enumerate(config.contexts): if ctx.name == context.name: @@ -127,6 +129,7 @@ def add_context(context: CloudClientContext, *, ignore_warning: bool = False) -> else: config.contexts.append(context) config.to_yaml_file() + return config def get_context(context: str | None) -> CloudClientContext: diff --git a/src/bentoml_cli/cloud.py b/src/bentoml_cli/cloud.py index 56f68479ea5..90837c870cf 100644 --- a/src/bentoml_cli/cloud.py +++ b/src/bentoml_cli/cloud.py @@ -61,7 +61,8 @@ def login(shared_options: SharedOptions, endpoint: str, api_token: str) -> None: email=user.email, ) - add_context(ctx) + new_config = add_context(ctx) + _ = new_config.set_current_context(ctx.name) click.echo(f"Successfully logged in to Cloud for {user.name} in {org.name}")