Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functon which can redact device log fields #92

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion drivers/other/driver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const TuyaOAuth2Driver = require("../../lib/TuyaOAuth2Driver");
const TuyaOAuth2Util = require("../../lib/TuyaOAuth2Util");

module.exports = class TuyaOAuth2DriverOther extends TuyaOAuth2Driver {
onTuyaPairListDeviceFilter() {
Expand All @@ -11,7 +12,7 @@ module.exports = class TuyaOAuth2DriverOther extends TuyaOAuth2Driver {
const props = super.onTuyaPairListDeviceProperties(device);

const combinedSpecification = {
device: device,
device: TuyaOAuth2Util.redactFields(device),
specifications: specifications,
};

Expand Down
3 changes: 2 additions & 1 deletion lib/TuyaOAuth2Driver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { OAuth2Driver } = require('homey-oauth2app');
const TuyaOAuth2Util = require('./TuyaOAuth2Util');

/**
* @extends OAuth2Driver
Expand All @@ -14,7 +15,7 @@ class TuyaOAuth2Driver extends OAuth2Driver {
const devices = await oAuth2Client.getDevices();
const filteredDevices = devices
.filter(device => {
this.log('Device:', JSON.stringify(device));
this.log('Device:', JSON.stringify(TuyaOAuth2Util.redactFields(device)));
return this.onTuyaPairListDeviceFilter(device);
});
const listDevices = [];
Expand Down
17 changes: 17 additions & 0 deletions lib/TuyaOAuth2Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ class TuyaOAuth2Util {
return headers;
}

/*
* Redact sensitive fields when logging Device information
*/
static redactFields(device, additionalFields = []) {
const defaultFields = ['ip', 'lat', 'lon', 'owner_id', 'uid', 'uuid', 'local_key'];
const combinedFields = [...new Set([...defaultFields, ...additionalFields])];

const newObj = JSON.parse(JSON.stringify(device));
combinedFields.forEach((field) => {
if (newObj.hasOwnProperty(field)) {
newObj[field] = "<redacted>";
}
});

return newObj;
}

}

module.exports = TuyaOAuth2Util;
Loading