]>
git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Config.pm
65c555fdc21a7dd6a8058d13617efd1e1a0eb1c8
1 package PVE
::APIClient
::Config
;
7 use PVE
::JSONSchema
qw(register_standard_option get_standard_option);
8 use PVE
::SectionConfig
;
9 use PVE
::Tools
qw(file_get_contents file_set_contents);
11 use base
qw(PVE::SectionConfig);
13 my $complete_remote_name = sub {
15 my $config = PVE
::APIClient
::Config-
>load();
16 return [keys %{$config->{ids
}}];
19 register_standard_option
('pveclient-remote-name', {
20 description
=> "The name of the remote.",
23 completion
=> $complete_remote_name,
30 description
=> "Section type.",
33 name
=> get_standard_option
('pveclient-remote-name'),
35 description
=> "The host.",
36 type
=> 'string', format
=> 'address',
40 description
=> "The username.",
45 description
=> "The users password.",
50 description
=> "The port.",
56 description
=> "Fingerprint.",
61 description
=> "Description.",
75 name
=> { optional
=> 0 },
76 host
=> { optional
=> 0 },
77 comment
=> { optional
=> 1 },
78 username
=> { optional
=> 0 },
79 password
=> { optional
=> 0 },
80 port
=> { optional
=> 1 },
81 fingerprint
=> { optional
=> 1 },
92 my $home = $ENV{HOME
};
94 die "environment HOME not set\n" if !defined($home);
96 return "$home/.pveclient";
102 my $filename = $class->config_filename();
107 my $filemode = (stat($filename))[2] & 07777;
108 if ($filemode != 0600) {
109 die sprintf "wrong permissions on '$filename' %04o (expected 0600)\n", $filemode;
112 $raw = file_get_contents
($filename);
115 return $class->parse_config($filename, $raw);
119 my ($class, $cfg) = @_;
121 my $filename = $class->config_filename();
122 my $raw = $class->write_config($filename, $cfg);
124 file_set_contents
($filename, $raw, 0600);
128 my ($class, $cfg, $name, $noerr) = @_;
130 my $data = $cfg->{ids
}->{$name};
132 return $data if $noerr || defined($data);
134 die "unknown remote \"$name\"\n";
138 my ($class, $cfg, $remote) = @_;
140 my $section = $class->lookup_remote($cfg, $remote);
141 my $conn = PVE::APIClient::LWP->new(
142 username => $section->{username},
143 password => $section->{password},
144 host => $section->{host},
145 port => $section->{port},
146 cached_fingerprints => {
147 $section->{fingerprint} => 1,
156 __PACKAGE__->register();