]> git.proxmox.com Git - pve-client.git/commitdiff
PVE/APIClient/Config.pm: new class to handle configuration file
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 29 May 2018 07:18:26 +0000 (09:18 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 29 May 2018 07:18:26 +0000 (09:18 +0200)
PVE/APIClient/Config.pm [new file with mode: 0644]

diff --git a/PVE/APIClient/Config.pm b/PVE/APIClient/Config.pm
new file mode 100644 (file)
index 0000000..86007d2
--- /dev/null
@@ -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;