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