Initiates the profile creation process. There are only two ways to create a profile: 1. By prompting your user and email. 2. By opening the browser and creating the credentials in the console.
(
scx: &Context,
no_browser: bool,
force: bool,
admin_endpoint: Option<Url>,
cloud_endpoint: Option<Url>,
)
| 153 | /// 1. By prompting your user and email. |
| 154 | /// 2. By opening the browser and creating the credentials in the console. |
| 155 | pub async fn init( |
| 156 | scx: &Context, |
| 157 | no_browser: bool, |
| 158 | force: bool, |
| 159 | admin_endpoint: Option<Url>, |
| 160 | cloud_endpoint: Option<Url>, |
| 161 | ) -> Result<(), Error> { |
| 162 | let config_file = scx.config_file(); |
| 163 | let profile = scx |
| 164 | .get_global_profile() |
| 165 | .unwrap_or_else(|| config_file.profile().to_string()); |
| 166 | |
| 167 | if let Some(profiles) = scx.config_file().profiles() { |
| 168 | if profiles.contains_key(&profile) && !force { |
| 169 | return Err(ProfileNameAlreadyExistsError(profile)); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | let app_password = match no_browser { |
| 174 | true => init_without_browser(admin_endpoint.clone()).await?, |
| 175 | false => init_with_browser(cloud_endpoint.clone()).await?, |
| 176 | }; |
| 177 | |
| 178 | let new_profile = TomlProfile { |
| 179 | app_password: Some(app_password.to_string()), |
| 180 | vault: None, |
| 181 | region: None, |
| 182 | admin_endpoint: admin_endpoint.map(|url| url.to_string()), |
| 183 | cloud_endpoint: cloud_endpoint.map(|url| url.to_string()), |
| 184 | }; |
| 185 | |
| 186 | config_file.add_profile(profile, new_profile).await?; |
| 187 | |
| 188 | Ok(()) |
| 189 | } |
| 190 | |
| 191 | /// List all the possible config values for the profile. |
| 192 | pub fn list(cx: &Context) -> Result<(), Error> { |
no test coverage detected