Skip to content

Commit

Permalink
api: Require POST for /api/push
Browse files Browse the repository at this point in the history
  • Loading branch information
dasJ authored and mweinelt committed Aug 27, 2024
1 parent 3d33615 commit c928018
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hydra-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ paths:
$ref: '#/components/examples/projects-success'

/api/push:
put:
post:
summary: trigger jobsets
parameters:
- in: query
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Hydra/Controller/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ sub triggerJobset {
sub push : Chained('api') PathPart('push') Args(0) {
my ($self, $c) = @_;

requirePost($c);

$c->{stash}->{json}->{jobsetsTriggered} = [];

my $force = exists $c->request->query_params->{force};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Hydra/Helper/CatalystUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ sub requireAdmin {

sub requirePost {
my ($c) = @_;
error($c, "Request must be POSTed.") if $c->request->method ne "POST";
error($c, "Request must be POSTed.", 405) if $c->request->method ne "POST";
}


Expand Down
1 change: 1 addition & 0 deletions src/root/jobset.tt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
if (!c) return;
requestJSON({
url: "[% HTML.escape(c.uri_for('/api/push', { jobsets = project.name _ ':' _ jobset.name, force = "1" })) %]",
type: 'POST',
success: function(data) {
bootbox.alert("The jobset has been scheduled for evaluation.");
}
Expand Down
4 changes: 2 additions & 2 deletions t/Hydra/Controller/API/checks.t
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ subtest "/api/push" => sub {
my $jobsetName = $jobset->name;
is($jobset->forceeval, undef, "The existing jobset is not set to be forced to eval");

my $response = request(GET "/api/push?jobsets=$projectName:$jobsetName&force=1");
my $response = request(POST "/api/push?jobsets=$projectName:$jobsetName&force=1");
ok($response->is_success, "The API enpdoint for triggering jobsets returns 200.");

my $data = is_json($response);
Expand All @@ -128,7 +128,7 @@ subtest "/api/push" => sub {

print STDERR $repo;

my $response = request(GET "/api/push?repos=$repo&force=1");
my $response = request(POST "/api/push?repos=$repo&force=1");
ok($response->is_success, "The API enpdoint for triggering jobsets returns 200.");

my $data = is_json($response);
Expand Down

0 comments on commit c928018

Please sign in to comment.