Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete domain command #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ run
testrun
coverrun

/nbproject/private/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ For the 'CAS' API system to work properly, the system expects the
transaction isolation level of MySQL to be 'REPEATABLE READ' (this is
the default).



## New Command Implementation - Delete domain

example curl -X DELETE -u username:password http://apidomain/api/domain/:id
3 changes: 2 additions & 1 deletion lib/PowerDNS/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sub startup {
['domain/*domain' => 'POST' => 'post_domain'],
['domain/*domain' => 'GET' => 'get_domain'],
['domain/*domain' => 'PUT' => 'put_domain'],
['domain/*id' => 'DELETE' => 'delete_domain'],

['record/*domain' => 'POST' => 'post_record'],
['record/*domain/*id' => 'PUT' => 'put_record'],
Expand Down Expand Up @@ -89,4 +90,4 @@ Copyright 2011-2012 Ask Bjørn Hansen, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut
=cut
27 changes: 26 additions & 1 deletion lib/PowerDNS/API/Handler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,31 @@ sub post_domain {
return $self->render_json({ domain => $domain });
}

sub delete_domain {
my $self = shift;

my $account = $self->stash('account') or die $self->render_error(401, 'unauthorized');

my $domain_id = $self->stash('id') or die $self->render_error(400, 'no domain id');

my $txn = $self->schema->txn_scope_guard;

my $domain = $self->schema->domain->find({ id => $domain_id }, { for => 'update' })
or die $self->render_error("domain not found", 404);

die $self->render_error(401, "unauthorized")
unless $account->has_access($domain);

$self->_check_cas($domain);


$domain->delete;

$txn->commit;

return $self->render_json({ message => "domain deleted"}, 205)
}

sub put_record {
my $self = shift;

Expand Down Expand Up @@ -308,4 +333,4 @@ sub delete_record {

}

1;
1;