| 5103 | } |
| 5104 | |
| 5105 | pub async fn provider_profile_import( |
| 5106 | server: &str, |
| 5107 | file: Option<&Path>, |
| 5108 | from: Option<&Path>, |
| 5109 | tls: &TlsOptions, |
| 5110 | ) -> Result<()> { |
| 5111 | let (items, mut diagnostics) = load_profile_import_items(file, from)?; |
| 5112 | if items.is_empty() && diagnostics.is_empty() { |
| 5113 | return Err(miette!("no provider profile files found")); |
| 5114 | } |
| 5115 | if profile_diagnostics_have_errors(&diagnostics) { |
| 5116 | print_profile_diagnostics(&diagnostics); |
| 5117 | return Err(miette!("provider profile import failed")); |
| 5118 | } |
| 5119 | |
| 5120 | let mut client = grpc_client(server, tls).await?; |
| 5121 | if !items.is_empty() { |
| 5122 | let response = client |
| 5123 | .import_provider_profiles(ImportProviderProfilesRequest { profiles: items }) |
| 5124 | .await |
| 5125 | .into_diagnostic()? |
| 5126 | .into_inner(); |
| 5127 | diagnostics.extend(response.diagnostics); |
| 5128 | if response.imported { |
| 5129 | println!( |
| 5130 | "Imported {} provider profile{}.", |
| 5131 | response.profiles.len(), |
| 5132 | if response.profiles.len() == 1 { |
| 5133 | "" |
| 5134 | } else { |
| 5135 | "s" |
| 5136 | } |
| 5137 | ); |
| 5138 | return Ok(()); |
| 5139 | } |
| 5140 | } |
| 5141 | |
| 5142 | print_profile_diagnostics(&diagnostics); |
| 5143 | Err(miette!("provider profile import failed")) |
| 5144 | } |
| 5145 | |
| 5146 | pub async fn provider_profile_update( |
| 5147 | server: &str, |