CreateAppToken godoc @Security ApiKey @Summary Create access token for an special application @Tags Access token @Accept json @Produce json @Param token_name path string true "token name" @Param app path string true "application" Enums(git,starship) @Param
(ctx *gin.Context)
| 98 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 99 | // @Router /token/{app}/{token_name} [post] |
| 100 | func (h *AccessTokenHandler) CreateAppToken(ctx *gin.Context) { |
| 101 | currentUser := httpbase.GetCurrentUser(ctx) |
| 102 | if currentUser == "" { |
| 103 | httpbase.UnauthorizedError(ctx, component.ErrUserNotFound) |
| 104 | return |
| 105 | } |
| 106 | var req types.CreateUserTokenRequest |
| 107 | if err := ctx.ShouldBindJSON(&req); err != nil { |
| 108 | slog.Error("Bad request format", "error", err) |
| 109 | httpbase.BadRequest(ctx, err.Error()) |
| 110 | return |
| 111 | } |
| 112 | var err error |
| 113 | _, err = h.sc.CheckRequest(ctx, &req) |
| 114 | if err != nil { |
| 115 | slog.Error("failed to check sensitive request", slog.Any("error", err)) |
| 116 | httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error()) |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | req.Application = types.AccessTokenApp(ctx.Param("app")) |
| 121 | req.Username = currentUser |
| 122 | req.TokenName = ctx.Param("token_name") |
| 123 | token, err := h.c.Create(ctx, &req) |
| 124 | if err != nil { |
| 125 | slog.Error("Failed to create user access token", slog.String("user_name", req.Username), slog.Any("error", err)) |
| 126 | httpbase.ServerError(ctx, err) |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | httpbase.OK(ctx, token) |
| 131 | } |
| 132 | |
| 133 | // Deprecated: use DeleteAppToken instead |
| 134 | // DeleteAccessToken godoc |
nothing calls this directly
no test coverage detected