MCPcopy Create free account
hub / github.com/actiontech/dtle / getCurrentUser

Function getCurrentUser

api/handler/v2/user.go:325–348  ·  view source on GitHub ↗
(c echo.Context)

Source from the content-addressed store, hash-verified

323}
324
325func getCurrentUser(c echo.Context) (*common.User, error) {
326 logger := handler.NewLogger().Named("getCurrentUser")
327 logger.Info("getCurrentUser")
328 key := "current_user"
329 currentUser := c.Get(key)
330 if currentUser != nil {
331 if user, ok := currentUser.(*common.User); ok {
332 return user, nil
333 }
334 }
335 storeManager, err := common.NewStoreManager([]string{handler.ConsulAddr}, logger)
336 if err != nil {
337 return nil, err
338 }
339 user, exist, err := storeManager.GetUser(GetUserName(c))
340 if err != nil {
341 return nil, err
342 } else if !exist {
343 return nil, fmt.Errorf("current user is not exist")
344 }
345
346 c.Set(key, user)
347 return user, nil
348}
349
350func GetUserName(c echo.Context) (string, string) {
351 user := c.Get("user").(*jwt.Token)

Callers 13

JobListV2Function · 0.85
CreateOrUpdateSyncJobV2Function · 0.85
ReverseJobV2Function · 0.85
checkJobAccessFunction · 0.85
RoleListV2Function · 0.85
UserListV2Function · 0.85
TenantListV2Function · 0.85
ResetPasswordV2Function · 0.85
GetCurrentUserV2Function · 0.85
ListActionV2Function · 0.85

Calls 6

GetUserMethod · 0.95
NewLoggerFunction · 0.92
NewStoreManagerFunction · 0.92
GetUserNameFunction · 0.85
GetMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected