refactor(instance): remove redundant instance ownership checks
The ownership validation is now handled at an earlier stage in the request processing, making these checks redundant. This change simplifies the code by removing duplicate validation logic.
This commit is contained in:
+18
-18
@@ -537,7 +537,7 @@ func StartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
instance, err := database.DBQueryFrpcInstanceByID(instanceID)
|
||||
// instance, err := database.DBQueryFrpcInstanceByID(instanceID)
|
||||
if err == sql.ErrNoRows {
|
||||
utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found")
|
||||
postLog.Error(fmt.Sprintf("[StartInstanceHandler] User %d tried to start a not existed instance: %d", userID, instanceID))
|
||||
@@ -549,11 +549,11 @@ func StartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if instance.UserID != userID {
|
||||
utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found")
|
||||
postLog.Error(fmt.Sprintf("[StartInstanceHandler] User %d tried to start instance %d that does not belong to them", userID, instanceID))
|
||||
return
|
||||
}
|
||||
// if instance.UserID != userID {
|
||||
// utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found")
|
||||
// postLog.Error(fmt.Sprintf("[StartInstanceHandler] User %d tried to start instance %d that does not belong to them", userID, instanceID))
|
||||
// return
|
||||
// }
|
||||
|
||||
initType := sys.GetInitSystem()
|
||||
sysName, err := database.GetServiceNameByInstanceID(instanceID)
|
||||
@@ -665,7 +665,7 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
instance, err := database.DBQueryFrpcInstanceByID(instanceID)
|
||||
// instance, err := database.DBQueryFrpcInstanceByID(instanceID)
|
||||
if err == sql.ErrNoRows {
|
||||
utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found")
|
||||
postLog.Error(fmt.Sprintf("[StopInstanceHandler] User %d tried to stop a not existed instance: %d", userID, instanceID))
|
||||
@@ -677,11 +677,11 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if instance.UserID != userID {
|
||||
utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found")
|
||||
postLog.Error(fmt.Sprintf("[StopInstanceHandler] User %d tried to stop instance %d that does not belong to them", userID, instanceID))
|
||||
return
|
||||
}
|
||||
// if instance.UserID != userID {
|
||||
// utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found")
|
||||
// postLog.Error(fmt.Sprintf("[StopInstanceHandler] User %d tried to stop instance %d that does not belong to them", userID, instanceID))
|
||||
// return
|
||||
// }
|
||||
|
||||
initType := sys.GetInitSystem()
|
||||
serviceName, err := database.GetServiceNameByInstanceID(instanceID)
|
||||
@@ -781,7 +781,7 @@ func RestartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
instance, err := database.DBQueryFrpcInstanceByID(instanceID)
|
||||
// instance, err := database.DBQueryFrpcInstanceByID(instanceID)
|
||||
if err == sql.ErrNoRows {
|
||||
utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found")
|
||||
postLog.Error(fmt.Sprintf("[RestartInstanceHandler] User %d tried to restart a not existed instance: %d", userID, instanceID))
|
||||
@@ -793,11 +793,11 @@ func RestartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if instance.UserID != userID {
|
||||
utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found")
|
||||
postLog.Error(fmt.Sprintf("[RestartInstanceHandler] User %d tried to restart instance %d that does not belong to them", userID, instanceID))
|
||||
return
|
||||
}
|
||||
// if instance.UserID != userID {
|
||||
// utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found")
|
||||
// postLog.Error(fmt.Sprintf("[RestartInstanceHandler] User %d tried to restart instance %d that does not belong to them", userID, instanceID))
|
||||
// return
|
||||
// }
|
||||
|
||||
initType := sys.GetInitSystem()
|
||||
sysName, err := database.GetServiceNameByInstanceID(instanceID)
|
||||
|
||||
Reference in New Issue
Block a user