rawlinp commented on a change in pull request #4015: Rewrite /federations to Go 
- POST/PUT/DELETE
URL: https://github.com/apache/trafficcontrol/pull/4015#discussion_r340160646
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/federations/federations.go
 ##########
 @@ -167,3 +206,296 @@ ORDER BY
        }
        return feds, nil
 }
+
+// AddFederationResorverMappingsForCurrentUser is the handler for a POST 
request to /federations.
+// Confusingly, it does not create a federation, but is instead used to 
manipulate the resolvers
+// used by one or more particular Delivery Services for one or more particular 
Federations.
+func AddFederationResolverMappingsForCurrentUser(w http.ResponseWriter, r 
*http.Request) {
+       inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+       tx := inf.Tx.Tx
+       if userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+               return
+       }
+       defer inf.Close()
+
+       mappings, userErr, sysErr := getMappingsFromRequestBody(*inf.Version, 
r.Body)
+       if userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, tx, http.StatusBadRequest, userErr, sysErr)
+               return
+       }
+
+       if err := mappings.Validate(tx); err != nil {
+               errCode = http.StatusBadRequest
+               userErr = fmt.Errorf("validating request: %v", err)
+               api.HandleErr(w, r, tx, errCode, userErr, nil)
+               return
+       }
+
+       userErr, sysErr, errCode = 
addFederationResolverMappingsForCurrentUser(inf.User, tx, mappings)
+       if userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+               return
+       }
+
+       msg := fmt.Sprintf("%s successfully created federation resolvers.", 
inf.User.UserName)
+       if inf.Version.Minor <= 3 {
 
 Review comment:
   this should probably also check the major version in case we ever decide to 
"graduate" this API to 2.0

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