agent/handlers/v1/task_container_metadata_handler.go
func TaskContainerMetadataHandler(taskEngine utils.DockerStateResolver) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		var responseJSON []byte
		dockerTaskEngineState := taskEngine.State()
		dockerID, dockerIDExists := utils.ValueFromRequest(r, dockerIDQueryField)
		taskArn, taskARNExists := utils.ValueFromRequest(r, taskARNQueryField)
		var status int
		if dockerIDExists && taskARNExists {
			seelog.Info("Request contains both ", dockerIDQueryField, " and ", taskARNQueryField, ". Expect at most one of these.")
			w.WriteHeader(http.StatusBadRequest)
			w.Write(responseJSON)
			return
		}
		if dockerIDExists {
			// Create TaskResponse for the docker id in the query.
			var task *apitask.Task
			var found bool
			if len(dockerID) > dockerShortIDLen {
				task, found = dockerTaskEngineState.TaskByID(dockerID)
			} else {
				tasks, _ := dockerTaskEngineState.TaskByShortID(dockerID)
				if len(tasks) == 0 {
					task = nil
					found = false
				} else if len(tasks) == 1 {
					task = tasks[0]
					found = true
				} else {
					seelog.Info("Multiple tasks found for requested dockerId: " + dockerID)
					w.WriteHeader(http.StatusBadRequest)
					w.Write(responseJSON)
					return
				}
			}
			responseJSON, status = createTaskResponse(task, found, dockerID, dockerTaskEngineState)
			w.WriteHeader(status)
		} else if taskARNExists {
			// Create TaskResponse for the task arn in the query.
			task, found := dockerTaskEngineState.TaskByArn(taskArn)
			responseJSON, status = createTaskResponse(task, found, taskArn, dockerTaskEngineState)
			w.WriteHeader(status)
		} else {
			// List all tasks.
			responseJSON, _ = json.Marshal(NewTasksResponse(dockerTaskEngineState))
		}
		w.Write(responseJSON)
	}
}
func TaskContainerMetadataHandler(taskEngine utils.DockerStateResolver) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		var responseJSON []byte
		dockerTaskEngineState := taskEngine.State()
		dockerID, dockerIDExists := utils.ValueFromRequest(r, dockerIDQueryField)
		taskArn, taskARNExists := utils.ValueFromRequest(r, taskARNQueryField)
		var status int
		if dockerIDExists && taskARNExists {
			seelog.Info("Request contains both ", dockerIDQueryField, " and ", taskARNQueryField, ". Expect at most one of these.")
			w.WriteHeader(http.StatusBadRequest)
			w.Write(responseJSON)
			return
		}
		if dockerIDExists {
			// Create TaskResponse for the docker id in the query.
			var task *apitask.Task
			var found bool
			if len(dockerID) > dockerShortIDLen {
				task, found = dockerTaskEngineState.TaskByID(dockerID)
			} else {
				tasks, _ := dockerTaskEngineState.TaskByShortID(dockerID)
				if len(tasks) == 0 {
					task = nil
					found = false
				} else if len(tasks) == 1 {
					task = tasks[0]
					found = true
				} else {
					seelog.Info("Multiple tasks found for requested dockerId: " + dockerID)
					w.WriteHeader(http.StatusBadRequest)
					w.Write(responseJSON)
					return
				}
			}
			responseJSON, status = createTaskResponse(task, found, dockerID, dockerTaskEngineState)
			w.WriteHeader(status)
		} else if taskARNExists {
			// Create TaskResponse for the task arn in the query.
			task, found := dockerTaskEngineState.TaskByArn(taskArn)
			responseJSON, status = createTaskResponse(task, found, taskArn, dockerTaskEngineState)
			w.WriteHeader(status)
		} else {
			// List all tasks.
			responseJSON, _ = json.Marshal(NewTasksResponse(dockerTaskEngineState))
		}
		w.Write(responseJSON)
	}
}
// TaskContainerMetadataHandler creates response for the 'v1/tasks' API. Lists all tasks if the request
// doesn't contain any fields. Returns a Task if either of 'dockerid' or
// 'taskarn' are specified in the request.