[pve-devel] [PATCH common 1/1] tools: add extract_sensitive_params
Dominik Csapak
d.csapak at proxmox.com
Wed Dec 2 10:21:04 CET 2020
moved and generalized from pve-storage, since we'll need it
in more places
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/PVE/Tools.pm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 4b445ea..bda236a 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -48,6 +48,7 @@ template_replace
safe_print
trim
extract_param
+extract_sensitive_params
file_copy
get_host_arch
O_PATH
@@ -807,6 +808,29 @@ sub extract_param {
return $res;
}
+sub extract_sensitive_params :prototype($$$) {
+ my ($param, $sensitive_list, $delete_list) = @_;
+
+ my $sensitive;
+
+ my %delete = map { $_ => 1 } ($delete_list || [])->@*;
+
+ # always extract sensitive keys, so they don't get written to the www-data readable scfg
+ for my $opt (@$sensitive_list) {
+ # First handle deletions as explicitly setting `undef`, afterwards new values may override
+ # it.
+ if (exists($delete{$opt})) {
+ $sensitive->{$opt} = undef;
+ }
+
+ if (defined(my $value = extract_param($param, $opt))) {
+ $sensitive->{$opt} = $value;
+ }
+ }
+
+ return $sensitive;
+}
+
# Note: we use this to wait until vncterm/spiceterm is ready
sub wait_for_vnc_port {
my ($port, $family, $timeout) = @_;
--
2.20.1
More information about the pve-devel
mailing list