From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 91B86704EA for ; Thu, 24 Jun 2021 12:17:52 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D1C1999CF for ; Thu, 24 Jun 2021 12:17:24 +0200 (CEST) Received: from dev7.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4F743997C for ; Thu, 24 Jun 2021 12:17:21 +0200 (CEST) Received: by dev7.proxmox.com (Postfix, from userid 0) id 1FA1680E26; Thu, 24 Jun 2021 12:17:21 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Thu, 24 Jun 2021 12:17:15 +0200 Message-Id: <20210624101719.2113280-6-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624101719.2113280-1-dietmar@proxmox.com> References: <20210624101719.2113280-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.628 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup v2 5/9] cli: add CLI to manage openid realms. X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2021 10:17:52 -0000 --- src/bin/proxmox-backup-manager.rs | 1 + src/bin/proxmox_backup_manager/mod.rs | 2 + src/bin/proxmox_backup_manager/openid.rs | 99 ++++++++++++++++++++++++ src/config/domains.rs | 9 +++ 4 files changed, 111 insertions(+) create mode 100644 src/bin/proxmox_backup_manager/openid.rs diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index c3806a31..461d45bd 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -354,6 +354,7 @@ fn main() { .insert("network", network_commands()) .insert("node", node_commands()) .insert("user", user_commands()) + .insert("openid", openid_commands()) .insert("remote", remote_commands()) .insert("garbage-collection", garbage_collection_commands()) .insert("acme", acme_mgmt_cli()) diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs index 21004bbe..a3a16246 100644 --- a/src/bin/proxmox_backup_manager/mod.rs +++ b/src/bin/proxmox_backup_manager/mod.rs @@ -24,3 +24,5 @@ mod disk; pub use disk::*; mod node; pub use node::*; +mod openid; +pub use openid::*; diff --git a/src/bin/proxmox_backup_manager/openid.rs b/src/bin/proxmox_backup_manager/openid.rs new file mode 100644 index 00000000..13915339 --- /dev/null +++ b/src/bin/proxmox_backup_manager/openid.rs @@ -0,0 +1,99 @@ +use anyhow::Error; +use serde_json::Value; + +use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; + +use proxmox_backup::{config, api2, api2::types::REALM_ID_SCHEMA}; + + +#[api( + input: { + properties: { + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// List configured OpenId realms +fn list_openid_realms(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + + let output_format = get_output_format(¶m); + + let info = &api2::config::access::openid::API_METHOD_LIST_OPENID_REALMS; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + let options = default_table_format_options() + .column(ColumnConfig::new("realm")) + .column(ColumnConfig::new("issuer-url")) + .column(ColumnConfig::new("comment")); + + format_and_print_result_full(&mut data, &info.returns, &output_format, &options); + + Ok(Value::Null) +} +#[api( + input: { + properties: { + realm: { + schema: REALM_ID_SCHEMA, + }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] + +/// Show OpenID realm configuration +fn show_openid_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + + let output_format = get_output_format(¶m); + + let info = &api2::config::access::openid::API_METHOD_READ_OPENID_REALM; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + let options = default_table_format_options(); + format_and_print_result_full(&mut data, &info.returns, &output_format, &options); + + Ok(Value::Null) +} + +pub fn openid_commands() -> CommandLineInterface { + + let cmd_def = CliCommandMap::new() + .insert("list", CliCommand::new(&&API_METHOD_LIST_OPENID_REALMS)) + .insert("show", CliCommand::new(&&API_METHOD_SHOW_OPENID_REALM) + .arg_param(&["realm"]) + .completion_cb("realm", config::domains::complete_openid_realm_name) + ) + .insert("create", + CliCommand::new(&api2::config::access::openid::API_METHOD_CREATE_OPENID_REALM) + .arg_param(&["realm"]) + .arg_param(&["realm"]) + .completion_cb("realm", config::domains::complete_openid_realm_name) + ) + .insert("update", + CliCommand::new(&api2::config::access::openid::API_METHOD_UPDATE_OPENID_REALM) + .arg_param(&["realm"]) + .arg_param(&["realm"]) + .completion_cb("realm", config::domains::complete_openid_realm_name) + ) + .insert("delete", + CliCommand::new(&api2::config::access::openid::API_METHOD_DELETE_OPENID_REALM) + .arg_param(&["realm"]) + .arg_param(&["realm"]) + .completion_cb("realm", config::domains::complete_openid_realm_name) + ) + ; + + cmd_def.into() +} diff --git a/src/config/domains.rs b/src/config/domains.rs index ee6fd754..ce3f6f23 100644 --- a/src/config/domains.rs +++ b/src/config/domains.rs @@ -120,3 +120,12 @@ pub fn complete_realm_name(_arg: &str, _param: &HashMap) -> Vec< Err(_) => return vec![], } } + +pub fn complete_openid_realm_name(_arg: &str, _param: &HashMap) -> Vec { + match config() { + Ok((data, _digest)) => data.sections.iter() + .filter_map(|(id, (t, _))| if t == "openid" { Some(id.to_string()) } else { None }) + .collect(), + Err(_) => return vec![], + } +} -- 2.30.2