RunSpace godoc @Security JWT token @Summary run 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" @Success 200
(ctx *gin.Context)
| 274 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 275 | // @Router /spaces/{namespace}/{name}/run [post] |
| 276 | func (h *SpaceHandler) Run(ctx *gin.Context) { |
| 277 | currentUser := httpbase.GetCurrentUser(ctx) |
| 278 | if currentUser == "" { |
| 279 | httpbase.UnauthorizedError(ctx, component.ErrUserNotFound) |
| 280 | return |
| 281 | } |
| 282 | namespace, name, err := common.GetNamespaceAndNameFromContext(ctx) |
| 283 | if err != nil { |
| 284 | slog.Error("failed to get namespace from context", "error", err) |
| 285 | httpbase.BadRequest(ctx, err.Error()) |
| 286 | return |
| 287 | } |
| 288 | allow, err := h.c.AllowAdminAccess(ctx, types.SpaceRepo, namespace, name, currentUser) |
| 289 | if err != nil { |
| 290 | slog.Error("failed to check user permission", "error", err) |
| 291 | httpbase.ServerError(ctx, errors.New("failed to check user permission")) |
| 292 | return |
| 293 | } |
| 294 | if !allow { |
| 295 | slog.Info("user not allowed to run space", slog.String("namespace", namespace), |
| 296 | slog.String("name", name), slog.Any("username", currentUser)) |
| 297 | httpbase.UnauthorizedError(ctx, errors.New("user not allowed to run sapce")) |
| 298 | return |
| 299 | } |
| 300 | deployID, err := h.c.Deploy(ctx, namespace, name, currentUser) |
| 301 | if err != nil { |
| 302 | slog.Error("failed to deploy space", slog.String("namespace", namespace), |
| 303 | slog.String("name", name), slog.Any("error", err)) |
| 304 | httpbase.ServerError(ctx, errors.New("failed to deploy space")) |
| 305 | return |
| 306 | } |
| 307 | |
| 308 | slog.Info("space deployment created", slog.String("namespace", namespace), |
| 309 | slog.String("name", name), slog.Int64("deploy_id", deployID)) |
| 310 | httpbase.OK(ctx, nil) |
| 311 | } |
| 312 | |
| 313 | // WakeupSpace godoc |
| 314 | // @Security JWT token |
nothing calls this directly
no test coverage detected