Skip to content

Commit fa66f75

Browse files
committed
feat: add a conf module that reads .env and environment variable overrides
1 parent cccb690 commit fa66f75

File tree

5 files changed

+71
-20
lines changed

5 files changed

+71
-20
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
SHELL := /bin/bash
12
PYTHON = python3
23
PIP = $(PYTHON) -m pip
4+
5+
ifneq ("$(wildcard .env)","")
6+
include .env
7+
endif
8+
39
.PHONY: pre-commit requirements init clean report test build release-test release-prod help
410

511
# Default target executed when no arguments are given to make.
612
all: help
713

14+
analyze:
15+
cloc . --exclude-ext=svg,json,zip --vcs=git
16+
817
init:
918
make clean && \
1019
npm install && \

requirements/local.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ bandit==1.7.5
1616
pydocstringformatter==0.7.3
1717
tox==4.11.4
1818
codespell==2.2.6
19+
20+
# project dependencies
21+
# ------------
22+
python-decouple==3.8

secure_logger/conf.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
"""Module conf.py"""
3+
4+
import logging
5+
6+
from decouple import config
7+
8+
from secure_logger.exceptions import ConfigurationError
9+
10+
11+
_DEFAULT_SENSITIVE_KEYS = [
12+
"password",
13+
"token",
14+
"client_id",
15+
"client_secret",
16+
"Authorization",
17+
"secret",
18+
"access_key_id",
19+
"secret_access_key",
20+
"access-key-id",
21+
"secret-access-key",
22+
"aws_access_key_id",
23+
"aws_secret_access_key",
24+
"aws-access-key-id",
25+
"aws-secret-access-key",
26+
]
27+
_DEFAULT_REDACTION_MESSAGE = "*** -- secure_logger() -- ***"
28+
_DEFAULT_INDENT = 4
29+
30+
DEFAULT_SENSITIVE_KEYS = config("DEFAULT_SENSITIVE_KEYS", default=_DEFAULT_SENSITIVE_KEYS, cast=list)
31+
DEFAULT_REDACTION_MESSAGE = config("DEFAULT_REDACTION_MESSAGE", default=_DEFAULT_REDACTION_MESSAGE)
32+
DEFAULT_INDENT = config("DEFAULT_INDENT", default=_DEFAULT_INDENT, cast=int)
33+
34+
if not isinstance(DEFAULT_SENSITIVE_KEYS, list):
35+
raise ConfigurationError("DEFAULT_SENSITIVE_KEYS must be a list")
36+
if not isinstance(DEFAULT_REDACTION_MESSAGE, str):
37+
raise ConfigurationError("DEFAULT_REDACTION_MESSAGE must be a string")
38+
if not isinstance(DEFAULT_INDENT, int):
39+
raise ConfigurationError("DEFAULT_INDENT must be an integer")
40+
41+
logging.debug("DEFAULT_SENSITIVE_KEYS: %s", DEFAULT_SENSITIVE_KEYS)
42+
logging.debug("DEFAULT_REDACTION_MESSAGE: %s", DEFAULT_REDACTION_MESSAGE)
43+
logging.debug("DEFAULT_INDENT: %s", DEFAULT_INDENT)

secure_logger/exceptions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
"""Module exceptions.py"""
3+
4+
5+
class ConfigurationError(Exception):
6+
"""Exception raised for errors in the configuration."""
7+
8+
def __init__(self, message):
9+
self.message = message
10+
super().__init__(self.message)

secure_logger/masked_dict.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,11 @@
55
import json
66
from unittest.mock import MagicMock
77

8-
9-
# our stuff
10-
DEFAULT_SENSITIVE_KEYS = [
11-
"password",
12-
"token",
13-
"client_id",
14-
"client_secret",
15-
"Authorization",
16-
"secret",
17-
"access_key_id",
18-
"secret_access_key",
19-
"access-key-id",
20-
"secret-access-key",
21-
"aws_access_key_id",
22-
"aws_secret_access_key",
23-
"aws-access-key-id",
24-
"aws-secret-access-key",
25-
]
26-
DEFAULT_REDACTION_MESSAGE = "*** -- secure_logger() -- ***"
27-
DEFAULT_INDENT = 4
8+
from secure_logger.conf import (
9+
DEFAULT_INDENT,
10+
DEFAULT_REDACTION_MESSAGE,
11+
DEFAULT_SENSITIVE_KEYS,
12+
)
2813

2914

3015
class _JSONEncoder(json.JSONEncoder):

0 commit comments

Comments
 (0)