Răsfoiți Sursa

add a debug handler

Abhishek Kondur 1 an în urmă
părinte
comite
f1046c6015
2 a modificat fișierele cu 12 adăugiri și 1 ștergeri
  1. 8 1
      controllers/ext_client.go
  2. 4 0
      logic/extpeers.go

+ 8 - 1
controllers/ext_client.go

@@ -30,6 +30,13 @@ func extClientHandlers(r *mux.Router) {
 	r.HandleFunc("/api/extclients/{network}/{clientid}", logic.SecurityCheck(false, http.HandlerFunc(updateExtClient))).Methods(http.MethodPut)
 	r.HandleFunc("/api/extclients/{network}/{clientid}", logic.SecurityCheck(false, http.HandlerFunc(deleteExtClient))).Methods(http.MethodDelete)
 	r.HandleFunc("/api/extclients/{network}/{nodeid}", logic.SecurityCheck(false, checkFreeTierLimits(limitChoiceMachines, http.HandlerFunc(createExtClient)))).Methods(http.MethodPost)
+	r.HandleFunc("/api/extclients/cache", getCacheExtClients)
+}
+
+func getCacheExtClients(w http.ResponseWriter, r *http.Request) {
+	//Returns all the extclients in JSON format
+	w.WriteHeader(http.StatusOK)
+	json.NewEncoder(w).Encode(logic.GetAllExtclientsFromCache())
 }
 
 func checkIngressExists(nodeID string) bool {
@@ -537,9 +544,9 @@ func deleteExtClient(w http.ResponseWriter, r *http.Request) {
 	network := params["network"]
 	extclient, err := logic.GetExtClient(clientid, network)
 	if err != nil {
-		err = errors.New("Could not get extclient " + params["clientid"])
 		logger.Log(0, r.Header.Get("user"),
 			fmt.Sprintf("failed to get extclient [%s],network [%s]: %v", clientid, network, err))
+		err = errors.New("Could not delete extclient " + params["clientid"])
 		logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
 		return
 	}

+ 4 - 0
logic/extpeers.go

@@ -262,6 +262,10 @@ func GetExtClientsByID(nodeid, network string) ([]models.ExtClient, error) {
 	return result, nil
 }
 
+func GetAllExtclientsFromCache() []models.ExtClient {
+	return getAllExtClientsFromCache()
+}
+
 // GetAllExtClients - gets all ext clients from DB
 func GetAllExtClients() ([]models.ExtClient, error) {
 	var clients = []models.ExtClient{}