1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Your cocore.dev API keys (dev.cocore.account.*ApiKey), authenticated by your PDS's service auth.
use abi::{Call, Handle, Run};
use cocore::{Args, CONSOLE, field, once, required};
use serde_json::json;
const NS: &str = "dev.cocore.account";
fn list(run: Run<Args>) -> Result<Handle, String> {
once(run.event, || Ok(Call::new("", format!("{NS}.listApiKeys")).params(json!({})).proxy(CONSOLE)))
}
/// The secret is in the result once; cocore keeps only its hash.
fn create(run: Run<Args>) -> Result<Handle, String> {
let args = run.args;
once(run.event, || {
let mut input = json!({ "name": required(&args, "name")? });
if let Some(at) = field(&args, "expiresAt") {
input["expiresAt"] = json!(at);
}
Ok(Call::new("", format!("{NS}.createApiKey")).input(input).proxy(CONSOLE))
})
}
fn by_id(run: Run<Args>, nsid: &str) -> Result<Handle, String> {
let args = run.args;
once(run.event, || Ok(Call::new("", format!("{NS}.{nsid}")).input(json!({ "id": required(&args, "id")? })).proxy(CONSOLE)))
}
fn revoke(run: Run<Args>) -> Result<Handle, String> {
by_id(run, "revokeApiKey")
}
fn delete(run: Run<Args>) -> Result<Handle, String> {
by_id(run, "deleteApiKey")
}
abi::entries!(list_keys => list, create_key => create, revoke_key => revoke, delete_key => delete);