TT#88901 - Add GET and DELETE method for /api/admincerts

* the GET request will show whether an admin
	   has or has not a certificate
	 * the DELETE request will remove an admin's
	   certificate

Change-Id: I2b233a76a4436a4d3a95749410e74aabd9fca531
mr9.0
Flaviu Mates 5 years ago
parent 12ad4079a8
commit 444a0d35b3

@ -13,7 +13,7 @@ sub config_allowed_roles {
}
sub allowed_methods {
return [qw/POST OPTIONS HEAD/];
return [qw/GET POST OPTIONS HEAD/];
}
sub api_description {

@ -0,0 +1,38 @@
package NGCP::Panel::Controller::API::AdminCertsItem;
use parent qw/NGCP::Panel::Role::EntitiesItem NGCP::Panel::Role::API::AdminCerts/;
use Sipwise::Base;
use HTTP::Status qw(:constants);
__PACKAGE__->set_config();
sub allowed_methods {
return [qw/GET OPTIONS HEAD DELETE/];
}
sub delete_item {
my($self, $c, $item, $old_resource, $resource, $form) = @_;
unless ($item->id == $c->user->id) {
$c->log->error("Administrator can only delete its own certificate.");
$self->error($c, HTTP_FORBIDDEN, "Administrator can only delete its own certificate.");
return;
}
try {
$item->update({
ssl_client_m_serial => undef,
ssl_client_certificate => undef,
});
} catch($e) {
$c->log->error("failed to delete administrator certificate: $e");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to delete administrator certificate.");
return;
}
return 1;
}
1;
# vim: set tabstop=4 expandtab:

@ -35,5 +35,11 @@ sub _item_rs {
return $item_rs;
}
sub post_process_hal_resource {
my ($self, $c, $item, $resource, $form) = @_;
my $res = { has_certificate => $item->ssl_client_m_serial ? 1 : 0 };
return $res;
}
1;
# vim: set tabstop=4 expandtab:

Loading…
Cancel
Save