func poolList(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	var teams, poolNames []string
	isGlobal := false
	contexts := permission.ContextsForPermission(t, permission.PermAppCreate)
	contexts = append(contexts, permission.ContextsForPermission(t, permission.PermPoolRead)...)
	for _, c := range contexts {
		if c.CtxType == permTypes.CtxGlobal {
			isGlobal = true
			break
		}
		if c.CtxType == permTypes.CtxTeam {
			teams = append(teams, c.Value)
		}
		if c.CtxType == permTypes.CtxPool {
			poolNames = append(poolNames, c.Value)
		}
	}
	var pools []pool.Pool
	var err error
	if isGlobal {
		pools, err = pool.ListAllPools()
		if err != nil {
			return err
		}
	} else {
		pools, err = pool.ListPossiblePools(teams)
		if err != nil {
			return err
		}
		if len(poolNames) > 0 {
			namedPools, err := pool.ListPools(poolNames...)
			if err != nil {
				return err
			}
			pools = append(pools, namedPools...)
		}
	}
	poolsMap := make(map[string]struct{})
	var poolList []pool.Pool
	for _, p := range pools {
		if _, ok := poolsMap[p.Name]; ok {
			continue
		}
		poolList = append(poolList, p)
		poolsMap[p.Name] = struct{}{}
	}
	if len(poolList) == 0 {
		w.WriteHeader(http.StatusNoContent)
		return nil
	}
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(poolList)
}
func poolList(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	var teams, poolNames []string
	isGlobal := false
	contexts := permission.ContextsForPermission(t, permission.PermAppCreate)
	contexts = append(contexts, permission.ContextsForPermission(t, permission.PermPoolRead)...)
	for _, c := range contexts {
		if c.CtxType == permTypes.CtxGlobal {
			isGlobal = true
			break
		}
		if c.CtxType == permTypes.CtxTeam {
			teams = append(teams, c.Value)
		}
		if c.CtxType == permTypes.CtxPool {
			poolNames = append(poolNames, c.Value)
		}
	}
	var pools []pool.Pool
	var err error
	if isGlobal {
		pools, err = pool.ListAllPools()
		if err != nil {
			return err
		}
	} else {
		pools, err = pool.ListPossiblePools(teams)
		if err != nil {
			return err
		}
		if len(poolNames) > 0 {
			namedPools, err := pool.ListPools(poolNames...)
			if err != nil {
				return err
			}
			pools = append(pools, namedPools...)
		}
	}
	poolsMap := make(map[string]struct{})
	var poolList []pool.Pool
	for _, p := range pools {
		if _, ok := poolsMap[p.Name]; ok {
			continue
		}
		poolList = append(poolList, p)
		poolsMap[p.Name] = struct{}{}
	}
	if len(poolList) == 0 {
		w.WriteHeader(http.StatusNoContent)
		return nil
	}
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(poolList)
}
// title: pool list
// path: /pools
// method: GET
// produce: application/json
// responses:
//   200: OK
//   204: No content
//   401: Unauthorized