4 use std
::collections
::HashMap
;
6 use proxmox
::api
::{api, cli::*, RpcEnvironment, ApiHandler}
;
8 use proxmox_backup
::config
;
9 use proxmox_backup
::tools
;
10 use proxmox_backup
::api2
;
11 use proxmox_backup
::api2
::types
::{ACL_PATH_SCHEMA, Authid, Userid}
;
17 schema
: OUTPUT_FORMAT
,
23 /// List configured users.
24 fn list_users(param
: Value
, rpcenv
: &mut dyn RpcEnvironment
) -> Result
<Value
, Error
> {
26 let output_format
= get_output_format(¶m
);
28 let info
= &api2
::access
::user
::API_METHOD_LIST_USERS
;
29 let mut data
= match info
.handler
{
30 ApiHandler
::Sync(handler
) => (handler
)(param
, info
, rpcenv
)?
,
34 let options
= default_table_format_options()
35 .column(ColumnConfig
::new("userid"))
37 ColumnConfig
::new("enable")
38 .renderer(tools
::format
::render_bool_with_default_true
)
41 ColumnConfig
::new("expire")
42 .renderer(tools
::format
::render_epoch
)
44 .column(ColumnConfig
::new("firstname"))
45 .column(ColumnConfig
::new("lastname"))
46 .column(ColumnConfig
::new("email"))
47 .column(ColumnConfig
::new("comment"));
49 format_and_print_result_full(&mut data
, &info
.returns
, &output_format
, &options
);
58 schema
: OUTPUT_FORMAT
,
67 /// List tokens associated with user.
68 fn list_tokens(param
: Value
, rpcenv
: &mut dyn RpcEnvironment
) -> Result
<Value
, Error
> {
70 let output_format
= get_output_format(¶m
);
72 let info
= &api2
::access
::user
::API_METHOD_LIST_TOKENS
;
73 let mut data
= match info
.handler
{
74 ApiHandler
::Sync(handler
) => (handler
)(param
, info
, rpcenv
)?
,
78 let options
= default_table_format_options()
79 .column(ColumnConfig
::new("tokenid"))
81 ColumnConfig
::new("enable")
82 .renderer(tools
::format
::render_bool_with_default_true
)
85 ColumnConfig
::new("expire")
86 .renderer(tools
::format
::render_epoch
)
88 .column(ColumnConfig
::new("comment"));
90 format_and_print_result_full(&mut data
, &info
.returns
, &output_format
, &options
);
100 schema
: OUTPUT_FORMAT
,
107 schema
: ACL_PATH_SCHEMA
,
113 /// List permissions of user/token.
114 fn list_permissions(param
: Value
, rpcenv
: &mut dyn RpcEnvironment
) -> Result
<Value
, Error
> {
116 let output_format
= get_output_format(¶m
);
118 let info
= &api2
::access
::API_METHOD_LIST_PERMISSIONS
;
119 let mut data
= match info
.handler
{
120 ApiHandler
::Sync(handler
) => (handler
)(param
, info
, rpcenv
)?
,
124 if output_format
== "text" {
125 println
!("Privileges with (*) have the propagate flag set\n");
126 let data
:HashMap
<String
, HashMap
<String
, bool
>> = serde_json
::from_value(data
)?
;
127 let mut paths
:Vec
<String
> = data
.keys().cloned().collect();
128 paths
.sort_unstable();
130 println
!("Path: {}", path
);
131 let priv_map
= data
.get(&path
).unwrap();
132 let mut privs
:Vec
<String
> = priv_map
.keys().cloned().collect();
133 if privs
.is_empty() {
134 println
!("- NoAccess");
136 privs
.sort_unstable();
137 for privilege
in privs
{
138 if *priv_map
.get(&privilege
).unwrap() {
139 println
!("- {} (*)", privilege
);
141 println
!("- {}", privilege
);
147 format_and_print_result(&mut data
, &output_format
);
154 pub fn user_commands() -> CommandLineInterface
{
156 let cmd_def
= CliCommandMap
::new()
157 .insert("list", CliCommand
::new(&&API_METHOD_LIST_USERS
))
160 // fixme: howto handle password parameter?
161 CliCommand
::new(&api2
::access
::user
::API_METHOD_CREATE_USER
)
162 .arg_param(&["userid"])
166 CliCommand
::new(&api2
::access
::user
::API_METHOD_UPDATE_USER
)
167 .arg_param(&["userid"])
168 .completion_cb("userid", config
::user
::complete_userid
)
172 CliCommand
::new(&api2
::access
::user
::API_METHOD_DELETE_USER
)
173 .arg_param(&["userid"])
174 .completion_cb("userid", config
::user
::complete_userid
)
178 CliCommand
::new(&&API_METHOD_LIST_TOKENS
)
179 .arg_param(&["userid"])
180 .completion_cb("userid", config
::user
::complete_userid
)
184 CliCommand
::new(&api2
::access
::user
::API_METHOD_GENERATE_TOKEN
)
185 .arg_param(&["userid", "tokenname"])
186 .completion_cb("userid", config
::user
::complete_userid
)
190 CliCommand
::new(&api2
::access
::user
::API_METHOD_DELETE_TOKEN
)
191 .arg_param(&["userid", "tokenname"])
192 .completion_cb("userid", config
::user
::complete_userid
)
193 .completion_cb("tokenname", config
::user
::complete_token_name
)
197 CliCommand
::new(&&API_METHOD_LIST_PERMISSIONS
)
198 .arg_param(&["auth-id"])
199 .completion_cb("auth-id", config
::user
::complete_authid
)
200 .completion_cb("path", config
::datastore
::complete_acl_path
)