From d41c3f7d6f9e95b5c53087d2aa9a09956b0940ec Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 14 Apr 2022 17:37:06 -0700 Subject: [PATCH] json schema traversal + secrets (#11847) --- .../io/airbyte/commons/json/JsonPaths.java | 22 +- .../io/airbyte/commons/json/JsonSchemas.java | 176 +++++++++- .../airbyte/commons/json/JsonSchemasTest.java | 121 +++++++ .../io/airbyte/commons/json/JsonsTest.java | 18 - .../json_schemas/composite_json_schema.json | 39 +++ .../json_schemas/json_with_all_types.json | 34 ++ .../json_with_array_type_fields.json | 18 + ...ith_array_type_fields_with_composites.json | 32 ++ .../split_secrets/JsonSecretsProcessor.java | 128 ++----- .../split_secrets/SecretsHelpers.java | 202 ++++------- .../JsonSecretsProcessorTest.java | 326 ++++++++++-------- .../split_secrets/SecretsHelpersTest.java | 18 +- .../split_secrets/SecretsTestCase.java | 15 + .../test_cases/ArrayTestCase.java | 12 +- .../test_cases/NestedObjectTestCase.java | 20 +- .../src/test/resources/array/expectedPaths | 1 + .../test/resources/array/partial_config.json | 12 +- .../array/updated_partial_config.json | 12 +- .../src/test/resources/array2/expected.json | 3 + .../test/resources/array2/full_config.json | 3 + .../test/resources/array2/partial_config.json | 7 + .../src/test/resources/array2/spec.json | 20 ++ .../test/resources/array2/update_config.json | 3 + .../array2/updated_partial_config.json | 7 + .../resources/array_of_oneof/expectedPaths | 1 + .../resources/nested_object/expectedPaths | 1 + .../nested_object/partial_config.json | 4 +- .../nested_object/updated_partial_config.json | 4 +- .../updated_partial_config_update1.json | 4 +- .../updated_partial_config_update2.json | 4 +- .../test/resources/nested_oneof/expectedPaths | 1 + .../src/test/resources/oneof/expectedPaths | 1 + .../resources/optional_password/expectedPaths | 1 + .../resources/postgres_ssh_key/expectedPaths | 1 + .../src/test/resources/simple/expectedPaths | 1 + 35 files changed, 840 insertions(+), 432 deletions(-) create mode 100644 airbyte-commons/src/test/java/io/airbyte/commons/json/JsonSchemasTest.java create mode 100644 airbyte-commons/src/test/resources/json_schemas/composite_json_schema.json create mode 100644 airbyte-commons/src/test/resources/json_schemas/json_with_all_types.json create mode 100644 airbyte-commons/src/test/resources/json_schemas/json_with_array_type_fields.json create mode 100644 airbyte-commons/src/test/resources/json_schemas/json_with_array_type_fields_with_composites.json create mode 100644 airbyte-config/persistence/src/test/resources/array/expectedPaths create mode 100644 airbyte-config/persistence/src/test/resources/array2/expected.json create mode 100644 airbyte-config/persistence/src/test/resources/array2/full_config.json create mode 100644 airbyte-config/persistence/src/test/resources/array2/partial_config.json create mode 100644 airbyte-config/persistence/src/test/resources/array2/spec.json create mode 100644 airbyte-config/persistence/src/test/resources/array2/update_config.json create mode 100644 airbyte-config/persistence/src/test/resources/array2/updated_partial_config.json create mode 100644 airbyte-config/persistence/src/test/resources/array_of_oneof/expectedPaths create mode 100644 airbyte-config/persistence/src/test/resources/nested_object/expectedPaths create mode 100644 airbyte-config/persistence/src/test/resources/nested_oneof/expectedPaths create mode 100644 airbyte-config/persistence/src/test/resources/oneof/expectedPaths create mode 100644 airbyte-config/persistence/src/test/resources/optional_password/expectedPaths create mode 100644 airbyte-config/persistence/src/test/resources/postgres_ssh_key/expectedPaths create mode 100644 airbyte-config/persistence/src/test/resources/simple/expectedPaths diff --git a/airbyte-commons/src/main/java/io/airbyte/commons/json/JsonPaths.java b/airbyte-commons/src/main/java/io/airbyte/commons/json/JsonPaths.java index 428299aa958b..0b75b981500d 100644 --- a/airbyte-commons/src/main/java/io/airbyte/commons/json/JsonPaths.java +++ b/airbyte-commons/src/main/java/io/airbyte/commons/json/JsonPaths.java @@ -42,15 +42,15 @@ * returning a list for query results. In addition, we provide helper functions that will just * return a single value (see: {@link JsonPaths#getSingleValue(JsonNode, String)}). These should * only be used if it is not possible for a query to return more than one value. - * - * Note: Package private as most uses of JsonPaths seems like they can be hidden inside other - * commons libraries (i.e. Jsons and JsonsSchemas). If this assumption proves incorrect, we can open - * it up. */ -class JsonPaths { +public class JsonPaths { private static final Logger LOGGER = LoggerFactory.getLogger(JsonPaths.class); + static final String JSON_PATH_START_CHARACTER = "$"; + static final String JSON_PATH_LIST_SPLAT = "[*]"; + static final String JSON_PATH_FIELD_SEPARATOR = "."; + // set default configurations at start up to match our JSON setup. static { Configuration.setDefaults(new Configuration.Defaults() { @@ -82,6 +82,18 @@ public Set