]>
git.proxmox.com Git - pmg-api.git/blob - PMG/API2/Domains.pm
1 package PMG
::API2
::Domains
;
8 use PVE
::Tools
qw(extract_param);
9 use PVE
::JSONSchema
qw(get_standard_option);
15 use base
qw(PVE::RESTHandler);
17 __PACKAGE__-
>register_method ({
21 description
=> "List relay domains.",
22 permissions
=> { check
=> [ 'admin', 'audit' ] },
25 additionalProperties
=> 0,
33 domain
=> { type
=> 'string'},
34 comment
=> { type
=> 'string'},
37 links
=> [ { rel
=> 'child', href
=> "{domain}" } ],
42 my $domains = PVE
::INotify
::read_file
('domains');
46 foreach my $domain (sort keys %$domains) {
47 push @$res, $domains->{$domain};
53 __PACKAGE__-
>register_method ({
59 permissions
=> { check
=> [ 'admin' ] },
60 description
=> "Add relay domain.",
62 additionalProperties
=> 0,
65 description
=> "Domain name.",
66 type
=> 'string', format
=> 'transport-domain',
69 description
=> "Comment.",
75 returns
=> { type
=> 'null' },
81 my $domains = PVE
::INotify
::read_file
('domains');
83 die "Domain '$param->{domain}' already exists\n"
84 if $domains->{$param->{domain
}};
86 $domains->{$param->{domain
}} = {
87 comment
=> $param->{comment
} // '',
90 PVE
::INotify
::write_file
('domains', $domains);
92 PMG
::Config
::postmap_pmg_domains
();
95 PMG
::Config
::lock_config
($code, "add relay domain failed");
100 __PACKAGE__-
>register_method ({
104 description
=> "Read Domain data (comment).",
106 permissions
=> { check
=> [ 'admin', 'audit' ] },
108 additionalProperties
=> 0,
111 description
=> "Domain name.",
112 type
=> 'string', format
=> 'transport-domain',
119 domain
=> { type
=> 'string'},
120 comment
=> { type
=> 'string'},
126 my $domains = PVE
::INotify
::read_file
('domains');
128 die "Domain '$param->{domain}' does not exist\n"
129 if !$domains->{$param->{domain
}};
131 return $domains->{$param->{domain
}};
134 __PACKAGE__-
>register_method ({
138 description
=> "Update relay domain data (comment).",
140 permissions
=> { check
=> [ 'admin' ] },
143 additionalProperties
=> 0,
146 description
=> "Domain name.",
147 type
=> 'string', format
=> 'transport-domain',
150 description
=> "Comment.",
155 returns
=> { type
=> 'null' },
161 my $domains = PVE
::INotify
::read_file
('domains');
163 die "Domain '$param->{domain}' does not exist\n"
164 if !$domains->{$param->{domain
}};
166 $domains->{$param->{domain
}}->{comment
} = $param->{comment
};
168 PVE
::INotify
::write_file
('domains', $domains);
170 PMG
::Config
::postmap_pmg_domains
();
173 PMG
::Config
::lock_config
($code, "update relay domain failed");
178 __PACKAGE__-
>register_method ({
182 description
=> "Delete a relay domain",
184 permissions
=> { check
=> [ 'admin' ] },
187 additionalProperties
=> 0,
190 description
=> "Domain name.",
191 type
=> 'string', format
=> 'transport-domain',
195 returns
=> { type
=> 'null' },
201 my $domains = PVE
::INotify
::read_file
('domains');
203 die "Domain '$param->{domain}' does not exist\n"
204 if !$domains->{$param->{domain
}};
206 delete $domains->{$param->{domain
}};
208 PVE
::INotify
::write_file
('domains', $domains);
210 PMG
::Config
::postmap_pmg_domains
();
213 PMG
::Config
::lock_config
($code, "delete relay domain failed");