-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Nomad Job Dispatch - Payload via HTTP request body #24312
Comments
Heya, thanks for the suggestion! I agree this would be a nifty enhancement for dispatch jobs, especially for the webhook use case you describe. I think a patch like this might be sufficientdiff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go
index 4eba764fbe..a5979bbfee 100644
--- a/command/agent/job_endpoint.go
+++ b/command/agent/job_endpoint.go
@@ -5,6 +5,7 @@ package agent
import (
"fmt"
+ "io"
"maps"
"net/http"
"slices"
@@ -876,8 +877,17 @@ func (s *HTTPServer) jobDispatchRequest(resp http.ResponseWriter, req *http.Requ
return nil, CodedError(405, ErrInvalidMethod)
}
args := structs.JobDispatchRequest{}
- if err := decodeBody(req, &args); err != nil {
- return nil, CodedError(400, err.Error())
+ var err error
+ payloadAsBody := req.URL.Query().Get("payloadAsBody")
+ if payloadAsBody != "" { // TODO: boolean
+ args.Payload, err = io.ReadAll(req.Body)
+ if err != nil {
+ return nil, CodedError(400, err.Error())
+ }
+ } else {
+ if err = decodeBody(req, &args); err != nil {
+ return nil, CodedError(400, err.Error())
+ }
}
if args.JobID != "" && args.JobID != jobID {
return nil, CodedError(400, "Job ID does not match") but we'll need to bounce it around internally a bit. I'll get it in the queue for consideration. Thanks again! |
We kicked it around over here, and instead of a query argument toggling the behavior on this API, we can provide a new endpoint: Have a look at the PR if you'd like to confirm this suits your use case. Thanks again for the suggestion! |
Thank you for your quick reply and hard work! I gave the PR a thorough glance (i.e., without building it) and it looks like everything we had hoped for. Awesome! |
Proposal
The ability to send the job payload as the http request body, instead of having to base64-encode it.
That would allow support for something like this:
Use-cases
Some external systems support 'webhooks', but don't allow for much control over the contents of the request body. These bodies usually contain information on the event or the changed entity, but do not allow us to specify "put that information in a
Payload
object and base64-encode everything". This makes it difficult to use Nomad's dispatch-job as a webhook handler.It would be nice to be able to tell Nomad (via a query parameter or a HTTP header) to interpret the entire HTTP request body as the raw payload.
Attempted Solutions
The text was updated successfully, but these errors were encountered: