Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up error output when validating settings values #265

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/overview/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The :doc:`file_systems` page provides an overview of supported file system types
],
"email_from": "[email protected]",
"email_domain": "@domain.com",
"email_admins": ["[email protected]"]
"admin_emails": ["[email protected]"]
}

Once the application has been configured, you can check the configuration file is valid by running:
Expand Down
11 changes: 9 additions & 2 deletions quota_notifier/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import logging
import logging.config
import sys
from argparse import ArgumentParser
from pathlib import Path
from smtplib import SMTP
Expand Down Expand Up @@ -116,7 +117,7 @@ def _configure_logging(cls, console_log_level: int) -> None:
'level': 'CRITICAL',
'mailhost': ApplicationSettings.get('smtp_host'),
'fromaddr': ApplicationSettings.get('email_from'),
'toaddrs': ApplicationSettings.get('email_admins'),
'toaddrs': ApplicationSettings.get('admin_emails'),
'subject': 'Quota Notifier - Admin Notification'
}
},
Expand Down Expand Up @@ -167,7 +168,13 @@ def run(cls, validate: bool = False, verbosity: int = 0, debug: bool = False) ->
"""

# Configure application settings
cls._load_settings(force_debug=debug)
try:
cls._load_settings(force_debug=debug)

except Exception as e:
print(e)
sys.exit(0)

if validate:
return

Expand Down
14 changes: 2 additions & 12 deletions quota_notifier/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Module Contents
---------------
"""

import logging
from pathlib import Path
from tempfile import NamedTemporaryFile
Expand Down Expand Up @@ -180,7 +179,7 @@ class SettingsSchema(BaseSettings):
description=('String to append to usernames when generating user email addresses. '
'The leading `@` is optional.'))

email_admins: List[str] = Field(
admin_emails: List[str] = Field(
title='Administrator Emails',
default=[],
description='Admin users to contact when the application encounters a critical issue.'
Expand Down Expand Up @@ -237,16 +236,7 @@ def set_from_file(cls, path: Path) -> None:
path: Path to load settings from
"""

logging.debug(f'Looking for settings file: {path.resolve()}')

try:
cls._parsed_settings = SettingsSchema.parse_file(path)

except Exception:
logging.error('settings file is invalid')
raise

logging.info(f'Loaded settings from file: {path.resolve()}')
cls._parsed_settings = SettingsSchema.model_validate_json(path.read_text())

@classmethod
def set(cls, **kwargs) -> None:
Expand Down