Skip to content

Commit

Permalink
🐛 FIX: fixed hopefully now sensitive data filter
Browse files Browse the repository at this point in the history
  • Loading branch information
unl0ck committed Dec 26, 2024
1 parent 5dc2bd0 commit beea236
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 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.11.29"
current_version = "2.11.30"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
Expand Down
10 changes: 10 additions & 0 deletions GridboxConnectorAddon-edge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<!-- https://developers.home-assistant.io/docs/add-ons/presentation#keeping-a-changelog -->

## 2.11.30

### 🚀 Added

- make possible the disable and enable telemetry

### 🔨 Fixed

- sensitive filter fixed

## 2.11.28

### 🔨 Fixed
Expand Down
14 changes: 14 additions & 0 deletions GridboxConnectorAddon-edge/GridboxConnector/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,19 @@ def test_main_heater(self, mock_retrieve_live_data, mock_init, mock_init_auth,mo
viessmann_gridbox_connector.update_sensors(result[0])
mock_heater_sensor.assert_called_once_with(3676,70.9)

def test_logger(self):
import os
import logging
from utils import SensitiveDataFilter
logger = logging.getLogger(__name__)
logger.setLevel(logging.getLevelName(os.getenv('LOG_LEVEL', 'INFO')))
formatter = logging.Formatter('%(asctime)s %(filename)s:%(lineno)d %(levelname)s - %(message)s')
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
logger.addFilter(SensitiveDataFilter())
login_message = "{'grant_type': 'http://auth0.com/oauth/grant-type/password-realm', 'username': 'username@username', 'password': 'UltraSecret', 'audience': 'my.gridx', 'client_id': 'oZpr934Ikn8OZOHTJEcrgXkjio0I0Q7b', 'scope': 'email openid', 'realm': 'viessmann-authentication-db', 'client_secret': ''}"
logger.info(login_message)

if __name__ == '__main__':
unittest.main()
15 changes: 8 additions & 7 deletions GridboxConnectorAddon-edge/GridboxConnector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ class SensitiveDataFilter(logging.Filter):
def filter(self, record):
message = record.getMessage()
try:
message_json = json.loads(message)
# Versuche die Nachricht als Python-Dictionary zu parsen
message_dict = ast.literal_eval(message)
# Sensible Daten filtern, falls vorhanden
sensitive_keys = ['username', 'password', 'id_token', 'access_token', 'client_id']
for key in sensitive_keys:
if key in message_json:
message_json[key] = '***'
# Das modifizierte JSON-Objekt zurück in einen String konvertieren
record.msg = json.dumps(message_json)
except json.JSONDecodeError:
logging.error("Error decoding JSON message")
if key in message_dict:
message_dict[key] = '***'
# Das modifizierte Dictionary zurück in einen String konvertieren
record.msg = str(message_dict)
except (ValueError, SyntaxError):
logging.error(f"Error parsing message: {message}")
except Exception as e:
logging.error(f"Error filtering sensitive data: {e}")
return True
Expand Down
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.11.29",
"version": "2.11.30",
"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.11.29"
version: "2.11.30"
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.11.29",
"version": "2.11.30",
"urls": {
"login": "https://gridx.eu.auth0.com/oauth/token",
"gateways": "https://api.gridx.de/gateways",
Expand Down

0 comments on commit beea236

Please sign in to comment.