From 5bbb2d3e03d80866099f7e07b995557ad68a02d1 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Wed, 31 Aug 2022 10:24:21 +0200 Subject: [PATCH 1/2] added new controller for creating custom ExtClient changed author --- controllers/ext_client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/controllers/ext_client.go b/controllers/ext_client.go index e5c19e82..86e55c3c 100644 --- a/controllers/ext_client.go +++ b/controllers/ext_client.go @@ -26,6 +26,7 @@ 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 { @@ -248,9 +249,9 @@ func createExtClient(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") 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") @@ -261,6 +262,9 @@ 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 + } extclient.Network = networkName extclient.IngressGatewayID = nodeid node, err := logic.GetNodeByID(nodeid) From bcddc3f3c57ad1212d8a9676ef624bfe19a6b7a9 Mon Sep 17 00:00:00 2001 From: Casini Lorenzo Date: Thu, 1 Sep 2022 15:45:54 +0200 Subject: [PATCH 2/2] Fix url prameter to body changed from url parameters to request body --- controllers/ext_client.go | 14 ++++++++++---- models/structs.go | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/controllers/ext_client.go b/controllers/ext_client.go index 86e55c3c..d6ddad2b 100644 --- a/controllers/ext_client.go +++ b/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) diff --git a/models/structs.go b/models/structs.go index d0ce6bb7..b907f3e1 100644 --- a/models/structs.go +++ b/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"`