rimashah25 commented on code in PR #6996:
URL: https://github.com/apache/trafficcontrol/pull/6996#discussion_r937001171
##########
traffic_ops/traffic_ops_golang/server/servers_server_capability.go:
##########
@@ -441,3 +442,87 @@ func getDSTenantIDsByIDs(tx *sqlx.Tx, dsIDs []int64)
([]DSTenant, error) {
return dsTenantIDs, nil
}
+
+// AssignMultipleServerCapabilities helps assign multiple server capabilities
to a given server
+func AssignMultipleServerCapabilities(w http.ResponseWriter, r *http.Request) {
+ inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"id"},
[]string{"id"})
+ tx := inf.Tx.Tx
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ var msc tc.MultipleServerCapabilities
+ if err := json.NewDecoder(r.Body).Decode(&msc); err != nil {
+ api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
+ return
+ }
+
+ // Check existence prior to checking type
+ _, exists, err := dbhelpers.GetServerNameFromID(tx,
int64(*msc.ServerID))
+ if err != nil {
+ api.HandleErr(w, r, tx, http.StatusInternalServerError, nil,
err)
+ }
+ if !exists {
+ userErr := fmt.Errorf("server %v does not exist", *msc.ServerID)
+ api.HandleErr(w, r, tx, http.StatusNotFound, userErr, nil)
+ return
+ }
+
+ // Ensure type is correct
+ correctType := true
+ if err := tx.QueryRow(scCheckServerTypeQuery(),
msc.ServerID).Scan(&correctType); err != nil {
+ api.HandleErr(w, r, tx, http.StatusInternalServerError, nil,
fmt.Errorf("checking server type: %v", err))
Review Comment:
Aha.. I remember this from LP review comments... should have done it..
thanks for keeping me honest.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]