Browse Source

Fix url prameter to body

changed from url parameters to request body
Casini Lorenzo 2 years ago
parent
commit
bcddc3f3c5
2 changed files with 15 additions and 4 deletions
  1. 10 4
      controllers/ext_client.go
  2. 5 0
      models/structs.go

+ 10 - 4
controllers/ext_client.go

@@ -26,7 +26,6 @@ func extClientHandlers(r *mux.Router) {
 	r.HandleFunc("/api/extclients/{network}/{clientid}", securityCheck(false, http.HandlerFunc(updateExtClient))).Methods("PUT")
 	r.HandleFunc("/api/extclients/{network}/{clientid}", securityCheck(false, http.HandlerFunc(deleteExtClient))).Methods("DELETE")
 	r.HandleFunc("/api/extclients/{network}/{nodeid}", securityCheck(false, http.HandlerFunc(createExtClient))).Methods("POST")
-	r.HandleFunc("/api/extclients/{network}/{nodeid}/{clientid}", securityCheck(false, http.HandlerFunc(createExtClient))).Methods("POST")
 }
 
 func checkIngressExists(nodeID string) bool {
@@ -251,7 +250,7 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
 	var params = mux.Vars(r)
 	networkName := params["network"]
 	nodeid := params["nodeid"]
-	clientid := params["clientid"]
+	
 	ingressExists := checkIngressExists(nodeid)
 	if !ingressExists {
 		err := errors.New("ingress does not exist")
@@ -262,9 +261,16 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
 	}
 
 	var extclient models.ExtClient
-	if clientid != "" {// if clientid is passed from api call, create new extclient with custom clientid instead to generate a random one
-		extclient.ClientID = clientid
+	var CustomExtClient models.CustomExtClient
+	
+	err := json.NewDecoder(r.body).Decode(&CustomExtClient);
+
+	if err != nil {
+		logger.Log(1, "error creating CustomExtClient"+err.Error())
+	} else {
+		extclient.ClientID = CustomExtClient.ClientID
 	}
+	
 	extclient.Network = networkName
 	extclient.IngressGatewayID = nodeid
 	node, err := logic.GetNodeByID(nodeid)

+ 5 - 0
models/structs.go

@@ -10,6 +10,11 @@ import (
 const PLACEHOLDER_KEY_TEXT = "ACCESS_KEY"
 const PLACEHOLDER_TOKEN_TEXT = "ACCESS_TOKEN"
 
+// CustomExtClient - struct for CustomExtClient params
+type CustomExtClient struct {
+	ClientID string `json:"clientid"`
+}
+
 // AuthParams - struct for auth params
 type AuthParams struct {
 	MacAddress string `json:"macaddress"`