Skip to content

Commit b0cc05b

Browse files
authored
Revert "Update configure command"
1 parent d39ef3b commit b0cc05b

File tree

1 file changed

+35
-57
lines changed

1 file changed

+35
-57
lines changed

guardrails/cli/configure.py

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,77 +24,55 @@ def save_configuration_file(token: str, no_metrics: bool) -> None:
2424
rc_file.close()
2525

2626

27-
def get_existing_config() -> dict:
28-
"""Get the configuration from the file if it exists."""
29-
home = expanduser("~")
30-
guardrails_rc = os.path.join(home, ".guardrailsrc")
31-
config = {}
32-
33-
# If the file exists
34-
if os.path.exists(guardrails_rc):
35-
with open(guardrails_rc, "r") as rc_file:
36-
lines = rc_file.readlines()
37-
for line in lines:
38-
key, value = line.strip().split("=")
39-
config[key] = value
40-
return config
41-
42-
4327
@guardrails.command()
4428
def configure(
4529
token: Optional[str] = typer.Option(
46-
None,
47-
help="Your Guardrails Hub auth token.",
48-
hide_input=True,
49-
prompt="Token (optional) [None]",
30+
help="Your Guardrails Hub auth token.", hide_input=True, default=""
5031
),
5132
no_metrics: Optional[str] = typer.Option(
52-
None,
53-
help="Opt out of anonymous metrics collection.",
54-
prompt="Disable anonymous metrics reporting? [Yes/No]",
33+
help="Opt out of anonymous metrics collection.", default=False
5534
),
5635
):
5736
"""Set the global configuration for the Guardrails CLI and Hub."""
58-
existing_config = get_existing_config()
37+
try:
38+
notice_message = """
5939
60-
# Normalize no_metrics to bool
61-
if no_metrics is not None:
62-
no_metrics_bool = no_metrics.lower() == 'yes'
63-
else:
64-
no_metrics_bool = existing_config.get("no_metrics", "false") == "true"
65-
66-
# Fetch existing token if None provided
67-
if token is None:
68-
token = existing_config.get("token", "")
40+
You can find your token at https://hub.guardrailsai.com/tokens
41+
"""
42+
logger.log(level=LEVELS.get("NOTICE"), msg=notice_message) # type: ignore
43+
if not token:
44+
token = typer.prompt("Token", hide_input=True)
45+
logger.info("Configuring...")
46+
save_configuration_file(token, no_metrics) # type: ignore
6947

70-
# Only save configuration if both token and no_metrics are valid
71-
if token and no_metrics is not None:
72-
save_configuration_file(token, no_metrics_bool)
73-
logger.info("Configuration saved.")
48+
logger.info("Validating credentials...")
49+
get_auth()
50+
success_message = """
7451
75-
# Authenticate with the Hub if token was updated
76-
if token != existing_config.get("token", ""):
77-
logger.info("Validating credentials...")
78-
#get_auth()
79-
success_message = """
80-
Login successful.
52+
Login successful.
8153
82-
Get started by installing our RegexMatch validator:
83-
https://hub.guardrailsai.com/validator/guardrails_ai/regex_match
54+
Get started by installing our RegexMatch validator:
55+
https://hub.guardrailsai.com/validator/guardrails_ai/regex_match
8456
85-
You can install it by running:
86-
guardrails hub install hub://guardrails/regex_match
57+
You can install it by running:
58+
guardrails hub install hub://guardrails/regex_match
8759
88-
Find more validators at https://hub.guardrailsai.com
60+
Find more validators at https://hub.guardrailsai.com
61+
"""
62+
logger.log(level=LEVELS.get("SUCCESS"), msg=success_message) # type: ignore
63+
except AuthenticationError as auth_error:
64+
logger.error(auth_error)
65+
logger.error(
8966
"""
90-
logger.log(level=LEVELS.get("SUCCESS", 25), msg=success_message) # Assuming 25 is the SUCCESS level
67+
Check that your token is correct and try again.
9168
92-
else:
93-
if not token:
94-
print("No token provided. Skipping authentication.")
95-
if no_metrics is None:
96-
print("No metrics preference provided. Skipping configuration update.")
69+
If you don't have your token credentials you can find them here:
9770
98-
# Log an information message if neither token nor no_metrics provided
99-
if not token and no_metrics is None:
100-
logger.info("No updates to configuration required.")
71+
https://hub.guardrailsai.com/tokens
72+
"""
73+
)
74+
sys.exit(1)
75+
except Exception as e:
76+
logger.error("An unexpected error occurred!")
77+
logger.error(e)
78+
sys.exit(1)

0 commit comments

Comments
 (0)