Skip to content

Settings

Settings API endpoints.

get_settings(service, current_user) async

List all settings with secrets masked.

This endpoint ensures default settings exist (self-healing) and returns all settings. Secrets are masked with asterisks for security. Logged in users only.

Parameters:

  • service (Annotated[SettingsService, Depends(get_settings_service)]) –

    The settings service instance.

  • current_user (Annotated[User, Depends(get_current_user)]) –

    The currently authenticated user.

Returns:

  • List[SettingResponse]

    List[SettingResponse]: A list of settings with masked secret values.

Raises:

  • TechnicalError

    If there is an error fetching the settings.

Source code in app/api/v1/endpoints/settings.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@router.get("/", response_model=List[SettingResponse])
async def get_settings(
    service: Annotated[SettingsService, Depends(get_settings_service)],
    current_user: Annotated[User, Depends(get_current_user)],
) -> List[SettingResponse]:
    """
    List all settings with secrets masked.

    This endpoint ensures default settings exist (self-healing) and returns all
    settings. Secrets are masked with asterisks for security.
    Logged in users only.

    Args:
        service: The settings service instance.
        current_user: The currently authenticated user.

    Returns:
        List[SettingResponse]: A list of settings with masked secret values.

    Raises:
        TechnicalError: If there is an error fetching the settings.
    """
    try:
        # Self-healing: ensure defaults exist
        await service.seed_defaults()

        settings = await service.get_all_settings()

        # Mask secrets for display
        return _mask_secrets(settings)

    except Exception as e:
        logger.error(f"❌ FAIL | get_settings | Error: {str(e)}", exc_info=True)
        raise TechnicalError(f"Failed to fetch settings: {e}") from e

update_settings(settings_in, service, current_admin) async

Batch update settings.

This endpoint allows administrators to update multiple settings at once. Secrets in the response are masked.

Parameters:

  • settings_in (List[SettingUpdate]) –

    A list of settings to update.

  • service (Annotated[SettingsService, Depends(get_settings_service)]) –

    The settings service instance.

  • current_admin (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated administrator.

Returns:

  • List[SettingResponse]

    List[SettingResponse]: A list of the updated settings with masked secret values.

Raises:

  • TechnicalError

    If there is an error updating the settings.

Source code in app/api/v1/endpoints/settings.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
@router.put("/", response_model=List[SettingResponse])
async def update_settings(
    settings_in: List[SettingUpdate],
    service: Annotated[SettingsService, Depends(get_settings_service)],
    current_admin: Annotated[User, Depends(get_current_admin)],
) -> List[SettingResponse]:
    """
    Batch update settings.

    This endpoint allows administrators to update multiple settings at once.
    Secrets in the response are masked.

    Args:
        settings_in: A list of settings to update.
        service: The settings service instance.
        current_admin: The currently authenticated administrator.

    Returns:
        List[SettingResponse]: A list of the updated settings with masked secret values.

    Raises:
        TechnicalError: If there is an error updating the settings.
    """
    try:
        # Convert Pydantic schemas to list of dicts for service
        updates = [s.model_dump(exclude_unset=True) for s in settings_in]

        # Transactional Batch Update
        updated_settings = await service.update_settings_batch(updates)

        # Mask secrets in response
        return _mask_secrets(updated_settings)

    except Exception as e:
        logger.error(f"❌ FAIL | update_settings | Error: {str(e)}", exc_info=True)
        raise TechnicalError(f"Failed to update settings: {e}") from e