Skip to content

Commit

Permalink
Merge pull request #45 from raktar-project/password-login
Browse files Browse the repository at this point in the history
Add custom CSS and logo for Cognito hosted UI
  • Loading branch information
davidsteiner authored Jul 27, 2023
2 parents 87ac181 + 995e323 commit 8f8a89d
Show file tree
Hide file tree
Showing 13 changed files with 756 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ deploy.sh
update-code.sh
infrastructure/.env
docker/dynamodb
**/.DS_Store
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ repos:
rev: v1.4.1
hooks:
- id: mypy
exclude: "^infrastructure/custom_resources/"
- repo: local
hooks:
- id: rust-linting
Expand Down
Empty file.
1 change: 1 addition & 0 deletions infrastructure/custom_resources/crhelper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from crhelper.resource_helper import FAILED, SUCCESS, CfnResource
79 changes: 79 additions & 0 deletions infrastructure/custom_resources/crhelper/log_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from __future__ import print_function

import json
import logging


def _json_formatter(obj):
"""Formatter for unserialisable values."""
return str(obj)


class JsonFormatter(logging.Formatter):
"""AWS Lambda Logging formatter.
Formats the log message as a JSON encoded string. If the message is a
dict it will be used directly. If the message can be parsed as JSON, then
the parse d value is used in the output record.
"""

def __init__(self, **kwargs):
super(JsonFormatter, self).__init__()
self.format_dict = {
"timestamp": "%(asctime)s",
"level": "%(levelname)s",
"location": "%(name)s.%(funcName)s:%(lineno)d",
}
self.format_dict.update(kwargs)
self.default_json_formatter = kwargs.pop("json_default", _json_formatter)

def format(self, record):
record_dict = record.__dict__.copy()
record_dict["asctime"] = self.formatTime(record)

log_dict = {k: v % record_dict for k, v in self.format_dict.items() if v}

if isinstance(record_dict["msg"], dict):
log_dict["message"] = record_dict["msg"]
else:
log_dict["message"] = record.getMessage()

# Attempt to decode the message as JSON, if so, merge it with the
# overall message for clarity.
try:
log_dict["message"] = json.loads(log_dict["message"])
except (TypeError, ValueError):
pass

if record.exc_info:
# Cache the traceback text to avoid converting it multiple times
# (it's constant anyway)
# from logging.Formatter:format
if not record.exc_text:
record.exc_text = self.formatException(record.exc_info)

if record.exc_text:
log_dict["exception"] = record.exc_text

json_record = json.dumps(log_dict, default=self.default_json_formatter)

if hasattr(json_record, "decode"): # pragma: no cover
json_record = json_record.decode("utf-8")

return json_record


def setup(level="DEBUG", formatter_cls=JsonFormatter, boto_level=None, **kwargs):
if formatter_cls:
for handler in logging.root.handlers:
handler.setFormatter(formatter_cls(**kwargs))

logging.root.setLevel(level)

if not boto_level:
boto_level = level

logging.getLogger("boto").setLevel(boto_level)
logging.getLogger("boto3").setLevel(boto_level)
logging.getLogger("botocore").setLevel(boto_level)
logging.getLogger("urllib3").setLevel(boto_level)
Loading

0 comments on commit 8f8a89d

Please sign in to comment.