From a31c7b279b49979da981d2dc36b9f93d6f3b4f93 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 29 May 2018 09:18:26 +0200 Subject: [PATCH] PVE/APIClient/Config.pm: new class to handle configuration file --- PVE/APIClient/Config.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 PVE/APIClient/Config.pm diff --git a/PVE/APIClient/Config.pm b/PVE/APIClient/Config.pm new file mode 100644 index 0000000..86007d2 --- /dev/null +++ b/PVE/APIClient/Config.pm @@ -0,0 +1,23 @@ +package PVE::APIClient::Config; + +use strict; +use warnings; +use JSON; +use File::HomeDir; + +use PVE::Tools; + +sub load_config { + + my $filename = home() . '/.pveclient'; + my $conf_str = PVE::Tools::file_get_contents($filename); + + my $filemode = (stat($filename))[2] & 07777; + if ($filemode != 0600) { + die sprintf "wrong permissions on '$filename' %04o (expected 0600)\n", $filemode; + } + + return decode_json($conf_str); +}; + +1; -- 2.39.2