Skip to content

Commit

Permalink
simplify message in studio login/logout flow (iterative#10297)
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry authored Feb 9, 2024
1 parent 953ae56 commit f639ab5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions dvc/commands/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dvc.cli import formatter
from dvc.cli.utils import append_doc_link
from dvc.commands.config import CmdConfig
from dvc.exceptions import DvcException
from dvc.log import logger

logger = logger.getChild(__name__)
Expand All @@ -22,8 +23,16 @@ def run(self):
hostname = self.args.hostname or os.environ.get(DVC_STUDIO_URL) or STUDIO_URL
scopes = self.args.scopes

studio = self.config.get("studio", {})
if studio.get("url", hostname) == hostname and "token" in studio:
raise DvcException(
"Token already exists. "
"To login with a different token, "
"logout using 'dvc studio logout'."
)

try:
token_name, access_token = get_access_token(
_, access_token = get_access_token(
token_name=name,
hostname=hostname,
scopes=scopes,
Expand All @@ -35,11 +44,9 @@ def run(self):
return 1

self.save_config(hostname, access_token)
ui.write(
"Authentication has been successfully completed."
"The generated token will now be accessible as"
f" {token_name} in the user's Studio profile."
)

config_path = self.config.files["global"]
ui.write(f"Authentication complete. Saved token to {config_path}.")
return 0

def save_config(self, hostname, token):
Expand All @@ -54,12 +61,14 @@ def run(self):

with self.config.edit("global") as conf:
if not get_in(conf, ["studio", "token"]):
ui.error_write("Not logged in to Studio.")
ui.error_write(
"Not logged in to Studio. Log in with 'dvc studio login'."
)
return 1

del conf["studio"]["token"]

ui.write("Logged out from Studio")
ui.write("Logged out from Studio (you can log back in with 'dvc studio login')")
return 0


Expand Down

0 comments on commit f639ab5

Please sign in to comment.