]>
git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Config.pm
1 package PVE
::APIClient
::Config
;
8 use PVE
::Tools
qw(file_get_contents file_set_contents);
14 file
=> File
::HomeDir
::home
() . '/.pveclient',
16 bless $self => $class;
26 if (-e
$self->{file
}) {
27 my $filemode = (stat($self->{file
}))[2] & 07777;
28 if ($filemode != 0600) {
29 die sprintf "wrong permissions on '$self->{file}' %04o (expected 0600)\n", $filemode;
32 my $contents = file_get_contents
($self->{file
});
33 $self->{data
} = from_json
($contents);
38 if (!exists($self->{data
}->{remotes
})) {
39 $self->{data
}->{remotes
} = {};
43 for my $name (@{$self->remote_names}) {
44 my $cfg = $self->{data
}->{remotes
}->{$name};
46 foreach my $opt (qw(host port username fingerprint)) {
47 die "missing option '$opt' (remote '$name')" if !defined($cfg->{$opt});
55 my $contents = to_json
($self->{data
}, {pretty
=> 1, canonical
=> 1});
56 file_set_contents
($self->{file
}, $contents, 0600);
60 my ($self, $name, $host, $port, $fingerprint, $username, $password) = @_;
62 $self->{data
}->{remotes
}->{$name} = {
65 fingerprint
=> $fingerprint,
66 username
=> $username,
69 if (defined($password)) {
70 $self->{data
}->{remotes
}->{$name}->{password
} = $password;
77 return [keys %{$self->{data
}->{remotes
}}];
81 my ($self, $name) = @_;
83 die "Unknown remote \"$name\" given"
84 if (!exists($self->{data}->{remotes}->{$name}));
86 return $self->{data}->{remotes}->{$name};
94 # Remove the password from each remote.
95 for my $name ($self->remote_names) {
96 my $cfg = $self->{data}->{remotes}->{$name};
100 username => $cfg->{username},
101 fingerprint => $cfg->{fingerprint},
109 my ($self, $remote) = @_;
111 $self->lookup_remote($remote);
113 delete($self->{data}->{remotes}->{$remote});
119 my ($self, $remote) = @_;
121 my $section = $self->lookup_remote($remote);
122 my $conn = PVE::APIClient::LWP->new(
123 username => $section->{username},
124 password => $section->{password},
125 host => $section->{host},
126 port => $section->{port},
127 cached_fingerprints => {
128 $section->{fingerprint} => 1,