Commit bb80d33e authored by Armon Dadgar's avatar Armon Dadgar
Browse files

agent: thread ACLs for Job Register

parent efe7fe89
Showing with 42 additions and 1 deletion
+42 -1
......@@ -41,6 +41,9 @@ type QueryOptions struct {
// Set HTTP parameters on the query.
Params map[string]string
// SecretID is the secret ID of an ACL token
SecretID string
}
// WriteOptions are used to parameterize a write
......@@ -48,6 +51,9 @@ type WriteOptions struct {
// Providing a datacenter overwrites the region provided
// by the Config
Region string
// SecretID is the secret ID of an ACL token
SecretID string
}
// QueryMeta is used to return meta data about a query
......
......@@ -692,6 +692,9 @@ func (j *Job) AddPeriodicConfig(cfg *PeriodicConfig) *Job {
type WriteRequest struct {
// The target region for this write
Region string
// SecretID is the secret ID of an ACL token
SecretID string
}
// JobValidateRequest is used to validate a job
......
......@@ -349,6 +349,7 @@ func (s *HTTPServer) jobUpdate(resp http.ResponseWriter, req *http.Request,
return nil, CodedError(400, "Job ID does not match name")
}
s.parseRegion(req, &args.Region)
s.parseToken(req, &args.SecretID)
sJob := ApiJobToStructJob(args.Job)
......@@ -357,7 +358,8 @@ func (s *HTTPServer) jobUpdate(resp http.ResponseWriter, req *http.Request,
EnforceIndex: args.EnforceIndex,
JobModifyIndex: args.JobModifyIndex,
WriteRequest: structs.WriteRequest{
Region: args.WriteRequest.Region,
Region: args.WriteRequest.Region,
SecretID: args.WriteRequest.SecretID,
},
}
var out structs.JobRegisterResponse
......
......@@ -171,6 +171,36 @@ func TestHTTP_JobsRegister(t *testing.T) {
})
}
func TestHTTP_JobsRegister_ACL(t *testing.T) {
t.Parallel()
httpACLTest(t, nil, func(s *TestAgent) {
// Create the job
job := api.MockJob()
args := api.JobRegisterRequest{
Job: job,
WriteRequest: api.WriteRequest{
Region: "global",
},
}
buf := encodeReq(args)
// Make the HTTP request
req, err := http.NewRequest("PUT", "/v1/jobs", buf)
if err != nil {
t.Fatalf("err: %v", err)
}
respW := httptest.NewRecorder()
setToken(req, s.Token)
// Make the request
obj, err := s.Server.JobsRequest(respW, req)
if err != nil {
t.Fatalf("err: %v", err)
}
assert.NotNil(t, obj)
})
}
func TestHTTP_JobsRegister_Defaulting(t *testing.T) {
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment