From 1bfc1efa505865bec6bc644f6a9ce334962459e6 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 17 Apr 2020 15:14:28 +0200 Subject: [PATCH] src/api2/subscription.rs: add access permissions --- src/api2/subscription.rs | 44 ++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/api2/subscription.rs b/src/api2/subscription.rs index 86b0b040..f88f2d7d 100644 --- a/src/api2/subscription.rs +++ b/src/api2/subscription.rs @@ -1,16 +1,39 @@ use failure::*; use serde_json::{json, Value}; -use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment}; -use proxmox::api::schema::ObjectSchema; +use proxmox::api::{api, Router, Permission}; use crate::tools; +use crate::config::acl::PRIV_SYS_AUDIT; -fn get_subscription( - _param: Value, - _info: &ApiMethod, - _rpcenv: &mut dyn RpcEnvironment, -) -> Result { +#[api( + returns: { + description: "Subscription status.", + properties: { + status: { + type: String, + description: "'NotFound', 'active' or 'inactive'." + }, + message: { + type: String, + description: "Human readable problem description.", + }, + serverid: { + type: String, + description: "The unique server ID.", + }, + url: { + type: String, + description: "URL to Web Shop.", + }, + }, + }, + access: { + permission: &Permission::Privilege(&[], PRIV_SYS_AUDIT, false), + }, +)] +/// Read subscription info. +fn get_subscription(_param: Value) -> Result { let url = "https://www.proxmox.com/en/proxmox-backup-server/pricing"; Ok(json!({ @@ -22,9 +45,4 @@ fn get_subscription( } pub const ROUTER: Router = Router::new() - .get( - &ApiMethod::new( - &ApiHandler::Sync(&get_subscription), - &ObjectSchema::new("Read subscription info.", &[]) - ) - ); + .get(&API_METHOD_GET_SUBSCRIPTION);