Merged in feature/demo-support (pull request #207)
Feature/demo support * index logs now debug * demo data loader
This commit is contained in:
@@ -321,7 +321,12 @@ func (ctrl *Controllers) GetAdminUser(ctx echo.Context, email UserEmail) error {
|
||||
// Get user from Cognito
|
||||
cognitoUser, err := usermanagement.GetCognitoUser(context.Background(), cognitoClient, cognitoConfig.UserPoolID, string(email))
|
||||
if err != nil {
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito", "error", err, "email", email)
|
||||
errInfo := usermanagement.ClassifyCognitoError(err, string(email))
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito",
|
||||
"error", err,
|
||||
"email", email,
|
||||
"error_type", errInfo.ErrorType,
|
||||
"http_status", errInfo.HTTPStatus)
|
||||
usermanagement.LogUserAdminAction(
|
||||
ctrl.cfg.GetAuthLogger(),
|
||||
usermanagement.ActionUpdate,
|
||||
@@ -330,12 +335,15 @@ func (ctrl *Controllers) GetAdminUser(ctx echo.Context, email UserEmail) error {
|
||||
string(email),
|
||||
"",
|
||||
usermanagement.ResultFailure,
|
||||
fmt.Sprintf("User not found in Cognito: %v", err),
|
||||
fmt.Sprintf("Cognito error (%s): %v", errInfo.ErrorType, err),
|
||||
ctx.Response().Header().Get(echo.HeaderXRequestID),
|
||||
)
|
||||
|
||||
return ctx.JSON(http.StatusNotFound, ErrorMessage{
|
||||
Message: fmt.Sprintf("User not found: %s", email),
|
||||
errorType := string(errInfo.ErrorType)
|
||||
return ctx.JSON(errInfo.HTTPStatus, ErrorMessage{
|
||||
Message: errInfo.Message,
|
||||
ErrorType: &errorType,
|
||||
Details: &errInfo.Details,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -392,11 +400,14 @@ func (ctrl *Controllers) CheckAdminUserExists(ctx echo.Context, email UserEmail)
|
||||
Region: ctrl.cfg.GetAuthRegion(),
|
||||
}
|
||||
|
||||
// Check if user exists in Cognito
|
||||
exists := usermanagement.UserExistsInCognito(context.Background(), cognitoClient, cognitoConfig.UserPoolID, string(email))
|
||||
|
||||
if !exists {
|
||||
return ctx.NoContent(http.StatusNotFound)
|
||||
// Check if user exists in Cognito (use GetCognitoUser to get detailed error info)
|
||||
_, err = usermanagement.GetCognitoUser(context.Background(), cognitoClient, cognitoConfig.UserPoolID, string(email))
|
||||
if err != nil {
|
||||
errInfo := usermanagement.ClassifyCognitoError(err, string(email))
|
||||
// For HEAD requests, we can only return status code and headers
|
||||
ctx.Response().Header().Set("X-Error-Type", string(errInfo.ErrorType))
|
||||
ctx.Response().Header().Set("X-Error-Message", errInfo.Message)
|
||||
return ctx.NoContent(errInfo.HTTPStatus)
|
||||
}
|
||||
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
@@ -674,7 +685,12 @@ func (ctrl *Controllers) UpdateAdminUser(ctx echo.Context, email UserEmail) erro
|
||||
// Get user from Cognito to verify existence and get Subject ID
|
||||
cognitoUser, err := usermanagement.GetCognitoUser(context.Background(), cognitoClient, cognitoConfig.UserPoolID, string(email))
|
||||
if err != nil {
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito", "error", err, "email", email)
|
||||
errInfo := usermanagement.ClassifyCognitoError(err, string(email))
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito",
|
||||
"error", err,
|
||||
"email", email,
|
||||
"error_type", errInfo.ErrorType,
|
||||
"http_status", errInfo.HTTPStatus)
|
||||
usermanagement.LogUserAdminAction(
|
||||
ctrl.cfg.GetAuthLogger(),
|
||||
usermanagement.ActionUpdate,
|
||||
@@ -683,12 +699,15 @@ func (ctrl *Controllers) UpdateAdminUser(ctx echo.Context, email UserEmail) erro
|
||||
string(email),
|
||||
"",
|
||||
usermanagement.ResultFailure,
|
||||
fmt.Sprintf("User not found in Cognito: %v", err),
|
||||
fmt.Sprintf("Cognito error (%s): %v", errInfo.ErrorType, err),
|
||||
ctx.Response().Header().Get(echo.HeaderXRequestID),
|
||||
)
|
||||
|
||||
return ctx.JSON(http.StatusNotFound, ErrorMessage{
|
||||
Message: fmt.Sprintf("User not found: %s", email),
|
||||
errorType := string(errInfo.ErrorType)
|
||||
return ctx.JSON(errInfo.HTTPStatus, ErrorMessage{
|
||||
Message: errInfo.Message,
|
||||
ErrorType: &errorType,
|
||||
Details: &errInfo.Details,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -773,7 +792,12 @@ func (ctrl *Controllers) DeleteAdminUser(ctx echo.Context, email UserEmail, para
|
||||
// Get user from Cognito to verify existence and get Subject ID
|
||||
cognitoUser, err := usermanagement.GetCognitoUser(context.Background(), cognitoClient, cognitoConfig.UserPoolID, string(email))
|
||||
if err != nil {
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito", "error", err, "email", email)
|
||||
errInfo := usermanagement.ClassifyCognitoError(err, string(email))
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito",
|
||||
"error", err,
|
||||
"email", email,
|
||||
"error_type", errInfo.ErrorType,
|
||||
"http_status", errInfo.HTTPStatus)
|
||||
usermanagement.LogUserAdminAction(
|
||||
ctrl.cfg.GetAuthLogger(),
|
||||
usermanagement.ActionDelete,
|
||||
@@ -782,12 +806,15 @@ func (ctrl *Controllers) DeleteAdminUser(ctx echo.Context, email UserEmail, para
|
||||
string(email),
|
||||
"",
|
||||
usermanagement.ResultFailure,
|
||||
fmt.Sprintf("User not found in Cognito: %v", err),
|
||||
fmt.Sprintf("Cognito error (%s): %v", errInfo.ErrorType, err),
|
||||
ctx.Response().Header().Get(echo.HeaderXRequestID),
|
||||
)
|
||||
|
||||
return ctx.JSON(http.StatusNotFound, ErrorMessage{
|
||||
Message: fmt.Sprintf("User not found: %s", email),
|
||||
errorType := string(errInfo.ErrorType)
|
||||
return ctx.JSON(errInfo.HTTPStatus, ErrorMessage{
|
||||
Message: errInfo.Message,
|
||||
ErrorType: &errorType,
|
||||
Details: &errInfo.Details,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -899,7 +926,12 @@ func (ctrl *Controllers) DisableAdminUser(ctx echo.Context, email UserEmail) err
|
||||
// Get user from Cognito to verify existence and get Subject ID
|
||||
cognitoUser, err := usermanagement.GetCognitoUser(context.Background(), cognitoClient, cognitoConfig.UserPoolID, string(email))
|
||||
if err != nil {
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito", "error", err, "email", email)
|
||||
errInfo := usermanagement.ClassifyCognitoError(err, string(email))
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito",
|
||||
"error", err,
|
||||
"email", email,
|
||||
"error_type", errInfo.ErrorType,
|
||||
"http_status", errInfo.HTTPStatus)
|
||||
usermanagement.LogUserAdminAction(
|
||||
ctrl.cfg.GetAuthLogger(),
|
||||
usermanagement.ActionDisable,
|
||||
@@ -908,12 +940,15 @@ func (ctrl *Controllers) DisableAdminUser(ctx echo.Context, email UserEmail) err
|
||||
string(email),
|
||||
"",
|
||||
usermanagement.ResultFailure,
|
||||
fmt.Sprintf("User not found in Cognito: %v", err),
|
||||
fmt.Sprintf("Cognito error (%s): %v", errInfo.ErrorType, err),
|
||||
ctx.Response().Header().Get(echo.HeaderXRequestID),
|
||||
)
|
||||
|
||||
return ctx.JSON(http.StatusNotFound, ErrorMessage{
|
||||
Message: fmt.Sprintf("User not found: %s", email),
|
||||
errorType := string(errInfo.ErrorType)
|
||||
return ctx.JSON(errInfo.HTTPStatus, ErrorMessage{
|
||||
Message: errInfo.Message,
|
||||
ErrorType: &errorType,
|
||||
Details: &errInfo.Details,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -995,7 +1030,12 @@ func (ctrl *Controllers) EnableAdminUser(ctx echo.Context, email UserEmail) erro
|
||||
// Get user from Cognito to verify existence and get Subject ID
|
||||
cognitoUser, err := usermanagement.GetCognitoUser(context.Background(), cognitoClient, cognitoConfig.UserPoolID, string(email))
|
||||
if err != nil {
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito", "error", err, "email", email)
|
||||
errInfo := usermanagement.ClassifyCognitoError(err, string(email))
|
||||
ctrl.cfg.GetAuthLogger().Error("Failed to get user from Cognito",
|
||||
"error", err,
|
||||
"email", email,
|
||||
"error_type", errInfo.ErrorType,
|
||||
"http_status", errInfo.HTTPStatus)
|
||||
usermanagement.LogUserAdminAction(
|
||||
ctrl.cfg.GetAuthLogger(),
|
||||
usermanagement.ActionEnable,
|
||||
@@ -1004,12 +1044,15 @@ func (ctrl *Controllers) EnableAdminUser(ctx echo.Context, email UserEmail) erro
|
||||
string(email),
|
||||
"",
|
||||
usermanagement.ResultFailure,
|
||||
fmt.Sprintf("User not found in Cognito: %v", err),
|
||||
fmt.Sprintf("Cognito error (%s): %v", errInfo.ErrorType, err),
|
||||
ctx.Response().Header().Get(echo.HeaderXRequestID),
|
||||
)
|
||||
|
||||
return ctx.JSON(http.StatusNotFound, ErrorMessage{
|
||||
Message: fmt.Sprintf("User not found: %s", email),
|
||||
errorType := string(errInfo.ErrorType)
|
||||
return ctx.JSON(errInfo.HTTPStatus, ErrorMessage{
|
||||
Message: errInfo.Message,
|
||||
ErrorType: &errorType,
|
||||
Details: &errInfo.Details,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user