2020-05-21 08:46:07 +00:00
|
|
|
use anyhow::Error;
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler};
|
|
|
|
|
2021-09-02 12:25:15 +00:00
|
|
|
use pbs_api_types::REMOTE_ID_SCHEMA;
|
|
|
|
|
|
|
|
use proxmox_backup::api2;
|
|
|
|
|
2020-05-21 08:46:07 +00:00
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)]
|
|
|
|
/// List configured remotes.
|
|
|
|
fn list_remotes(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
|
|
|
|
let info = &api2::config::remote::API_METHOD_LIST_REMOTES;
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("name"))
|
|
|
|
.column(ColumnConfig::new("host"))
|
2021-02-11 10:31:20 +00:00
|
|
|
.column(ColumnConfig::new("auth-id"))
|
2020-05-21 08:46:07 +00:00
|
|
|
.column(ColumnConfig::new("fingerprint"))
|
|
|
|
.column(ColumnConfig::new("comment"));
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-05-21 08:46:07 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
schema: REMOTE_ID_SCHEMA,
|
|
|
|
},
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)]
|
|
|
|
/// Show remote configuration
|
|
|
|
fn show_remote(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
|
|
|
|
let info = &api2::config::remote::API_METHOD_READ_REMOTE;
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options();
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-05-21 08:46:07 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remote_commands() -> CommandLineInterface {
|
|
|
|
|
|
|
|
let cmd_def = CliCommandMap::new()
|
|
|
|
.insert("list", CliCommand::new(&&API_METHOD_LIST_REMOTES))
|
|
|
|
.insert(
|
|
|
|
"show",
|
|
|
|
CliCommand::new(&API_METHOD_SHOW_REMOTE)
|
|
|
|
.arg_param(&["name"])
|
2021-09-02 12:25:15 +00:00
|
|
|
.completion_cb("name", pbs_config::remote::complete_remote_name)
|
2020-05-21 08:46:07 +00:00
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"create",
|
|
|
|
// fixme: howto handle password parameter?
|
|
|
|
CliCommand::new(&api2::config::remote::API_METHOD_CREATE_REMOTE)
|
|
|
|
.arg_param(&["name"])
|
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"update",
|
|
|
|
CliCommand::new(&api2::config::remote::API_METHOD_UPDATE_REMOTE)
|
|
|
|
.arg_param(&["name"])
|
2021-09-02 12:25:15 +00:00
|
|
|
.completion_cb("name", pbs_config::remote::complete_remote_name)
|
2020-05-21 08:46:07 +00:00
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"remove",
|
|
|
|
CliCommand::new(&api2::config::remote::API_METHOD_DELETE_REMOTE)
|
|
|
|
.arg_param(&["name"])
|
2021-09-02 12:25:15 +00:00
|
|
|
.completion_cb("name", pbs_config::remote::complete_remote_name)
|
2020-05-21 08:46:07 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
cmd_def.into()
|
|
|
|
}
|