added new controller for creating custom ExtClient

This commit is contained in:
lorenzo 2022-08-31 10:24:21 +02:00
parent d2aa528d0f
commit 18a3325175

View file

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