diff --git a/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java b/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java index 3fb6c2b23b3c..f65c701d2b34 100644 --- a/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java +++ b/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java @@ -591,6 +591,23 @@ public List listSourceConnection() throws JsonValidationExcept return persistence.listConfigs(ConfigSchema.SOURCE_CONNECTION, SourceConnection.class); } + /** + * Returns all sources for a workspace. Does not contain secrets. + * + * @param workspaceId - id of the workspace + * @return sources + * @throws JsonValidationException - throws if returned sources are invalid + * @throws IOException - you never know when you IO + */ + public List listWorkspaceSourceConnection(final UUID workspaceId) throws IOException { + final Result result = database.query(ctx -> ctx.select(asterisk()) + .from(ACTOR) + .where(ACTOR.ACTOR_TYPE.eq(ActorType.source)) + .and(ACTOR.WORKSPACE_ID.eq(workspaceId)) + .andNot(ACTOR.TOMBSTONE).fetch()); + return result.stream().map(DbConverter::buildSourceConnection).collect(Collectors.toList()); + } + /** * Returns destination with a given id. Does not contain secrets. To hydrate with secrets see * { @link SecretsRepositoryReader#getDestinationConnectionWithSecrets(final UUID destinationId) }. diff --git a/airbyte-config/config-persistence/src/test/java/io/airbyte/config/persistence/ConfigRepositoryE2EReadWriteTest.java b/airbyte-config/config-persistence/src/test/java/io/airbyte/config/persistence/ConfigRepositoryE2EReadWriteTest.java index 07df60011d7e..eea254e61d55 100644 --- a/airbyte-config/config-persistence/src/test/java/io/airbyte/config/persistence/ConfigRepositoryE2EReadWriteTest.java +++ b/airbyte-config/config-persistence/src/test/java/io/airbyte/config/persistence/ConfigRepositoryE2EReadWriteTest.java @@ -297,6 +297,15 @@ void testListPublicSourceDefinitions() throws IOException { assertEquals(List.of(MockData.publicSourceDefinition()), actualDefinitions); } + @Test + void testListWorkspaceSources() throws IOException { + UUID workspaceId = MockData.standardWorkspaces().get(1).getWorkspaceId(); + final List expectedSources = MockData.sourceConnections().stream() + .filter(source -> source.getWorkspaceId().equals(workspaceId)).collect(Collectors.toList()); + final List sources = configRepository.listWorkspaceSourceConnection(workspaceId); + assertThat(sources).hasSameElementsAs(expectedSources); + } + @Test void testSourceDefinitionGrants() throws IOException { final UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId(); diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/SourceHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/SourceHandler.java index 57c751e3e589..743c4b9e4f74 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/SourceHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/SourceHandler.java @@ -162,10 +162,7 @@ public SourceRead cloneSource(final SourceCloneRequestBody sourceCloneRequestBod public SourceReadList listSourcesForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) throws ConfigNotFoundException, IOException, JsonValidationException { - final List sourceConnections = configRepository.listSourceConnection() - .stream() - .filter(sc -> sc.getWorkspaceId().equals(workspaceIdRequestBody.getWorkspaceId()) && !MoreBooleans.isTruthy(sc.getTombstone())) - .toList(); + final List sourceConnections = configRepository.listWorkspaceSourceConnection(workspaceIdRequestBody.getWorkspaceId()); final List reads = Lists.newArrayList(); for (final SourceConnection sc : sourceConnections) { diff --git a/airbyte-server/src/test/java/io/airbyte/server/handlers/SourceHandlerTest.java b/airbyte-server/src/test/java/io/airbyte/server/handlers/SourceHandlerTest.java index c8157a8ae493..49b0651fbdb6 100644 --- a/airbyte-server/src/test/java/io/airbyte/server/handlers/SourceHandlerTest.java +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/SourceHandlerTest.java @@ -261,7 +261,7 @@ void testListSourcesForWorkspace() throws JsonValidationException, ConfigNotFoun when(configRepository.getSourceConnection(sourceConnection.getSourceId())).thenReturn(sourceConnection); when(configRepository.getSourceConnection(sourceConnection.getSourceId())).thenReturn(sourceConnection); - when(configRepository.listSourceConnection()).thenReturn(Lists.newArrayList(sourceConnection)); + when(configRepository.listWorkspaceSourceConnection(sourceConnection.getWorkspaceId())).thenReturn(Lists.newArrayList(sourceConnection)); when(configRepository.getStandardSourceDefinition(sourceDefinitionSpecificationRead.getSourceDefinitionId())) .thenReturn(standardSourceDefinition); when(configRepository.getSourceDefinitionFromSource(sourceConnection.getSourceId())).thenReturn(standardSourceDefinition);