Skip to main content

systemprompt_cli/commands/cloud/profile/
edit_settings.rs

1use anyhow::{Context, Result};
2use systemprompt_logging::CliService;
3use systemprompt_models::{Environment, LogLevel, Profile};
4
5use crate::interactive::Prompter;
6
7pub fn edit_server_settings(prompter: &dyn Prompter, profile: &mut Profile) -> Result<()> {
8    CliService::section("Server Settings");
9
10    profile.server.host = prompter.input_with_default("Host", &profile.server.host)?;
11
12    profile.server.port = prompter
13        .input_with_default("Port", &profile.server.port.to_string())?
14        .trim()
15        .parse()
16        .context("Invalid port")?;
17
18    profile.server.api_server_url =
19        prompter.input_with_default("API Server URL", &profile.server.api_server_url)?;
20
21    profile.server.api_external_url =
22        prompter.input_with_default("API External URL", &profile.server.api_external_url)?;
23
24    profile.server.use_https = prompter.confirm("Use HTTPS?", profile.server.use_https)?;
25
26    CliService::success("Server settings updated");
27    Ok(())
28}
29
30pub fn edit_security_settings(prompter: &dyn Prompter, profile: &mut Profile) -> Result<()> {
31    CliService::section("Security Settings");
32
33    profile.security.issuer =
34        prompter.input_with_default("JWT Issuer", &profile.security.issuer)?;
35
36    profile.security.access_token_expiration = prompter
37        .input_with_default(
38            "Access Token Expiration (seconds)",
39            &profile.security.access_token_expiration.to_string(),
40        )?
41        .trim()
42        .parse()
43        .context("Invalid access token expiration")?;
44
45    profile.security.refresh_token_expiration = prompter
46        .input_with_default(
47            "Refresh Token Expiration (seconds)",
48            &profile.security.refresh_token_expiration.to_string(),
49        )?
50        .trim()
51        .parse()
52        .context("Invalid refresh token expiration")?;
53
54    CliService::success("Security settings updated");
55    Ok(())
56}
57
58pub fn edit_runtime_settings(prompter: &dyn Prompter, profile: &mut Profile) -> Result<()> {
59    CliService::section("Runtime Settings");
60
61    let env_options: Vec<String> = ["development", "test", "staging", "production"]
62        .into_iter()
63        .map(str::to_owned)
64        .collect();
65
66    let env_selection = prompter.select("Environment", &env_options)?;
67
68    profile.runtime.environment = env_options[env_selection]
69        .parse::<Environment>()
70        .map_err(|e| anyhow::anyhow!("{}", e))?;
71
72    let log_options: Vec<String> = ["quiet", "normal", "verbose", "debug"]
73        .into_iter()
74        .map(str::to_owned)
75        .collect();
76
77    let log_selection = prompter.select("Log Level", &log_options)?;
78
79    profile.runtime.log_level = log_options[log_selection]
80        .parse::<LogLevel>()
81        .map_err(|e| anyhow::anyhow!("{}", e))?;
82
83    CliService::success("Runtime settings updated");
84    Ok(())
85}