Skip to content

Commit

Permalink
Refactor the buildDestinationRead function (#18446)
Browse files Browse the repository at this point in the history
Create a new buildDestinationRead function, that function can be called by top-level functions in the handler that
already have a DestinationConnection object.
  • Loading branch information
malikdiarra authored and nataly committed Nov 3, 2022
1 parent 824be09 commit bbf9b23
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public DestinationRead createDestination(final DestinationCreate destinationCrea
false);

// read configuration from db
return buildDestinationRead(destinationId, spec);
return buildDestinationRead(configRepository.getDestinationConnection(destinationId), spec);
}

public void deleteDestination(final DestinationIdRequestBody destinationIdRequestBody)
Expand Down Expand Up @@ -157,7 +157,8 @@ public DestinationRead updateDestination(final DestinationUpdate destinationUpda
updatedDestination.getTombstone());

// read configuration from db
return buildDestinationRead(destinationUpdate.getDestinationId(), spec);
return buildDestinationRead(
configRepository.getDestinationConnection(destinationUpdate.getDestinationId()), spec);
}

public DestinationRead getDestination(final DestinationIdRequestBody destinationIdRequestBody)
Expand Down Expand Up @@ -206,7 +207,7 @@ public DestinationReadList listDestinationsForWorkspace(final WorkspaceIdRequest
continue;
}

reads.add(buildDestinationRead(dci.getDestinationId()));
reads.add(buildDestinationRead(dci));
}

return new DestinationReadList().destinations(reads);
Expand All @@ -224,7 +225,7 @@ public DestinationReadList listDestinationsForDestinationDefinition(final Destin
continue;
}

reads.add(buildDestinationRead(destinationConnection.getDestinationId()));
reads.add(buildDestinationRead(destinationConnection));
}

return new DestinationReadList().destinations(reads);
Expand All @@ -236,7 +237,7 @@ public DestinationReadList searchDestinations(final DestinationSearch destinatio

for (final DestinationConnection dci : configRepository.listDestinationConnection()) {
if (!dci.getTombstone()) {
final DestinationRead destinationRead = buildDestinationRead(dci.getDestinationId());
final DestinationRead destinationRead = buildDestinationRead(dci);
if (connectionsHandler.matchSearch(destinationSearch, destinationRead)) {
reads.add(destinationRead);
}
Expand Down Expand Up @@ -273,15 +274,20 @@ private void persistDestinationConnection(final String name,
}

private DestinationRead buildDestinationRead(final UUID destinationId) throws JsonValidationException, IOException, ConfigNotFoundException {
final ConnectorSpecification spec = getSpec(configRepository.getDestinationConnection(destinationId).getDestinationDefinitionId());
return buildDestinationRead(destinationId, spec);
return buildDestinationRead(configRepository.getDestinationConnection(destinationId));
}

private DestinationRead buildDestinationRead(final UUID destinationId, final ConnectorSpecification spec)
private DestinationRead buildDestinationRead(final DestinationConnection destinationConnection)
throws JsonValidationException, IOException, ConfigNotFoundException {
final ConnectorSpecification spec = getSpec(destinationConnection.getDestinationDefinitionId());
return buildDestinationRead(destinationConnection, spec);
}

private DestinationRead buildDestinationRead(final DestinationConnection destinationConnection, final ConnectorSpecification spec)
throws ConfigNotFoundException, IOException, JsonValidationException {

// remove secrets from config before returning the read
final DestinationConnection dci = Jsons.clone(configRepository.getDestinationConnection(destinationId));
final DestinationConnection dci = Jsons.clone(destinationConnection);
dci.setConfiguration(secretsProcessor.prepareSecretsForOutput(dci.getConfiguration(), spec.getConnectionSpecification()));

final StandardDestinationDefinition standardDestinationDefinition =
Expand Down

0 comments on commit bbf9b23

Please sign in to comment.