Skip to content

Commit

Permalink
🐛 FIX: added sensitive filter for python logs
Browse files Browse the repository at this point in the history
  • Loading branch information
unl0ck committed Jul 15, 2024
1 parent c8cd1cc commit 0bf9224
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .bumpversion-edge.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "2.8.1"
current_version = "2.8.2"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
Expand Down
5 changes: 5 additions & 0 deletions GridboxConnectorAddon-edge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<!-- https://developers.home-assistant.io/docs/add-ons/presentation#keeping-a-changelog -->
## 2.8.2

### 🚀 Added

- sensitive filter

## 2.8.0

Expand Down
4 changes: 4 additions & 0 deletions GridboxConnectorAddon-edge/GridboxConnector/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ha_viessmann_gridbox_connector import HAViessmannGridboxConnector
import logging
from importlib.resources import files
from utils import SensitiveDataFilter
opens_file_path = '/data/options.json'
#logging.basicConfig(format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s - %(message)s', level=logging.getLevelName(os.getenv('LOG_LEVEL', 'INFO')))
logger = logging.getLogger(__name__)
Expand All @@ -14,6 +15,8 @@
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
# Benutzerdefinierten Filter zum Logger hinzufügen
logger.addFilter(SensitiveDataFilter())

def load_gridbox_config():
config_file = files('viessmann_gridbox_connector').joinpath('config.json')
Expand Down Expand Up @@ -61,5 +64,6 @@ def load_gridbox_config():
one_time_print = False
# Wait until fetch new values in seconds
else:
logger.warning("No data received")
gridboxConnector.init_auth()
time.sleep(WAIT)
24 changes: 24 additions & 0 deletions GridboxConnectorAddon-edge/GridboxConnector/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
import logging

class SensitiveDataFilter(logging.Filter):
def filter(self, record):
message = record.getMessage()
try:
# Versuchen, die Nachricht als JSON zu parsen
data = json.loads(message)
# Sensible Daten filtern, falls vorhanden
if 'username' in data:
data['username'] = '***'
if 'password' in data:
data['password'] = '***'
if 'id_token' in data:
data['id_token'] = '***'
if 'access_token' in data:
data['access_token'] = '***'
# Das modifizierte Dictionary zurück in einen String konvertieren
record.msg = json.dumps(data)
except json.JSONDecodeError:
# Wenn die Nachricht kein JSON ist, nichts tun
pass
return True
2 changes: 1 addition & 1 deletion GridboxConnectorAddon-edge/cloudSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.8.1",
"version": "2.8.2",
"urls": {
"login": "https://gridx.eu.auth0.com/oauth/token",
"gateways": "https://api.gridx.de/gateways",
Expand Down
2 changes: 1 addition & 1 deletion GridboxConnectorAddon-edge/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
---
name: Viessmann Gridbox Connector (edge)
version: "2.8.1"
version: "2.8.2"
slug: "gridbox_connector_edge"
description: "Viessmann Gridbox Connector (edge)"
url: "https://github.com/unl0ck/homeassistant-addon-viessmann-gridbox/tree/main/GridboxConnectorAddon-edge"
Expand Down
2 changes: 1 addition & 1 deletion GridboxConnectorAddon-edge/rootfs/share/cloudSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.8.1",
"version": "2.8.2",
"urls": {
"login": "https://gridx.eu.auth0.com/oauth/token",
"gateways": "https://api.gridx.de/gateways",
Expand Down

0 comments on commit 0bf9224

Please sign in to comment.