MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / execute

Method execute

atomic-cli/src/commands/identity/delegation.rs:174–232  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

172
173impl Push {
174 async fn execute(&self) -> CliResult<()> {
175 let store = IdentityStore::open_default().map_err(|e| {
176 CliError::Internal(anyhow::anyhow!("Failed to open identity store: {e}"))
177 })?;
178
179 let documents = match &self.id {
180 Some(id) => vec![(normalize_id(id)?, load_document(&store, id)?)],
181 None => store
182 .list_delegations()
183 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to list: {e}")))?,
184 };
185
186 if documents.is_empty() {
187 print_hint("No certificates to push.");
188 return Ok(());
189 }
190
191 let mut pushed = 0;
192 for (id, raw) in documents {
193 let Ok(value) = jcs::admit_document(raw.as_bytes()) else {
194 print_warning(&format!("Skipping {id}: refused at the ingest boundary"));
195 continue;
196 };
197 let Ok(delegation) = cert::verify_self_contained(&value) else {
198 print_warning(&format!("Skipping {id}: does not verify"));
199 continue;
200 };
201 if delegation.is_expired() {
202 continue;
203 }
204
205 // The delegator must be on this machine — the server authenticates
206 // the *human*, since only they may enroll on their own behalf.
207 let Ok(delegator) = store.load_by_name(&delegation.delegator_name) else {
208 print_warning(&format!(
209 "Skipping {id}: the delegating identity '{}' is not on this machine",
210 delegation.delegator_name
211 ));
212 continue;
213 };
214
215 let (client, url) =
216 crate::commands::client::build_apex_client_as(&delegator, self.server.as_deref())
217 .await?;
218 let request = PushDelegationRequest { certificate: value };
219 match client.push_delegation(&request).await {
220 Ok(_) => {
221 println!(" {} → {url}", delegation.id.to_urn());
222 pushed += 1;
223 }
224 Err(e) => print_warning(&format!("Failed to push {id}: {e}")),
225 }
226 }
227
228 if pushed > 0 {
229 print_success(&format!("Pushed {pushed} certificate(s)"));
230 }
231 Ok(())

Callers 1

runMethod · 0.45

Calls 15

print_hintFunction · 0.85
admit_documentFunction · 0.85
print_warningFunction · 0.85
verify_self_containedFunction · 0.85
build_apex_client_asFunction · 0.85
print_successFunction · 0.85
load_documentFunction · 0.85
normalize_idFunction · 0.85
mint_revocationFunction · 0.85
load_by_nameMethod · 0.80
push_delegationMethod · 0.80
time_remainingMethod · 0.80

Tested by

no test coverage detected