You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/07/08 19:55:32 UTC

[GitHub] [trafficcontrol] zrhoffman commented on issue #4867: GET /api/1.1/servers/{id} returns an empty response

zrhoffman commented on issue #4867:
URL: https://github.com/apache/trafficcontrol/issues/4867#issuecomment-655723532


   Output of `git log -n1 -L565,596:servers.go --pretty=format:%h`:
   
   83d3012eec
   ```diff
   diff --git a/traffic_ops/traffic_ops_golang/server/servers.go b/traffic_ops/traffic_ops_golang/server/servers.go
   --- a/traffic_ops/traffic_ops_golang/server/servers.go
   +++ b/traffic_ops/traffic_ops_golang/server/servers.go
   @@ -544,36 +565,32 @@
    func ReadID(w http.ResponseWriter, r *http.Request) {
    	alternative := "GET /servers with query parameter id"
    	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, []string{"id"})
    	tx := inf.Tx.Tx
    	if userErr != nil || sysErr != nil {
    		api.HandleDeprecatedErr(w, r, tx, errCode, userErr, sysErr, &alternative)
    		return
    	}
    	defer inf.Close()
    
    	servers := []tc.ServerNullable{}
   -	servers, _, userErr, sysErr, errCode = getServers(inf.Params, inf.Tx, inf.User)
   +	cfg, e := api.GetConfig(r.Context())
   +	useIMS := false
   +	if e == nil && cfg != nil {
   +		useIMS = cfg.UseIMS
   +	} else {
   +		log.Warnf("Couldn't get config %v", e)
   +	}
   +	servers, _, userErr, sysErr, errCode, _ = getServers(r.Header, inf.Params, inf.Tx, inf.User, useIMS)
    
    	if len(servers) > 1 {
    		api.HandleDeprecatedErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("ID '%d' matched more than one server (%d total)", inf.IntParams["id"], len(servers)), &alternative)
    		return
    	}
    
    	deprecationAlerts := api.CreateDeprecationAlerts(&alternative)
    
    	// No need to bother converting if there's no data
    	if len(servers) < 1 {
    		api.WriteAlertsObj(w, r, http.StatusOK, deprecationAlerts, servers)
    	}
   -
   -	legacyServers := make([]tc.ServerNullableV11, 0, len(servers))
   -	for _, server := range servers {
   -		legacyServer, err := server.ToServerV2()
   -		if err != nil {
   -			api.HandleDeprecatedErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to convert servers to legacy format: %v", err), &alternative)
   -			return
   -		}
   -		legacyServers = append(legacyServers, legacyServer.ServerNullableV11)
   -	}
   -	api.WriteAlertsObj(w, r, http.StatusOK, deprecationAlerts, legacyServers)
    }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org