saving changes

This commit is contained in:
root
2021-05-29 17:24:13 +00:00
parent a3c5602b4b
commit 6bb3695465
3 changed files with 66 additions and 13 deletions

View File

@@ -20,7 +20,9 @@ func intClientHandlers(r *mux.Router) {
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(getIntClient))).Methods("GET")
r.HandleFunc("/api/intclients", securityCheck(http.HandlerFunc(getAllIntClients))).Methods("GET")
r.HandleFunc("/api/intclients/deleteall", securityCheck(http.HandlerFunc(deleteAllIntClients))).Methods("POST")
r.HandleFunc("/api/intclients/deleteall", securityCheck(http.HandlerFunc(deleteAllIntClients))).Methods("DELETE")
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(deleteIntClient))).Methods("DELETE")
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(updateIntClient))).Methods("PUT")
r.HandleFunc("/api/intclient/register", http.HandlerFunc(registerIntClient)).Methods("POST")
}
@@ -47,9 +49,20 @@ func deleteAllIntClients(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
func deleteIntClient(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
err := functions.DeleteIntClient()
if err != nil {
returnErrorResponse(w, r, formatError(err, "internal"))
return
}
//Return all the extclients in JSON format
w.WriteHeader(http.StatusOK)
}
func getIntClient(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
clients, err := functions.GetAllIntClients()
clients, err := functions.GetIntClient()
if err != nil {
returnErrorResponse(w, r, formatError(err, "internal"))
return
@@ -59,6 +72,40 @@ func getIntClient(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(clients)
}
func updateIntClient(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
var errorResponse = models.ErrorResponse{
Code: http.StatusInternalServerError, Message: "W1R3: It's not you it's me.",
}
var clientreq models.IntClient
//get node from body of request
err := json.NewDecoder(r.Body).Decode(&clientreq)
if err != nil {
returnErrorResponse(w, r, formatError(err, "internal"))
return
}
if servercfg.IsRegisterKeyRequired() {
validKey := functions.IsKeyValidGlobal(clientreq.AccessKey)
if !validKey {
errorResponse = models.ErrorResponse{
Code: http.StatusUnauthorized, Message: "W1R3: Key invalid, or none provided.",
}
returnErrorResponse(w, r, errorResponse)
return
}
}
client, err := RegisterIntClient(clientreq)
if err != nil {
returnErrorResponse(w, r, formatError(err, "internal"))
return
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(client)
}
func RegisterIntClient(client models.IntClient) (models.IntClient, error) {