Skip to content

Commit

Permalink
Remove unused deleteSource code. (#12169)
Browse files Browse the repository at this point in the history
Remove unused 'deleteSource' and getSecretPersistenceCoordinate code.

This is what I ran into while trying to implement deleting secrets when sources/destinations are deleted.
  • Loading branch information
davinchia committed Apr 18, 2024
1 parent 5536030 commit d8e939d
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -833,25 +833,6 @@ public void writeSourceConnectionNoSecrets(final SourceConnection partialSource)
sourceService.writeSourceConnectionNoSecrets(partialSource);
}

/**
* Delete a source by id.
*
* @param sourceId source id
* @return true if a source was deleted, false otherwise.
* @throws JsonValidationException - throws if returned sources are invalid
* @throws io.airbyte.data.exceptions.ConfigNotFoundException - throws if no source with that id can
* be found.
* @throws IOException - you never know when you IO
*/
@Deprecated
public boolean deleteSource(final UUID sourceId) throws JsonValidationException, ConfigNotFoundException, IOException {
try {
return sourceService.deleteSource(sourceId);
} catch (final io.airbyte.data.exceptions.ConfigNotFoundException e) {
throw new ConfigNotFoundException(e.getType(), e.getConfigId());
}
}

/**
* Returns all sources in the database. Does not contain secrets. To hydrate with secrets see the
* config-secrets module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public interface SecretPersistenceConfigService {

SecretPersistenceConfig getSecretPersistenceConfig(ScopeType scope, UUID scopeId) throws IOException, ConfigNotFoundException;

Optional<SecretPersistenceCoordinate> getSecretPersistenceCoordinate(UUID workspaceId, UUID organizationId) throws IOException;

Optional<SecretPersistenceCoordinate> createOrUpdateSecretPersistenceConfig(ScopeType scope,
UUID scopeId,
SecretPersistenceType secretPersistenceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public interface SourceService {

void writeSourceConnectionNoSecrets(SourceConnection partialSource) throws IOException;

boolean deleteSource(UUID sourceId) throws JsonValidationException, ConfigNotFoundException, IOException;

List<SourceConnection> listSourceConnection() throws IOException;

List<SourceConnection> listWorkspaceSourceConnection(UUID workspaceId) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import static io.airbyte.db.instance.configs.jooq.generated.tables.SecretPersistenceConfig.SECRET_PERSISTENCE_CONFIG;
import static org.jooq.impl.DSL.asterisk;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.inline;

import com.fasterxml.jackson.databind.JsonNode;
import io.airbyte.commons.json.Jsons;
Expand Down Expand Up @@ -75,33 +73,6 @@ public SecretPersistenceConfig getSecretPersistenceConfig(final ScopeType scope,
throw new ConfigNotFoundException(ConfigSchema.SECRET_PERSISTENCE_CONFIG, List.of(scope, scopeId).toString());
}

/**
* Retrieve secret persistence configs in order of precedence: workspace -> organization.
*
* @param workspaceId workspace ID
* @param organizationId organization ID
* @return Optional secret persistence config for the first scope found.
* @throws IOException it could happen
*/
@Override
public Optional<SecretPersistenceCoordinate> getSecretPersistenceCoordinate(final UUID workspaceId, final UUID organizationId) throws IOException {
final Result<Record> result = database.query(ctx -> {
final SelectJoinStep<Record> query = ctx.select(asterisk(), inline(1).as(SORT_ORDER)).from(SECRET_PERSISTENCE_CONFIG);
return query.where(
SECRET_PERSISTENCE_CONFIG.SCOPE_TYPE.eq(SecretPersistenceScopeType.workspace),
SECRET_PERSISTENCE_CONFIG.SCOPE_ID.eq(workspaceId))
.unionAll(
ctx.select(asterisk(), inline(2).as(SORT_ORDER)).from(SECRET_PERSISTENCE_CONFIG)
.where(
SECRET_PERSISTENCE_CONFIG.SCOPE_TYPE.eq(SecretPersistenceScopeType.organization),
SECRET_PERSISTENCE_CONFIG.SCOPE_ID.eq(organizationId)))
.orderBy(field(SORT_ORDER).asc())
.limit(1).fetch();
});

return result.stream().findFirst().map(DbConverter::buildSecretPersistenceCoordinate);
}

@Override
public Optional<SecretPersistenceCoordinate> createOrUpdateSecretPersistenceConfig(final ScopeType scope,
final UUID scopeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import static io.airbyte.db.instance.configs.jooq.generated.Tables.WORKSPACE;
import static io.airbyte.featureflag.ContextKt.ANONYMOUS;
import static org.jooq.impl.DSL.asterisk;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.noCondition;
import static org.jooq.impl.DSL.select;

Expand Down Expand Up @@ -74,7 +73,6 @@
import org.jooq.Record1;
import org.jooq.Result;
import org.jooq.SelectJoinStep;
import org.jooq.Table;
import org.jooq.impl.DSL;

@Slf4j
Expand Down Expand Up @@ -287,21 +285,6 @@ public void writeSourceConnectionNoSecrets(final SourceConnection partialSource)
});
}

/**
* Delete a source by id.
*
* @param sourceId
* @return true if a source was deleted, false otherwise.
* @throws JsonValidationException - throws if returned sources are invalid
* @throws ConfigNotFoundException - throws if no source with that id can be found.
* @throws IOException - you never know when you IO
*/
@Override
public boolean deleteSource(final UUID sourceId)
throws JsonValidationException, ConfigNotFoundException, IOException {
return deleteById(ACTOR, sourceId);
}

/**
* Returns all sources in the database. Does not contain secrets.
*
Expand Down Expand Up @@ -567,7 +550,7 @@ private Result<Record> actorDefinitionsJoinedWithGrants(final UUID scopeId,
.fetch());
}

public Optional<UUID> getOrganizationIdFromWorkspaceId(final UUID scopeId) throws IOException {
private Optional<UUID> getOrganizationIdFromWorkspaceId(final UUID scopeId) throws IOException {
final Optional<Record1<UUID>> optionalRecord = database.query(ctx -> ctx.select(WORKSPACE.ORGANIZATION_ID).from(WORKSPACE)
.where(WORKSPACE.ID.eq(scopeId)).fetchOptional());
return optionalRecord.map(Record1::value1);
Expand All @@ -580,7 +563,7 @@ private <T> Entry<T, Boolean> actorDefinitionWithGrantStatus(final Record outerJ
return Map.entry(actorDefinition, granted);
}

static void writeStandardSourceDefinition(final List<StandardSourceDefinition> configs, final DSLContext ctx) {
private static void writeStandardSourceDefinition(final List<StandardSourceDefinition> configs, final DSLContext ctx) {
final OffsetDateTime timestamp = OffsetDateTime.now();
configs.forEach((standardSourceDefinition) -> {
final boolean isExistingConfig = ctx.fetchExists(DSL.select()
Expand Down Expand Up @@ -680,19 +663,6 @@ private ActorDefinitionVersion getDefaultVersionForActorDefinitionId(final UUID
return ConnectorMetadataJooqHelper.getDefaultVersionForActorDefinitionIdOptional(actorDefinitionId, ctx).orElseThrow();
}

/**
* Deletes all records with given id. If it deletes anything, returns true. Otherwise, false.
*
* @param table - table from which to delete the record
* @param id - id of the record to delete
* @return true if anything was deleted, otherwise false.
* @throws IOException - you never know when you io
*/
@SuppressWarnings("SameParameterValue")
private boolean deleteById(final Table<?> table, final UUID id) throws IOException {
return database.transaction(ctx -> ctx.deleteFrom(table)).where(field(DSL.name(PRIMARY_KEY)).eq(id)).execute() > 0;
}

private Stream<SourceConnection> listSourceQuery(final Optional<UUID> configId) throws IOException {
final Result<Record> result = database.query(ctx -> {
final SelectJoinStep<Record> query = ctx.select(asterisk()).from(ACTOR);
Expand Down Expand Up @@ -777,7 +747,7 @@ public void writeSourceConnectionWithSecrets(
writeSourceConnectionNoSecrets(partialSource);
}

public Optional<SourceConnection> getSourceIfExists(final UUID sourceId) {
private Optional<SourceConnection> getSourceIfExists(final UUID sourceId) {
try {
return Optional.of(getSourceConnection(sourceId));
} catch (final ConfigNotFoundException | JsonValidationException | IOException e) {
Expand Down

0 comments on commit d8e939d

Please sign in to comment.