Skip to content

Commit b2e8b14

Browse files
authored
Remove sensitive data from component logs (#54)
* Remove sensitive data from component logs
1 parent aedd967 commit b2e8b14

22 files changed

+93
-79
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# JDBC Component
2+
## 2.4.1 (September 25, 2020)
3+
4+
* Remove sensitive data from component logs
5+
26
## 2.3.2 (October 21, 2019)
37

48
* Add rebound mechanism in case of deadlocks for actions: Insert, UpsertByPK, DeleteByPK

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group = 'io.elastic'
2-
version = '2.4.0'
2+
version = '2.4.1'
33
apply plugin: 'java'
44
apply plugin: 'idea'
55
apply plugin: 'eclipse'

src/main/java/io/elastic/jdbc/actions/CreateOrUpdateRecord.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public void execute(ExecutionParameters parameters) {
4040
if (!(!body.has(idColumn) || body.get(idColumn).isJsonNull() || body.get(idColumn).getAsString().isEmpty())) {
4141
idColumnValue = body.get(idColumn).getAsString();
4242
}
43-
logger.info("ID column value: {}", idColumnValue);
43+
logger.trace("ID column value: {}", idColumnValue);
4444
String db = configuration.get(UtilsOld.CFG_DB_ENGINE).getAsString();
4545
isOracle = db.equals(EnginesOld.ORACLE.name().toLowerCase());
4646
try {
4747
connection = UtilsOld.getConnection(configuration);
4848
columnTypes = getColumnTypes(tableName);
49-
logger.info("Detected column types: " + columnTypes);
49+
logger.debug("Detected column types: " + columnTypes);
5050
if (recordExists(tableName, idColumn, idColumnValue)) {
5151
makeUpdate(tableName, idColumn, idColumnValue, body);
5252
} else {
@@ -151,7 +151,7 @@ private boolean recordExists(String tableName, String idColumn, String idValue)
151151
String query = "SELECT COUNT(*) FROM " + tableName + " WHERE " + idColumn + " = ?";
152152
PreparedStatement statement = connection.prepareStatement(query);
153153
setStatementParam(statement, 1, idColumn, idValue);
154-
logger.info("{}",statement);
154+
logger.trace("{}",statement);
155155
ResultSet rs = statement.executeQuery();
156156
rs.next();
157157
return rs.getInt(1) > 0;
@@ -173,7 +173,7 @@ private void makeInsert(String tableName, JsonObject body) throws SQLException {
173173
setStatementParam(statement, i, entry.getKey(), entry.getValue().getAsString());
174174
i++;
175175
}
176-
logger.debug("{}",statement);
176+
logger.trace("{}",statement);
177177
statement.execute();
178178
}
179179

src/main/java/io/elastic/jdbc/actions/CustomQuery.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public void execute(ExecutionParameters parameters) {
3333
final JsonObject body = parameters.getMessage().getBody();
3434
final String dbEngine = Utils.getDbEngine(configuration);
3535
final String queryString = body.getString("query");
36-
LOGGER.info("Found dbEngine: '{}' and query: '{}'", dbEngine, queryString);
36+
LOGGER.info("Found dbEngine: '{}'", dbEngine);
37+
LOGGER.trace("Query: '{}'", queryString);
3738

3839
List<Message> messages = new ArrayList<>();
3940
try (Connection connection = Utils.getConnection(configuration)) {

src/main/java/io/elastic/jdbc/actions/DeleteRowByPrimaryKey.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void execute(ExecutionParameters parameters) {
6464
}
6565

6666
for (Map.Entry<String, JsonValue> entry : body.entrySet()) {
67-
LOGGER.info("{} = {}", entry.getKey(), entry.getValue());
67+
LOGGER.trace("{} = {}", entry.getKey(), entry.getValue());
6868
primaryKey.append(entry.getKey());
6969
primaryValue.append(entry.getValue());
7070
primaryKeysCount++;
@@ -75,23 +75,23 @@ public void execute(ExecutionParameters parameters) {
7575
LOGGER.info("Executing delete row by primary key action");
7676
boolean isOracle = dbEngine.equals(Engines.ORACLE.name().toLowerCase());
7777
Utils.columnTypes = Utils.getColumnTypes(connection, isOracle, tableName);
78-
LOGGER.info("Detected column types: " + Utils.columnTypes);
78+
LOGGER.debug("Detected column types: " + Utils.columnTypes);
7979
try {
8080
QueryFactory queryFactory = new QueryFactory();
8181
Query query = queryFactory.getQuery(dbEngine);
82-
LOGGER.info("Lookup parameters: {} = {}", primaryKey.toString(), primaryValue.toString());
82+
LOGGER.trace("Lookup parameters: {} = {}", primaryKey.toString(), primaryValue.toString());
8383
query.from(tableName).lookup(primaryKey.toString(), primaryValue.toString());
8484
checkConfig(configuration);
8585
JsonObject row = query.executeLookup(connection, body);
8686

8787
for (Map.Entry<String, JsonValue> entry : configuration.entrySet()) {
88-
LOGGER.info("Key = " + entry.getKey() + " Value = " + entry.getValue());
88+
LOGGER.trace("Key = " + entry.getKey() + " Value = " + entry.getValue());
8989
}
9090

9191
if (row.size() != 0) {
9292
int result = query.executeDelete(connection, body);
9393
if (result == 1) {
94-
LOGGER.info("Emitting data {}", row);
94+
LOGGER.trace("Emitting data {}", row);
9595
parameters.getEventEmitter().emitData(new Message.Builder().body(row).build());
9696
} else {
9797
LOGGER.info("Unexpected result");
@@ -112,7 +112,7 @@ public void execute(ExecutionParameters parameters) {
112112
.add(PROPERTY_ID_COLUMN, primaryKey.toString())
113113
.add(PROPERTY_LOOKUP_VALUE, primaryValue.toString())
114114
.add(PROPERTY_NULLABLE_RESULT, nullableResult).build();
115-
LOGGER.info("Emitting new snapshot {}", snapshot.toString());
115+
LOGGER.trace("Emitting new snapshot {}", snapshot.toString());
116116
parameters.getEventEmitter().emitSnapshot(snapshot);
117117
} catch (SQLException e) {
118118
if (Utils.reboundIsEnabled(configuration)) {
@@ -124,11 +124,12 @@ public void execute(ExecutionParameters parameters) {
124124
return;
125125
}
126126
}
127-
LOGGER.error("Failed to make request", e.toString());
127+
LOGGER.error("Failed to make request..");
128+
LOGGER.trace("Failed to make request {}", e.toString());
128129
throw new RuntimeException(e);
129130
}
130131
} catch (SQLException e) {
131-
LOGGER.error("Failed to close connection", e.toString());
132+
LOGGER.error("Failed to close connection {}", e.toString());
132133
}
133134
} else {
134135
LOGGER.error("Error: Should be one Primary Key");

src/main/java/io/elastic/jdbc/actions/InsertAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public void execute(ExecutionParameters parameters) {
3131
final String dbEngine = Utils.getDbEngine(configuration);
3232
final boolean isOracle = dbEngine.equals(Engines.ORACLE.name().toLowerCase());
3333
final String tableName = Utils.getTableName(configuration, isOracle);
34-
LOGGER.info("Found dbEngine: '{}' and tableName: '{}'", dbEngine, tableName);
34+
LOGGER.info("Found dbEngine: '{}'", dbEngine);
3535
try (Connection connection = Utils.getConnection(configuration)) {
3636
Utils.columnTypes = Utils.getColumnTypes(connection, isOracle, tableName);
37-
LOGGER.info("Detected column types: " + Utils.columnTypes);
38-
LOGGER.info("Inserting in table '{}' values '{}'", tableName, body);
37+
LOGGER.debug("Detected column types: " + Utils.columnTypes);
38+
LOGGER.trace("Inserting in table '{}' values '{}'", tableName, body);
3939
QueryFactory queryFactory = new QueryFactory();
4040
Query query = queryFactory.getQuery(dbEngine);
4141
query.from(tableName);
@@ -54,7 +54,7 @@ public void execute(ExecutionParameters parameters) {
5454
JsonObject result = Json.createObjectBuilder()
5555
.add("result", true)
5656
.build();
57-
LOGGER.info("Emit data= {}", result);
57+
LOGGER.trace("Emit data= {}", result);
5858
parameters.getEventEmitter().emitData(new Message.Builder().body(result).build());
5959
LOGGER.info("Insert action is successfully executed");
6060
}

src/main/java/io/elastic/jdbc/actions/LookupRowByPrimaryKey.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void execute(ExecutionParameters parameters) {
6767
boolean isOracle = dbEngine.equals(Engines.ORACLE.name().toLowerCase());
6868

6969
for (Map.Entry<String, JsonValue> entry : body.entrySet()) {
70-
LOGGER.info("{} = {}", entry.getKey(), entry.getValue());
70+
LOGGER.trace("{} = {}", entry.getKey(), entry.getValue());
7171
primaryKey.append(entry.getKey());
7272
primaryValue.append(entry.getValue());
7373
primaryKeysCount++;
@@ -78,25 +78,25 @@ public void execute(ExecutionParameters parameters) {
7878
try (Connection connection = Utils.getConnection(configuration)) {
7979
LOGGER.info("Executing lookup row by primary key action");
8080
Utils.columnTypes = Utils.getColumnTypes(connection, isOracle, tableName);
81-
LOGGER.info("Detected column types: " + Utils.columnTypes);
81+
LOGGER.debug("Detected column types: " + Utils.columnTypes);
8282
try {
8383
QueryFactory queryFactory = new QueryFactory();
8484
Query query = queryFactory.getQuery(dbEngine);
85-
LOGGER.info("Lookup parameters: {} = {}", primaryKey.toString(), primaryValue.toString());
85+
LOGGER.trace("Lookup parameters: {} = {}", primaryKey.toString(), primaryValue.toString());
8686
query.from(tableName).lookup(primaryKey.toString(), primaryValue.toString());
8787
checkConfig(configuration);
8888

8989
JsonObject row = query.executeLookup(connection, body);
9090
if (row.size() != 0) {
9191
LOGGER.info("Emitting data");
92-
LOGGER.info(row.toString());
92+
LOGGER.trace(row.toString());
9393
parameters.getEventEmitter().emitData(new Message.Builder().body(row).build());
9494
}
9595
if (row.size() == 0 && nullableResult) {
9696
JsonObjectBuilder emptyResBuilder = Json.createObjectBuilder();
9797
emptyResBuilder.add("empty dataset", JsonValue.NULL);
9898
LOGGER.info("Emitting data");
99-
LOGGER.info(JSON.stringify(emptyResBuilder.build()));
99+
LOGGER.trace(JSON.stringify(emptyResBuilder.build()));
100100
parameters.getEventEmitter().emitData(new Message.Builder().body(emptyResBuilder.build()).build());
101101
} else if (row.size() == 0 && !nullableResult) {
102102
LOGGER.info("Empty response. Error message will be returned");
@@ -107,14 +107,15 @@ public void execute(ExecutionParameters parameters) {
107107
.add(PROPERTY_ID_COLUMN, primaryKey.toString())
108108
.add(PROPERTY_LOOKUP_VALUE, primaryValue.toString())
109109
.add(PROPERTY_NULLABLE_RESULT, nullableResult).build();
110-
LOGGER.info("Emitting new snapshot {}", snapshot.toString());
110+
LOGGER.trace("Emitting new snapshot {}", snapshot.toString());
111111
parameters.getEventEmitter().emitSnapshot(snapshot);
112112
} catch (SQLException e) {
113-
LOGGER.error("Failed to make request", e.toString());
113+
LOGGER.error("Failed to make request");
114+
LOGGER.trace("Error: {}", e.toString());
114115
throw new RuntimeException(e);
115116
}
116117
} catch (SQLException e) {
117-
LOGGER.error("Failed to close connection", e.toString());
118+
LOGGER.error("Failed to close connection: {}", e.toString());
118119
}
119120
} else {
120121
LOGGER.error("Error: Should be one Primary Key");

src/main/java/io/elastic/jdbc/actions/SelectAction.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ public void execute(ExecutionParameters parameters) {
4444
}
4545

4646
Utils.columnTypes = Utils.getVariableTypes(sqlQuery);
47-
LOGGER.info("Detected column types: " + Utils.columnTypes);
47+
LOGGER.debug("Detected column types: " + Utils.columnTypes);
4848
LOGGER.info("Executing select action");
4949
try {
5050
QueryFactory queryFactory = new QueryFactory();
5151
Query query = queryFactory.getQuery(dbEngine);
5252
sqlQuery = Query.preProcessSelect(sqlQuery);
53-
LOGGER.info("SQL Query: {}", sqlQuery);
53+
LOGGER.trace("SQL Query: {}", sqlQuery);
5454
ArrayList<JsonObject> resultList;
5555
try(Connection connection = Utils.getConnection(configuration)){
5656
resultList = query.executeSelectQuery(connection, sqlQuery, body);
5757
}
5858
for (int i = 0; i < resultList.size(); i++) {
59-
LOGGER.info("Columns count: {} from {}", i + 1, resultList.size());
60-
LOGGER.info("Emitting data {}", resultList.get(i).toString());
59+
LOGGER.trace("Columns count: {} from {}", i + 1, resultList.size());
60+
LOGGER.trace("Emitting data {}", resultList.get(i).toString());
6161
parameters.getEventEmitter()
6262
.emitData(new Message.Builder().body(resultList.get(i)).build());
6363
}
@@ -66,7 +66,7 @@ public void execute(ExecutionParameters parameters) {
6666
resultList.add(Json.createObjectBuilder()
6767
.add("empty dataset", "no data")
6868
.build());
69-
LOGGER.info("Emitting data {}", resultList.get(0));
69+
LOGGER.trace("Emitting data {}", resultList.get(0));
7070
parameters.getEventEmitter()
7171
.emitData(new Message.Builder().body(resultList.get(0)).build());
7272
} else if (resultList.size() == 0 && !nullableResult) {
@@ -78,7 +78,7 @@ public void execute(ExecutionParameters parameters) {
7878
.add(PROPERTY_SKIP_NUMBER, skipNumber + resultList.size())
7979
.add(SQL_QUERY_VALUE, sqlQuery)
8080
.add(PROPERTY_NULLABLE_RESULT, nullableResult).build();
81-
LOGGER.info("Emitting new snapshot {}", snapshot.toString());
81+
LOGGER.trace("Emitting new snapshot {}", snapshot.toString());
8282
parameters.getEventEmitter().emitSnapshot(snapshot);
8383
} catch (SQLException e) {
8484
throw new RuntimeException(e);

src/main/java/io/elastic/jdbc/actions/UpsertRowByPrimaryKey.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ public void execute(ExecutionParameters parameters) {
7979
if (primaryKeysCount == 1) {
8080
LOGGER.info("Executing upsert row by primary key action");
8181
Utils.columnTypes = Utils.getColumnTypes(connection, isOracle, tableName);
82-
LOGGER.info("Detected column types: " + Utils.columnTypes);
82+
LOGGER.debug("Detected column types: " + Utils.columnTypes);
8383
QueryFactory queryFactory = new QueryFactory();
8484
Query query = queryFactory.getQuery(dbEngine);
8585
LOGGER
86-
.info("Execute upsert parameters by PK: '{}' = {}", primaryKey, body.get(primaryKey));
86+
.trace("Execute upsert parameters by PK: '{}' = {}", primaryKey, body.get(primaryKey));
8787
query.from(tableName);
8888
resultRow = query.executeUpsert(connection, primaryKey, body);
89-
LOGGER.info("Emit data= {}", resultRow);
89+
LOGGER.trace("Emit data= {}", resultRow);
9090
parameters.getEventEmitter().emitData(new Message.Builder().body(resultRow).build());
9191
snapshot = Json.createObjectBuilder().add(PROPERTY_TABLE_NAME, tableName).build();
92-
LOGGER.info("Emitting new snapshot {}", snapshot.toString());
92+
LOGGER.trace("Emitting new snapshot {}", snapshot.toString());
9393
parameters.getEventEmitter().emitSnapshot(snapshot);
9494
} else if (primaryKeysCount == 0) {
9595
LOGGER.error("Error: Table has not Primary Key. Should be one Primary Key");

src/main/java/io/elastic/jdbc/providers/ColumnNamesForInsertProvider.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class ColumnNamesForInsertProvider implements DynamicMetadataProvider {
2626
public JsonObject getMetaModel(JsonObject configuration) {
2727
LOGGER.info("Getting metadata...");
2828
JsonObject inMetadata = getInputMetaData(configuration);
29-
LOGGER.info("Generated input metadata {}", inMetadata);
29+
LOGGER.trace("Generated input metadata {}", inMetadata);
3030
JsonObject outMetadata = getOutputMetaData();
31-
LOGGER.info("Generated output metadata {}", outMetadata);
31+
LOGGER.trace("Generated output metadata {}", outMetadata);
3232
return Json.createObjectBuilder()
3333
.add("out", outMetadata)
3434
.add("in", inMetadata)
@@ -61,10 +61,10 @@ private JsonObject getInputMetaData(JsonObject configuration) {
6161
try (Connection connection = Utils.getConnection(configuration)) {
6262
DatabaseMetaData dbMetaData;
6363
try {
64-
LOGGER.info("Getting DatabaseMetaData for table: '{}'...", tableName);
64+
LOGGER.trace("Getting DatabaseMetaData for table: '{}'...", tableName);
6565
dbMetaData = connection.getMetaData();
6666
} catch (SQLException e) {
67-
LOGGER.error("Failed while getting DatabaseMetaData. Error: " + e.getMessage());
67+
LOGGER.error("Failed while getting DatabaseMetaData");
6868
throw new RuntimeException(e);
6969
}
7070

@@ -78,21 +78,21 @@ private JsonObject getInputMetaData(JsonObject configuration) {
7878
final String catalog = isMySql ? configuration.getString("databaseName") : null;
7979
ArrayList<String> primaryKeysNames = Utils
8080
.getPrimaryKeyNames(catalog, schemaNamePattern, tableNamePattern, dbMetaData);
81-
LOGGER.info("Found primary key name(s): '{}'", primaryKeysNames);
81+
LOGGER.trace("Found primary key name(s): '{}'", primaryKeysNames);
8282

8383
LOGGER.info("Starting processing columns...");
8484
while (resultSet.next()) {
8585
final String fieldName = resultSet.getString("COLUMN_NAME");
8686
final int sqlDataType = resultSet.getInt("DATA_TYPE");
8787
final String fieldType = Utils.convertType(sqlDataType);
88-
LOGGER.info("Found column: name={}, type={}", fieldName, fieldType);
88+
LOGGER.trace("Found column: name={}, type={}", fieldName, fieldType);
8989

9090
final boolean isPrimaryKey = Utils.isPrimaryKey(primaryKeysNames, fieldName);
9191
final boolean isNotNull = Utils.isNotNull(resultSet);
9292
final boolean isAutoincrement = Utils.isAutoincrement(resultSet, isOracle);
9393
final boolean isCalculated = Utils.isCalculated(resultSet, dbEngine);
9494
LOGGER
95-
.info(
95+
.trace(
9696
"Field '{}': isPrimaryKey={}, isNotNull={}, isAutoincrement={}, isCalculated={}",
9797
fieldName, isPrimaryKey, isNotNull, isAutoincrement,
9898
isCalculated);
@@ -104,7 +104,7 @@ private JsonObject getInputMetaData(JsonObject configuration) {
104104
.add("title", fieldName)
105105
.add("type", fieldType)
106106
.build();
107-
LOGGER.debug("Field description '{}': {}", fieldName, field);
107+
LOGGER.trace("Field description '{}': {}", fieldName, field);
108108
propertiesIn.add(fieldName, field);
109109
isEmpty = false;
110110
}

0 commit comments

Comments
 (0)