types: extract DataStoreListItem

for reuse in remote scan API call

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2020-11-05 12:12:22 +01:00 committed by Thomas Lamprecht
parent c26c9390ff
commit 455e5f7110
2 changed files with 27 additions and 15 deletions

View File

@ -902,15 +902,7 @@ pub fn garbage_collection_status(
type: Array, type: Array,
items: { items: {
description: "Datastore name and description.", description: "Datastore name and description.",
properties: { type: DataStoreListItem,
store: {
schema: DATASTORE_SCHEMA,
},
comment: {
optional: true,
schema: SINGLE_LINE_COMMENT_SCHEMA,
},
},
}, },
}, },
access: { access: {
@ -922,7 +914,7 @@ fn get_datastore_list(
_param: Value, _param: Value,
_info: &ApiMethod, _info: &ApiMethod,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Vec<DataStoreListItem>, Error> {
let (config, _digest) = datastore::config()?; let (config, _digest) = datastore::config()?;
@ -935,11 +927,12 @@ fn get_datastore_list(
let user_privs = user_info.lookup_privs(&auth_id, &["datastore", &store]); let user_privs = user_info.lookup_privs(&auth_id, &["datastore", &store]);
let allowed = (user_privs & (PRIV_DATASTORE_AUDIT| PRIV_DATASTORE_BACKUP)) != 0; let allowed = (user_privs & (PRIV_DATASTORE_AUDIT| PRIV_DATASTORE_BACKUP)) != 0;
if allowed { if allowed {
let mut entry = json!({ "store": store }); list.push(
if let Some(comment) = data["comment"].as_str() { DataStoreListItem {
entry["comment"] = comment.into(); store: store.clone(),
comment: data["comment"].as_str().map(String::from),
} }
list.push(entry); );
} }
} }

View File

@ -370,6 +370,25 @@ pub const BLOCKDEVICE_NAME_SCHEMA: Schema = StringSchema::new("Block device name
// Complex type definitions // Complex type definitions
#[api(
properties: {
store: {
schema: DATASTORE_SCHEMA,
},
comment: {
optional: true,
schema: SINGLE_LINE_COMMENT_SCHEMA,
},
},
)]
#[derive(Serialize, Deserialize)]
#[serde(rename_all="kebab-case")]
/// Basic information about a datastore.
pub struct DataStoreListItem {
pub store: String,
pub comment: Option<String>,
}
#[api( #[api(
properties: { properties: {
"backup-type": { "backup-type": {