ocket8888 commented on a change in pull request #3534: TP Delivery Service 
Generate SSL update, new letsencrypt generate and renew API endpoints
URL: https://github.com/apache/trafficcontrol/pull/3534#discussion_r378333326
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/deliveryservice/keys.go
 ##########
 @@ -210,9 +248,78 @@ func getSSLKeysByXMLIDHelper(xmlID string, inf 
*api.APIInfo, w http.ResponseWrit
                        return
                }
        }
+
        api.WriteResp(w, r, keyObj)
 }
 
+// GetSSLKeysByXMLIDV15 fetches the deliveryservice ssl keys by the specified 
xmlID. V15 includes expiration date.
+func GetSSLKeysByXMLIDV15(w http.ResponseWriter, r *http.Request) {
+       inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"xmlid"}, nil)
+       if userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+               return
+       }
+       defer inf.Close()
+       if inf.Config.RiakEnabled == false {
+               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
errors.New("the Riak service is unavailable"), errors.New("getting SSL keys 
from Riak by xml id: Riak is not configured"))
+               return
+       }
+       xmlID := inf.Params["xmlid"]
+       getSSLKeysByXMLIDHelperV15(xmlID, inf, w, r)
+}
+
+func getSSLKeysByXMLIDHelperV15(xmlID string, inf *api.APIInfo, w 
http.ResponseWriter, r *http.Request) {
+       version := inf.Params["version"]
+       decode := inf.Params["decode"]
+       if userErr, sysErr, errCode := tenant.Check(inf.User, xmlID, 
inf.Tx.Tx); userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+               return
+       }
+       keyObj, ok, err := riaksvc.GetDeliveryServiceSSLKeysObjV15(xmlID, 
version, inf.Tx.Tx, inf.Config.RiakAuthOptions, inf.Config.RiakPort)
+       if err != nil {
+               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
nil, errors.New("getting ssl keys: "+err.Error()))
+               return
+       }
+       if !ok {
+               api.WriteRespAlertObj(w, r, tc.ErrorLevel, "no object found for 
the specified key", struct{}{})
 
 Review comment:
   This writes a response using the `200 OK` response code, which is 
inappropriate when the request was not successfully serviced. Looks like for 
backward compatibility we should still send back an empty object, but the 
response code can change to be more appropriate (probably `404 Not Found`).

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to