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 2019/12/11 21:11:19 UTC

[GitHub] [trafficcontrol] ChrisHines commented on a change in pull request #4105: Rewrite /federation_resolvers/{{ID}} to Go

ChrisHines commented on a change in pull request #4105: Rewrite /federation_resolvers/{{ID}} to Go
URL: https://github.com/apache/trafficcontrol/pull/4105#discussion_r356832282
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/federation_resolvers/federation_resolvers.go
 ##########
 @@ -136,3 +151,99 @@ func Read(w http.ResponseWriter, r *http.Request) {
 
 	api.WriteResp(w, r, resolvers)
 }
+
+func Delete(w http.ResponseWriter, r *http.Request) {
+	inf, sysErr, userErr, errCode := api.NewInfo(r, []string{"id"}, []string{"id"})
+	tx := inf.Tx.Tx
+	if sysErr != nil || userErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	userErr, sysErr, statusCode, alert, respObj := delete(inf)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, tx, statusCode, userErr, sysErr)
+		return
+	}
+
+	api.WriteRespAlertObj(w, r, tc.SuccessLevel, alert.Text, respObj)
+}
+
+func delete(inf *api.APIInfo) (error, error, int, tc.Alert, tc.FederationResolver) {
+	var userErr error
+	var sysErr error
+	var statusCode = http.StatusOK
+	var alert tc.Alert
+	var result tc.FederationResolver
+
+	err := inf.Tx.Tx.QueryRow(deleteQuery, inf.IntParams["id"]).Scan(&result.ID, &result.IPAddress, &result.Type)
+	if err != nil {
+		if err == sql.ErrNoRows {
+			userErr = fmt.Errorf("No federation resolver by ID %d", inf.IntParams["id"])
+			statusCode = http.StatusNotFound
+		} else {
+			userErr, sysErr, statusCode = api.ParseDBError(err)
+		}
+		return userErr, sysErr, statusCode, alert, result
+	}
+
+	changeLogMsg := fmt.Sprintf("FEDERATION_RESOLVER: %s, ID: %d, ACTION: Deleted", *result.IPAddress, *result.ID)
+	api.CreateChangeLogRawTx(api.ApiChange, changeLogMsg, inf.User, inf.Tx.Tx)
+
+	alertMsg := fmt.Sprintf("Federation resolver deleted [ IP = %s ] with id: %d", *result.IPAddress, *result.ID)
+	alert = tc.Alert {
+		Level: tc.SuccessLevel.String(),
+		Text: alertMsg,
+	}
+
+	return userErr, sysErr, statusCode, alert, result
+}
+
+func DeleteByID(w http.ResponseWriter, r *http.Request) {
+	inf, sysErr, userErr, errCode := api.NewInfo(r, []string{"id"}, []string{"id"})
+	tx := inf.Tx.Tx
+	if sysErr != nil || userErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	userErr, sysErr, statusCode, alert, respObj := delete(inf)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, tx, statusCode, userErr, sysErr)
+		return
+	}
+
+	var resp = struct {
+		tc.Alerts
+		Response *tc.FederationResolver `json:"response,omitempty"`
+	} {
+		tc.Alerts{
+			Alerts: []tc.Alert{
+				alert,
+				tc.Alert{
+					Level: tc.WarnLevel.String(),
+					Text: "This endpoint is deprecated, please use '/federation_resolvers' instead",
+				},
+			},
+		},
+		&respObj,
+	}
+
+	if inf.Version.Major < 2 && inf.Version.Minor < 4 {
 
 Review comment:
   Do we care about `Major == 0` here? Would this line be more clear if it checked for `Major == 1` instead?

----------------------------------------------------------------
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


With regards,
Apache Git Services