]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/API2/DestinationTLSPolicy.pm
1 package PMG
::API2
::DestinationTLSPolicy
;
8 use PVE
::Exception
qw(raise_param_exc);
12 use base
qw(PVE::RESTHandler);
14 __PACKAGE__-
>register_method ({
18 description
=> "List tls_policy entries.",
20 permissions
=> { check
=> [ 'admin', 'audit' ] },
22 additionalProperties
=> 0,
30 domain
=> { type
=> 'string', format
=> 'transport-domain'},
31 policy
=> { type
=> 'string', format
=> 'tls-policy'},
34 links
=> [ { rel
=> 'child', href
=> "{domain}" } ],
41 my $policies = PVE
::INotify
::read_file
('tls_policy');
42 foreach my $policy (sort keys %$policies) {
43 push @$res, $policies->{$policy};
49 __PACKAGE__-
>register_method ({
55 permissions
=> { check
=> [ 'admin' ] },
56 description
=> "Add tls_policy entry.",
58 additionalProperties
=> 0,
61 description
=> "Domain name.",
62 type
=> 'string', format
=> 'transport-domain',
65 description
=> "TLS policy",
66 type
=> 'string', format
=> 'tls-policy-strict',
70 returns
=> { type
=> 'null' },
73 my $domain = $param->{domain
};
74 my $policy = $param->{policy
};
77 my $tls_policy = PVE
::INotify
::read_file
('tls_policy');
78 raise_param_exc
({ domain
=> "DestinationTLSPolicy entry for '$domain' already exists" })
79 if $tls_policy->{$domain};
81 $tls_policy->{$domain} = {
83 policy
=> $param->{policy
},
86 PVE
::INotify
::write_file
('tls_policy', $tls_policy);
87 PMG
::Config
::postmap_tls_policy
();
90 PMG
::Config
::lock_config
($code, "add tls_policy entry failed");
95 __PACKAGE__-
>register_method ({
99 description
=> "Read tls_policy entry.",
101 permissions
=> { check
=> [ 'admin', 'audit' ] },
103 additionalProperties
=> 0,
106 description
=> "Domain name.",
107 type
=> 'string', format
=> 'transport-domain',
114 domain
=> { type
=> 'string', format
=> 'transport-domain'},
115 policy
=> { type
=> 'string', format
=> 'tls-policy'},
120 my $domain = $param->{domain
};
122 my $tls_policy = PVE
::INotify
::read_file
('tls_policy');
124 if (my $entry = $tls_policy->{$domain}) {
128 raise_param_exc
({ domain
=> "DestinationTLSPolicy entry for '$domain' does not exist" });
131 __PACKAGE__-
>register_method ({
135 description
=> "Update tls_policy entry.",
137 permissions
=> { check
=> [ 'admin' ] },
140 additionalProperties
=> 0,
143 description
=> "Domain name.",
144 type
=> 'string', format
=> 'transport-domain',
147 description
=> "TLS policy",
148 type
=> 'string', format
=> 'tls-policy-strict',
152 returns
=> { type
=> 'null' },
155 my $domain = $param->{domain
};
156 my $policy = $param->{policy
};
160 my $tls_policy = PVE
::INotify
::read_file
('tls_policy');
162 raise_param_exc
({ domain
=> "DestinationTLSPolicy entry for '$domain' does not exist" })
163 if !$tls_policy->{$domain};
165 $tls_policy->{$domain}->{policy
} = $policy;
167 PVE
::INotify
::write_file
('tls_policy', $tls_policy);
168 PMG
::Config
::postmap_tls_policy
();
171 PMG
::Config
::lock_config
($code, "update tls_policy entry failed");
176 __PACKAGE__-
>register_method ({
180 description
=> "Delete a tls_policy entry",
182 permissions
=> { check
=> [ 'admin' ] },
185 additionalProperties
=> 0,
188 description
=> "Domain name.",
189 type
=> 'string', format
=> 'transport-domain',
193 returns
=> { type
=> 'null' },
196 my $domain = $param->{domain
};
199 my $tls_policy = PVE
::INotify
::read_file
('tls_policy');
201 raise_param_exc
({ domain
=> "DestinationTLSPolicy entry for '$domain' does not exist" })
202 if !$tls_policy->{$domain};
204 delete $tls_policy->{$domain};
206 PVE
::INotify
::write_file
('tls_policy', $tls_policy);
207 PMG
::Config
::postmap_tls_policy
();
210 PMG
::Config
::lock_config
($code, "delete tls_policy entry failed");