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

Grd93792 #686

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gradle
.idea
build
gradle.properties
vendor
201 changes: 83 additions & 118 deletions filter-plugin/logstash-filter-pubsub-bigquery-guardium/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ dependencies {
testImplementation group: 'org.mockito', name: 'mockito-all', version: versions.dependencies.mockitoAll
testImplementation 'org.junit.jupiter:junit-jupiter:' + versions.dependencies.junitJupiter
testImplementation 'org.jruby:jruby-complete:' + versions.dependencies.jrubyComplete
implementation fileTree(dir: GUARDIUM_UNIVERSALCONNECTOR_COMMONS_PATH, include: "common-*.*.*.jar")
implementation fileTree(dir: GUARDIUM_UNIVERSALCONNECTOR_COMMONS_PATH, include: "guardium-universalconnector-commons-*.*.*.jar")
implementation fileTree(dir: LOGSTASH_CORE_PATH, include: "build/libs/logstash-core-*.*.*.jar")
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: versions.dependencies.log4jCore
implementation group: 'org.json', name: 'json', version: versions.dependencies.json
implementation group: 'org.parboiled', name: 'parboiled-java', version: versions.dependencies.parboiledJava
implementation group: 'org.glassfish', name: 'javax.json', version: versions.dependencies.javaxJson
testImplementation fileTree(dir: GUARDIUM_UNIVERSALCONNECTOR_COMMONS_PATH, include: "common-*.*.*.jar")
testImplementation fileTree(dir: GUARDIUM_UNIVERSALCONNECTOR_COMMONS_PATH, include: "guardium-universalconnector-commons-*.*.*.jar")
}

clean {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Guardium_Big_Query_filter_Plugin",
"name": "BigQueryFilterPlugin",
"alias": "BigQuery Filter Plugin",
"type": "filter",
"pipeline_type":"pull",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"plugin_name": "BigQuery Over PubSub",
"plugin_name": "BigQueryFilterPlugin",
"help_link": "https://github.com/IBM/universal-connectors/blob/main/filter-plugin/logstash-filter-pubsub-bigquery-guardium/README.md",
"input_name": "Google_PubSub",
"input_parameters": [
Expand Down Expand Up @@ -31,7 +31,7 @@
}
}
],
"filter_name": "Guardium_Big_Query_filter_Plugin",
"filter_name": "BigQueryFilterPlugin",
"filter_parameters": [],
"credentials": [
{
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/
package com.ibm.guardium.bigquery;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/
package com.ibm.guardium.bigquery;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,21 @@ public class Parser {
*
*/
public static Record parseRecord(JsonObject inputJson) {
JsonObject protoPayload = null;
JsonObject metaDataJson = null;
JsonObject protoPayload = new JsonObject();
JsonObject metaDataJson = new JsonObject();

Record record = new Record();

if(inputJson.has(ApplicationConstants.PROTO_PAYLOAD) && inputJson.get(ApplicationConstants.PROTO_PAYLOAD).getAsJsonObject() != null && !inputJson.get(ApplicationConstants.PROTO_PAYLOAD).getAsJsonObject().entrySet().isEmpty());
{
if(inputJson.has(ApplicationConstants.PROTO_PAYLOAD) &&
inputJson.get(ApplicationConstants.PROTO_PAYLOAD).getAsJsonObject() != null &&
!inputJson.get(ApplicationConstants.PROTO_PAYLOAD).getAsJsonObject().entrySet().isEmpty()) {

protoPayload = inputJson.get(ApplicationConstants.PROTO_PAYLOAD).getAsJsonObject();
if(protoPayload.has(ApplicationConstants.METADATA) && protoPayload.get(ApplicationConstants.METADATA).getAsJsonObject() != null && !protoPayload.get(ApplicationConstants.METADATA).getAsJsonObject().entrySet().isEmpty());
{

if(protoPayload.has(ApplicationConstants.METADATA) &&
protoPayload.get(ApplicationConstants.METADATA).getAsJsonObject() != null &&
!protoPayload.get(ApplicationConstants.METADATA).getAsJsonObject().entrySet().isEmpty()) {

metaDataJson = protoPayload.get(ApplicationConstants.METADATA).getAsJsonObject();
}

Expand All @@ -96,15 +101,19 @@ public static Record parseRecord(JsonObject inputJson) {
String auditType = StringUtils.EMPTY;
String projectId = getTypeMetaData(inputJson);

if (protoPayload.has(ApplicationConstants.SERVICE_DATA) && !protoPayload.get(ApplicationConstants.SERVICE_DATA).isJsonNull())
if (protoPayload.has(ApplicationConstants.SERVICE_DATA) &&
!protoPayload.get(ApplicationConstants.SERVICE_DATA).isJsonNull()) {
auditType = ApplicationConstants.SERVICE_DATA;
else if (protoPayload.has(ApplicationConstants.METADATA) && !protoPayload.get(ApplicationConstants.METADATA).isJsonNull())
} else if (protoPayload.has(ApplicationConstants.METADATA) &&
!protoPayload.get(ApplicationConstants.METADATA).isJsonNull()) {
auditType = ApplicationConstants.METADATA;
}

if (metaDataJson != null && !metaDataJson.entrySet().isEmpty()) {
sql = getEventQueryFromMetaData(metaDataJson);
databaseName = getDatabaseNameFromMetaData(inputJson);
}

if (StringUtils.isEmpty(sql)) {
sql = getSql(sql, inputJson, protoPayload, metaDataJson);
}
Expand All @@ -117,7 +126,8 @@ else if (protoPayload.has(ApplicationConstants.METADATA) && !protoPayload.get(Ap


if (null == record.getException()) {
bigQueryDTO = parseAsConstruct(sql);
bigQueryDTO = parseAsData(sql);

record.setData(bigQueryDTO.getData());
if (StringUtils.isEmpty(databaseName) && !StringUtils.isEmpty(sql)) {
databaseName = !bigQueryDTO.getDBName().isEmpty() ? bigQueryDTO.getDBName().toArray()[0].toString()
Expand All @@ -127,6 +137,15 @@ else if (protoPayload.has(ApplicationConstants.METADATA) && !protoPayload.get(Ap
}
}
}
else {
int exceptionCode = getExceptionCode(protoPayload);

if (exceptionCode == 6 || exceptionCode == 5){
bigQueryDTO = parseAsData(sql);
record.setData(bigQueryDTO.getData());
}
}

record.setDbName(projectId + ":" + databaseName);
record.setAppUserName(appUserName);
record.setAccessor(parseAccessor(appUserName, inputJson, databaseName, sql,
Expand All @@ -140,6 +159,8 @@ else if (protoPayload.has(ApplicationConstants.METADATA) && !protoPayload.get(Ap
return record;
}



/**
* getDataSetNameBySQLQuery() method will perform operation on String inputs,
* set the expected value into respective dataset name and then return the value
Expand Down Expand Up @@ -287,6 +308,17 @@ private static BigQueryDTO parseAsConstruct(String sql) {
return bigQueryDTO;
}

private static BigQueryDTO parseAsData(String sql) {

BigQueryDTO bigQueryDTO = null;

bigQueryDTO = parseAsConstruct(sql);


return bigQueryDTO;

}

/**
* getSql() method will perform operation on String input,Picking the value from
* response log property based on the log property forming sql queries
Expand Down Expand Up @@ -725,6 +757,15 @@ private static String getExceptionCodeAndMessage(JsonObject protoPayload) {

}

private static int getExceptionCode(JsonObject protoPayload) {
JsonObject status = validateKeyExistance(protoPayload, ApplicationConstants.STATUS);
if (status.entrySet().isEmpty()) {
return -1;
}
return status.get(ApplicationConstants.CODE).getAsInt();

}

/**
* validateKeyExistance() method will perform operation on JsonObject jsonObject
* and String as a key object into JsonObject and return response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright IBM Corp. 2021, 2023 All rights reserved.
Copyright IBM Corp. 2021, 2025 All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/
package com.ibm.guardium.bigquery;
Expand Down
Binary file not shown.