Skip to content

Commit

Permalink
fix(oauth): handle fields missing in the stored config when building …
Browse files Browse the repository at this point in the history
…consent url (#20933)

* fix: handle missing fields

* test
  • Loading branch information
pedroslopez committed Jan 3, 2023
1 parent bac789e commit c7f8e67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import org.slf4j.Logger;
Expand Down Expand Up @@ -342,10 +343,17 @@ JsonNode getOauthFromDBIfNeeded(final JsonNode oAuthInputConfigurationFromDB, fi

@VisibleForTesting
JsonNode getOAuthInputConfiguration(final JsonNode hydratedSourceConnectionConfiguration, final Map<String, String> pathsToGet) {
return Jsons.jsonNode(pathsToGet.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> JsonPaths.getSingleValue(hydratedSourceConnectionConfiguration, entry.getValue()).get())));
final Map<String, JsonNode> result = new HashMap<>();
pathsToGet.forEach((k, v) -> {
final Optional<JsonNode> configValue = JsonPaths.getSingleValue(hydratedSourceConnectionConfiguration, v);
if (configValue.isPresent()) {
result.put(k, configValue.get());
} else {
LOGGER.warn("Missing the key {} from the config stored in DB", k);
}
});

return Jsons.jsonNode(result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ void testGetOAuthInputConfiguration() {
final Map<String, String> pathsToGet = Map.ofEntries(
Map.entry("field1", "$.field1"),
Map.entry("field3_1", "$.field3.field3_1"),
Map.entry("field3_2", "$.field3.field3_2"));
Map.entry("field3_2", "$.field3.field3_2"),
Map.entry("field4", "$.someNonexistentField"));

final JsonNode expected = Jsons.deserialize(
"""
Expand Down

0 comments on commit c7f8e67

Please sign in to comment.