]>
git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Config.pm
1 package PVE
::APIClient
::Config
;
8 use PVE
::JSONSchema
qw(register_standard_option get_standard_option);
9 use PVE
::SectionConfig
;
10 use PVE
::Tools
qw(file_get_contents file_set_contents);
12 use base
qw(PVE::SectionConfig);
14 my $complete_remote_name = sub {
16 my $config = PVE
::APIClient
::Config-
>load();
17 return [keys %{$config->{ids
}}];
20 register_standard_option
('pveclient-remote-name', {
21 description
=> "The name of the remote.",
24 completion
=> $complete_remote_name,
31 description
=> "Section type.",
34 name
=> get_standard_option
('pveclient-remote-name'),
36 description
=> "The host.",
37 type
=> 'string', format
=> 'address',
41 description
=> "The username.",
46 description
=> "The users password.",
51 description
=> "The port.",
57 description
=> "Fingerprint.",
62 description
=> "Description.",
76 name
=> { optional
=> 0 },
77 host
=> { optional
=> 0 },
78 comment
=> { optional
=> 1 },
79 username
=> { optional
=> 0 },
80 password
=> { optional
=> 0 },
81 port
=> { optional
=> 1 },
82 fingerprint
=> { optional
=> 1 },
93 return File
::HomeDir
::home
() . '/.pveclient';
99 my $filename = $class->config_filename();
104 my $filemode = (stat($filename))[2] & 07777;
105 if ($filemode != 0600) {
106 die sprintf "wrong permissions on '$filename' %04o (expected 0600)\n", $filemode;
109 $raw = file_get_contents
($filename);
112 return $class->parse_config($filename, $raw);
116 my ($class, $cfg) = @_;
118 my $filename = $class->config_filename();
119 my $raw = $class->write_config($filename, $cfg);
121 file_set_contents
($filename, $raw, 0600);
125 my ($class, $cfg, $name, $noerr) = @_;
127 my $data = $cfg->{ids
}->{$name};
129 return $data if $noerr || defined($data);
131 die "unknown remote \"$name\"\n";
135 my ($class, $cfg, $remote) = @_;
137 my $section = $class->lookup_remote($cfg, $remote);
138 my $conn = PVE::APIClient::LWP->new(
139 username => $section->{username},
140 password => $section->{password},
141 host => $section->{host},
142 port => $section->{port},
143 cached_fingerprints => {
144 $section->{fingerprint} => 1,
153 __PACKAGE__->register();