StopSpace godoc @Security JWT token @Summary stop space app @Tags Space @Accept json @Produce json @Param namespace path string true "namespace" @Param name path string true "name" @Param current_user query string true "current_user" @Failure 4
(ctx *gin.Context)
| 352 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 353 | // @Router /spaces/{namespace}/{name}/stop [post] |
| 354 | func (h *SpaceHandler) Stop(ctx *gin.Context) { |
| 355 | currentUser := httpbase.GetCurrentUser(ctx) |
| 356 | if currentUser == "" { |
| 357 | httpbase.UnauthorizedError(ctx, component.ErrUserNotFound) |
| 358 | return |
| 359 | } |
| 360 | namespace, name, err := common.GetNamespaceAndNameFromContext(ctx) |
| 361 | if err != nil { |
| 362 | slog.Error("failed to get namespace from context", "error", err) |
| 363 | httpbase.BadRequest(ctx, err.Error()) |
| 364 | return |
| 365 | } |
| 366 | allow, err := h.c.AllowAdminAccess(ctx, types.SpaceRepo, namespace, name, currentUser) |
| 367 | if err != nil { |
| 368 | slog.Error("failed to check user permission", "error", err) |
| 369 | httpbase.ServerError(ctx, errors.New("failed to check user permission")) |
| 370 | return |
| 371 | } |
| 372 | if !allow { |
| 373 | slog.Info("user not allowed to stop space", slog.String("namespace", namespace), |
| 374 | slog.String("name", name), slog.Any("username", currentUser)) |
| 375 | httpbase.UnauthorizedError(ctx, errors.New("user not allowed to stop sapce")) |
| 376 | return |
| 377 | } |
| 378 | |
| 379 | err = h.c.Stop(ctx, namespace, name) |
| 380 | if err != nil { |
| 381 | slog.Error("failed to stop space", slog.String("namespace", namespace), |
| 382 | slog.String("name", name), slog.Any("error", err)) |
| 383 | httpbase.ServerError(ctx, errors.New("failed to stop space")) |
| 384 | return |
| 385 | } |
| 386 | |
| 387 | slog.Info("stop space success", slog.String("namespace", namespace), |
| 388 | slog.String("name", name)) |
| 389 | httpbase.OK(ctx, nil) |
| 390 | } |
| 391 | |
| 392 | // GetSpaceStatus godoc |
| 393 | // @Security JWT token |
nothing calls this directly
no test coverage detected