Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #873 from joyent/ether/v2-relay-delete
Browse files Browse the repository at this point in the history
add DELETE /relay/:serial
  • Loading branch information
karenetheridge authored Aug 27, 2019
2 parents 9b5571c + a562681 commit 25d75d6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/modules/Conch::Controller::Relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ If the user is a system admin, retrieve a list of all active relays in the datab

Response uses the Relays json schema.

## delete

# LICENSING

Copyright Joyent, Inc.
Expand Down
5 changes: 5 additions & 0 deletions docs/modules/Conch::Route::Relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Unless otherwise noted, all routes require authentication.
- Requires System Admin Authentication
- Response: response.yaml#/Relays

## `DELETE /relay/:relay_serial_number`

- Requires system admin authorization
- Response: `204 NO CONTENT`

# LICENSING

Copyright Joyent, Inc.
Expand Down
22 changes: 22 additions & 0 deletions lib/Conch/Controller/Relay.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ sub list ($c) {
$c->status(200, [ $c->db_relays->active->all ]);
}

=head2 delete
=cut

sub delete ($c) {
my $identifier = $c->stash('relay_serial_number');

my $rs = $c->db_relays
->active
->search({ id => $identifier });
return $c->status(404) if not $rs->exists;

my $drc_count = $rs->related_resultset('device_relay_connections')->delete;
my $urc_count = $rs->related_resultset('user_relay_connections')->delete;
$rs->deactivate;

$c->log->debug('Deactivated relay '.$identifier
.', removing '.$drc_count.' associated device connections and '
.$urc_count.' associated user connections');
return $c->status(204);
}

1;
__END__
Expand Down
13 changes: 13 additions & 0 deletions lib/Conch/Route/Relay.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ sub routes {

# GET /relay
$relay->get('/')->to('#list');

# DELETE /relay/:relay_serial_number
$relay->require_system_admin->delete('/:relay_serial_number')->to('#delete');
}

1;
Expand Down Expand Up @@ -60,6 +63,16 @@ Unless otherwise noted, all routes require authentication.
=cut
=head2 C<DELETE /relay/:relay_serial_number>
=over 4
=item * Requires system admin authorization
=item * Response: C<204 NO CONTENT>
=back
=head1 LICENSING
Copyright Joyent, Inc.
Expand Down
19 changes: 19 additions & 0 deletions t/integration/crud/relay.t
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,24 @@ subtest get_relay_devices => sub {
]);
};

subtest delete => sub {
$t->authenticate(user => $t->load_fixture('null_user')->email);

$t->delete_ok('/relay/'.$relay0->id)
->status_is(403);

$t->authenticate; # back to superuser

$t->delete_ok('/relay/'.$relay0->id)
->status_is(204)
->log_debug_is('Deactivated relay '.$relay0->id.', removing 2 associated device connections and 1 associated user connections');

$t->get_ok('/relay/'.$relay0->id)
->status_is(404);

$t->delete_ok('/relay/'.$relay0->id)
->status_is(404);
};

done_testing;
# vim: set ts=4 sts=4 sw=4 et :

0 comments on commit 25d75d6

Please sign in to comment.