diff --git a/Cargo.toml b/Cargo.toml index 648c9806..bf6b76d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ openssl = "0.10" pam = "0.7" pam-sys = "0.5" pin-utils = "0.1.0-alpha" -proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1", features = [ "sortable-macro" ] } +proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1", features = [ "sortable-macro", "api-macro" ] } regex = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/api2/access.rs b/src/api2/access.rs index e7ba4790..10d53389 100644 --- a/src/api2/access.rs +++ b/src/api2/access.rs @@ -2,11 +2,11 @@ use failure::*; use serde_json::{json, Value}; -use proxmox::{sortable, identity}; +use proxmox::sortable; use proxmox::api::{http_err, list_subdirs_api_method}; -use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment}; +use proxmox::api::{ApiMethod, Router, RpcEnvironment}; use proxmox::api::router::SubdirMap; -use proxmox::api::schema::*; +use proxmox::api::api; use crate::tools; use crate::tools::ticket::*; @@ -36,6 +36,40 @@ fn authenticate_user(username: &str, password: &str) -> Result<(), Error> { bail!("inavlid credentials"); } +#[api] +#[input({ + properties: { + username: { + type: String, + description: "User name.", + max_length: 64, + }, + password: { + type: String, + description: "The secret password. This can also be a valid ticket.", + }, + }, +})] +#[returns({ + properties: { + username: { + type: String, + description: "User name.", + }, + ticket: { + type: String, + description: "Auth ticket.", + }, + CSRFPreventionToken: { + type: String, + description: "Cross Site Request Forgery Prevention Token.", + }, + }, +})] +#[protected] +/// Create or verify authentication ticket. +/// +/// Returns: An authentication ticket with additional infos. fn create_ticket( param: Value, _info: &ApiMethod, @@ -72,51 +106,7 @@ fn create_ticket( const SUBDIRS: SubdirMap = &[ ( "ticket", &Router::new() - .post( - &ApiMethod::new( - &ApiHandler::Sync(&create_ticket), - &ObjectSchema::new( - "Create or verify authentication ticket.", - &sorted!([ - ( - "username", - false, - &StringSchema::new("User name.") - .max_length(64) - .schema() - ), - ( - "password", - false, - &StringSchema::new("The secret password. This can also be a valid ticket.") - .schema() - ), - ]), - ) - ).returns( - &ObjectSchema::new( - "Returns authentication ticket with additional infos.", - &sorted!([ - ( - "username", - false, - &StringSchema::new("User name.").schema() - ), - ( - "ticket", - false, - &StringSchema::new("Auth ticket.").schema() - ), - ( - "CSRFPreventionToken", - false, - &StringSchema::new("Cross Site Request Forgery Prevention Token.") - .schema() - ), - ]), - ).schema() - ).protected(true) - ) + .post(&API_METHOD_CREATE_TICKET) ) ];