From: Dietmar Maurer Date: Tue, 29 May 2018 07:18:26 +0000 (+0200) Subject: PVE/APIClient/Config.pm: new class to handle configuration file X-Git-Url: https://git.proxmox.com/?p=pve-client.git;a=commitdiff_plain;h=a31c7b279b49979da981d2dc36b9f93d6f3b4f93;ds=sidebyside PVE/APIClient/Config.pm: new class to handle configuration file --- 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;