mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
agent: thread ACLs for Job Register
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -729,6 +729,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) {
|
||||
|
||||
Reference in New Issue
Block a user