Skip to content

Commit

Permalink
Clean up error output when validating settings values (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort committed Jul 25, 2023
1 parent 2260306 commit 988ba1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
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

0 comments on commit 988ba1c

Please sign in to comment.