From 34a654ba7b0071935e1288e08d5bb3e02509663a Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Fri, 30 Dec 2022 01:16:42 -0400 Subject: [PATCH 1/3] fix: don't convert config values to strings --- .../airbyte/server/handlers/OAuthHandler.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/OAuthHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/OAuthHandler.java index 5e528cf5a230..6e8d9842d35a 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/OAuthHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/OAuthHandler.java @@ -9,6 +9,7 @@ import static io.airbyte.metrics.lib.ApmTraceConstants.Tags.WORKSPACE_ID_KEY; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.annotations.VisibleForTesting; import io.airbyte.analytics.TrackingClient; import io.airbyte.api.model.generated.CompleteDestinationOAuthRequest; @@ -40,7 +41,6 @@ import io.airbyte.validation.json.JsonValidationException; import java.io.IOException; import java.net.http.HttpClient; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -321,23 +321,24 @@ Map buildJsonPathFromOAuthFlowInitParameters(final Map result = new HashMap<>(); - - Jsons.deserializeToStringMap(oAuthInputConfigurationFromInput) - .forEach((k, v) -> { - if (AirbyteSecretConstants.SECRETS_MASK.equals(v)) { - if (oAuthInputConfigurationFromDB.has(k)) { - result.put(k, oAuthInputConfigurationFromDB.get(k).textValue()); - } else { - LOGGER.warn("Missing the key {} in the config store in DB", k); - } - - } else { - result.put(k, v); - } - }); - - return Jsons.jsonNode(result); + final ObjectNode result = (ObjectNode) Jsons.emptyObject(); + + oAuthInputConfigurationFromInput.fields().forEachRemaining(entry -> { + final String k = entry.getKey(); + final JsonNode v = entry.getValue(); + + if (AirbyteSecretConstants.SECRETS_MASK.equals(v.textValue())) { + if (oAuthInputConfigurationFromDB.has(k)) { + result.set(k, oAuthInputConfigurationFromDB.get(k)); + } else { + LOGGER.warn("Missing the key {} in the config store in DB", k); + } + } else { + result.set(k, v); + } + }); + + return result; } @VisibleForTesting From a2a15944bf45d19612209c59c78417ffb87b94a1 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Fri, 30 Dec 2022 01:16:52 -0400 Subject: [PATCH 2/3] tests --- .../io/airbyte/server/handlers/OAuthHandlerTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/airbyte-server/src/test/java/io/airbyte/server/handlers/OAuthHandlerTest.java b/airbyte-server/src/test/java/io/airbyte/server/handlers/OAuthHandlerTest.java index 4b6ad812cac0..490f42680bda 100644 --- a/airbyte-server/src/test/java/io/airbyte/server/handlers/OAuthHandlerTest.java +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/OAuthHandlerTest.java @@ -205,7 +205,8 @@ void testGetOauthFromDBIfNeeded() { """ { "testMask": "**********", - "testNotMask": "this" + "testNotMask": "this", + "testOtherType": true } """); @@ -213,7 +214,8 @@ void testGetOauthFromDBIfNeeded() { """ { "testMask": "mask", - "testNotMask": "notThis" + "testNotMask": "notThis", + "testOtherType": true } """); @@ -221,7 +223,8 @@ void testGetOauthFromDBIfNeeded() { """ { "testMask": "mask", - "testNotMask": "this" + "testNotMask": "this", + "testOtherType": true } """); From de70c705bd150c5b02e1e8e0f6f277db3b09f525 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Fri, 30 Dec 2022 02:08:16 -0400 Subject: [PATCH 3/3] add note --- .../src/main/java/io/airbyte/server/handlers/OAuthHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/OAuthHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/OAuthHandler.java index 6e8d9842d35a..d4f04ac67d50 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/OAuthHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/OAuthHandler.java @@ -327,6 +327,7 @@ JsonNode getOauthFromDBIfNeeded(final JsonNode oAuthInputConfigurationFromDB, fi final String k = entry.getKey(); final JsonNode v = entry.getValue(); + // Note: This does not currently handle replacing masked secrets within nested objects. if (AirbyteSecretConstants.SECRETS_MASK.equals(v.textValue())) { if (oAuthInputConfigurationFromDB.has(k)) { result.set(k, oAuthInputConfigurationFromDB.get(k));