|
2 | 2 |
|
3 | 3 | use anyhow::{Context, Result}; |
4 | 4 | use auths_sdk::workflows::allowed_signers::{ |
5 | | - AllowedSigners, AllowedSignersError, EmailAddress, SignerPrincipal, SignerSource, |
| 5 | + AllowedSigners, AllowedSignersError, EmailAddress, SignerPrincipal, SignerSource, SyncReport, |
6 | 6 | }; |
7 | 7 | use auths_storage::git::RegistryAttestationStorage; |
8 | 8 | use auths_verifier::core::Ed25519PublicKey; |
@@ -208,26 +208,32 @@ fn handle_remove(args: &SignersRemoveArgs) -> Result<()> { |
208 | 208 | Ok(()) |
209 | 209 | } |
210 | 210 |
|
| 211 | +/// Core sync logic — no printing. Reused by init and `auths signers sync`. |
| 212 | +pub(crate) fn sync_signers( |
| 213 | + repo: &std::path::Path, |
| 214 | + output_file: &std::path::Path, |
| 215 | +) -> Result<(PathBuf, SyncReport)> { |
| 216 | + let storage = RegistryAttestationStorage::new(repo); |
| 217 | + let mut signers = AllowedSigners::load(output_file, &FileAllowedSignersStore) |
| 218 | + .with_context(|| format!("Failed to load {}", output_file.display()))?; |
| 219 | + let report = signers |
| 220 | + .sync(&storage) |
| 221 | + .context("Failed to sync attestations")?; |
| 222 | + signers |
| 223 | + .save(&FileAllowedSignersStore) |
| 224 | + .with_context(|| format!("Failed to write {}", output_file.display()))?; |
| 225 | + Ok((output_file.to_path_buf(), report)) |
| 226 | +} |
| 227 | + |
211 | 228 | pub(crate) fn handle_sync(args: &SignersSyncArgs) -> Result<()> { |
212 | 229 | let repo_path = expand_tilde(&args.repo)?; |
213 | | - let storage = RegistryAttestationStorage::new(&repo_path); |
214 | | - |
215 | 230 | let path = if let Some(ref output) = args.output_file { |
216 | 231 | expand_tilde(output).map_err(|e| anyhow::anyhow!("{}", e))? |
217 | 232 | } else { |
218 | 233 | resolve_signers_path()? |
219 | 234 | }; |
220 | 235 |
|
221 | | - let mut signers = AllowedSigners::load(&path, &FileAllowedSignersStore) |
222 | | - .with_context(|| format!("Failed to load {}", path.display()))?; |
223 | | - |
224 | | - let report = signers |
225 | | - .sync(&storage) |
226 | | - .context("Failed to sync attestations")?; |
227 | | - |
228 | | - signers |
229 | | - .save(&FileAllowedSignersStore) |
230 | | - .with_context(|| format!("Failed to write {}", path.display()))?; |
| 236 | + let (path, report) = sync_signers(&repo_path, &path)?; |
231 | 237 |
|
232 | 238 | println!( |
233 | 239 | "Synced: {} added, {} removed, {} manual preserved", |
|
0 commit comments