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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::cli::DatabricksCli;
use crate::shape::{relative_time, ListItem, Shape, Status};
use anyhow::Result;
/// Lists secret scopes, or the keys inside one scope. Values are never
/// fetched or shown anywhere — by design.
pub async fn fetch(cli: &DatabricksCli, scope: Option<&str>) -> Result<Shape> {
let items: Vec<ListItem> = match scope {
None => {
let json = cli.run(&["secrets", "list-scopes"]).await?;
json["scopes"]
.as_array()
.map(|scopes| {
scopes
.iter()
.map(|s| {
let name = s["name"].as_str().unwrap_or("?").to_string();
ListItem {
id: Some(name.clone()),
name,
status: Status::Unknown("SCOPE".to_string()),
detail: s["backend_type"].as_str().map(str::to_string),
history: Vec::new(),
}
})
.collect()
})
.unwrap_or_default()
}
Some(scope) => {
let args = ["secrets", "list-secrets", scope];
let json = cli.run(&args).await?;
json["secrets"]
.as_array()
.map(|keys| {
keys.iter()
.map(|k| {
let key = k["key"].as_str().unwrap_or("?").to_string();
ListItem {
id: Some(key.clone()),
name: key,
status: Status::Unknown("KEY".to_string()),
detail: k["last_updated_timestamp"]
.as_u64()
.map(|t| format!("updated {}", relative_time(t))),
history: Vec::new(),
}
})
.collect()
})
.unwrap_or_default()
}
};
let mut items = items;
items.sort_by_key(|i| i.name.to_lowercase());
Ok(Shape::List(items))
}