fixed readme, composes, netclient push/pull

This commit is contained in:
afeiszli
2021-06-01 00:36:08 +00:00
parent 0ffb590b99
commit 963a3d1b92
17 changed files with 190 additions and 63 deletions

View File

@@ -369,24 +369,39 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) {
returnErrorResponse(w, r, formatError(err, "internal"))
return
}
success, err := DeleteExtClient(params["network"], params["clientid"])
if err != nil {
returnErrorResponse(w, r, formatError(err, "internal"))
return
} else if !success {
returnErrorResponse(w, r, formatError(err, "internal"))
return
}
oldExtClient.ClientID = newExtClient.ClientID
CreateExtClient(oldExtClient)
newclient, err := UpdateExtClient(newExtClient.ClientID, params["network"], oldExtClient)
if err != nil {
returnErrorResponse(w, r, formatError(err, "internal"))
return
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(oldExtClient)
json.NewEncoder(w).Encode(newclient)
}
func UpdateExtClient(newclientid string, network string, client models.ExtClient) (models.ExtClient, error) {
//collection := mongoconn.ConnectDB()
collection := mongoconn.Client.Database("netmaker").Collection("extclients")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
// Create filter
filter := bson.M{"clientid": client.ClientID, "network": network}
// prepare update model.
update := bson.D{
{"$set", bson.D{
{"clientid", newclientid},
}},
}
var clientupdate models.ExtClient
err := collection.FindOneAndUpdate(ctx, filter, update).Decode(&clientupdate)
defer cancel()
return clientupdate, err
}
func DeleteExtClient(network string, clientid string) (bool, error) {