agent/handlers/v3/task_metadata_handler.go
func TaskMetadataHandler(state dockerstate.TaskEngineState, ecsClient api.ECSClient, cluster, az, containerInstanceArn string, propagateTags bool) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		taskARN, err := getTaskARNByRequest(r, state)
		if err != nil {
			responseJSON, _ := json.Marshal(
				fmt.Sprintf("V3 task metadata handler: unable to get task arn from request: %s", err.Error()))
			utils.WriteJSONToResponse(w, http.StatusBadRequest, responseJSON, utils.RequestTypeTaskMetadata)
			return
		}

		seelog.Infof("V3 task metadata handler: writing response for task '%s'", taskARN)

		taskResponse, err := v2.NewTaskResponse(taskARN, state, ecsClient, cluster, az, containerInstanceArn, propagateTags)
		if err != nil {
			errResponseJSON, _ := json.Marshal("Unable to generate metadata for task: '" + taskARN + "'")
			utils.WriteJSONToResponse(w, http.StatusBadRequest, errResponseJSON, utils.RequestTypeTaskMetadata)
			return
		}
		task, _ := state.TaskByArn(taskARN)
		if task.GetTaskENI() == nil {
			// fill in non-awsvpc network details for container responses here
			responses := make([]v2.ContainerResponse, 0)
			for _, containerResponse := range taskResponse.Containers {
				networks, err := GetContainerNetworkMetadata(containerResponse.ID, state)
				if err != nil {
					errResponseJSON, _ := json.Marshal(err.Error())
					utils.WriteJSONToResponse(w, http.StatusBadRequest, errResponseJSON, utils.RequestTypeContainerMetadata)
					return
				}
				containerResponse.Networks = networks
				responses = append(responses, containerResponse)
			}
			taskResponse.Containers = responses
		}
		responseJSON, _ := json.Marshal(taskResponse)
		utils.WriteJSONToResponse(w, http.StatusOK, responseJSON, utils.RequestTypeTaskMetadata)
	}
}
func TaskMetadataHandler(state dockerstate.TaskEngineState, ecsClient api.ECSClient, cluster, az, containerInstanceArn string, propagateTags bool) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		taskARN, err := getTaskARNByRequest(r, state)
		if err != nil {
			responseJSON, _ := json.Marshal(
				fmt.Sprintf("V3 task metadata handler: unable to get task arn from request: %s", err.Error()))
			utils.WriteJSONToResponse(w, http.StatusBadRequest, responseJSON, utils.RequestTypeTaskMetadata)
			return
		}

		seelog.Infof("V3 task metadata handler: writing response for task '%s'", taskARN)

		taskResponse, err := v2.NewTaskResponse(taskARN, state, ecsClient, cluster, az, containerInstanceArn, propagateTags)
		if err != nil {
			errResponseJSON, _ := json.Marshal("Unable to generate metadata for task: '" + taskARN + "'")
			utils.WriteJSONToResponse(w, http.StatusBadRequest, errResponseJSON, utils.RequestTypeTaskMetadata)
			return
		}
		task, _ := state.TaskByArn(taskARN)
		if task.GetTaskENI() == nil {
			// fill in non-awsvpc network details for container responses here
			responses := make([]v2.ContainerResponse, 0)
			for _, containerResponse := range taskResponse.Containers {
				networks, err := GetContainerNetworkMetadata(containerResponse.ID, state)
				if err != nil {
					errResponseJSON, _ := json.Marshal(err.Error())
					utils.WriteJSONToResponse(w, http.StatusBadRequest, errResponseJSON, utils.RequestTypeContainerMetadata)
					return
				}
				containerResponse.Networks = networks
				responses = append(responses, containerResponse)
			}
			taskResponse.Containers = responses
		}
		responseJSON, _ := json.Marshal(taskResponse)
		utils.WriteJSONToResponse(w, http.StatusOK, responseJSON, utils.RequestTypeTaskMetadata)
	}
}
func TaskMetadataHandler ( state dockerstate . TaskEngineState , ecsClient api . ECSClient , cluster , az , containerInstanceArn string , propagateTags bool ) func ( http . ResponseWriter , * http . Request ) { return func ( w http . ResponseWriter , r * http . Request ) { taskARN , err := getTaskARNByRequest ( r , state ) if err != nil { responseJSON , _ := json . Marshal ( fmt . Sprintf ( " " , err . Error ( ) ) ) utils . WriteJSONToResponse ( w , http . StatusBadRequest , responseJSON , utils . RequestTypeTaskMetadata ) return } seelog . Infof ( " " , taskARN ) taskResponse , err := v2 . NewTaskResponse ( taskARN , state , ecsClient , cluster , az , containerInstanceArn , propagateTags ) if err != nil { errResponseJSON , _ := json . Marshal ( " " + taskARN + " " ) utils . WriteJSONToResponse ( w , http . StatusBadRequest , errResponseJSON , utils . RequestTypeTaskMetadata ) return } task , _ := state . TaskByArn ( taskARN ) if task . GetTaskENI ( ) == nil { // fill in non-awsvpc network details for container responses here responses := make ( [ ] v2 . ContainerResponse , 0 ) for _ , containerResponse := range taskResponse . Containers { networks , err := GetContainerNetworkMetadata ( containerResponse . ID , state ) if err != nil { errResponseJSON , _ := json . Marshal ( err . Error ( ) ) utils . WriteJSONToResponse ( w , http . StatusBadRequest , errResponseJSON , utils . RequestTypeContainerMetadata ) return } containerResponse . Networks = networks responses = append ( responses , containerResponse ) } taskResponse . Containers = responses } responseJSON , _ := json . Marshal ( taskResponse ) utils . WriteJSONToResponse ( w , http . StatusOK , responseJSON , utils . RequestTypeTaskMetadata ) } }
// TaskMetadataHandler returns the handler method for handling task metadata requests.
TaskMetadataHandler returns the handler method for handling task metadata requests .