From aa62f96b41657a30458ccd5e924fed90936f8bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Tue, 27 Aug 2024 17:34:48 +0200 Subject: [PATCH] api: Require POST for /api/push --- hydra-api.yaml | 2 +- src/lib/Hydra/Controller/API.pm | 2 ++ src/lib/Hydra/Helper/CatalystUtils.pm | 2 +- src/root/jobset.tt | 1 + t/Hydra/Controller/API/checks.t | 4 ++-- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hydra-api.yaml b/hydra-api.yaml index 623c90823..a2fdea28b 100644 --- a/hydra-api.yaml +++ b/hydra-api.yaml @@ -70,7 +70,7 @@ paths: $ref: '#/components/examples/projects-success' /api/push: - put: + post: summary: trigger jobsets parameters: - in: query diff --git a/src/lib/Hydra/Controller/API.pm b/src/lib/Hydra/Controller/API.pm index a8b4440ee..9f8b7cba2 100644 --- a/src/lib/Hydra/Controller/API.pm +++ b/src/lib/Hydra/Controller/API.pm @@ -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}; diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 8c33c3d83..488c2b59f 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -293,7 +293,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"; } diff --git a/src/root/jobset.tt b/src/root/jobset.tt index 56abdb505..5d8345f9f 100644 --- a/src/root/jobset.tt +++ b/src/root/jobset.tt @@ -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."); } diff --git a/t/Hydra/Controller/API/checks.t b/t/Hydra/Controller/API/checks.t index 2b97b4895..f0f51f1cf 100644 --- a/t/Hydra/Controller/API/checks.t +++ b/t/Hydra/Controller/API/checks.t @@ -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); @@ -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);