Skip to content

Commit

Permalink
feat(api): authorization extended for soft-delete and suspended
Browse files Browse the repository at this point in the history
* fix AspectRetriever behavior with respect to key aspects always returned
* Deprecated active boolean in corpUserInfo not supported
  • Loading branch information
david-leifker committed Dec 18, 2024
1 parent d0b4f7a commit 6d03e03
Show file tree
Hide file tree
Showing 78 changed files with 979 additions and 430 deletions.
2 changes: 2 additions & 0 deletions datahub-frontend/app/auth/AuthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.datahubproject.metadata.context.EntityRegistryContext;
import io.datahubproject.metadata.context.OperationContext;
import io.datahubproject.metadata.context.OperationContextConfig;
import io.datahubproject.metadata.context.RetrieverContext;
import io.datahubproject.metadata.context.SearchContext;
import io.datahubproject.metadata.context.ValidationContext;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -195,6 +196,7 @@ protected OperationContext provideOperationContext(
.searchContext(SearchContext.EMPTY)
.entityRegistryContext(EntityRegistryContext.builder().build(EmptyEntityRegistry.EMPTY))
.validationContext(ValidationContext.builder().alternateValidation(false).build())
.retrieverContext(RetrieverContext.EMPTY)
.build(systemAuthentication);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.linkedin.gms.factory.kafka.common.TopicConventionFactory;
import com.linkedin.gms.factory.kafka.schemaregistry.InternalSchemaRegistryFactory;
import com.linkedin.gms.factory.search.BaseElasticSearchComponentsFactory;
import com.linkedin.metadata.aspect.CachingAspectRetriever;
import com.linkedin.metadata.config.kafka.KafkaConfiguration;
import com.linkedin.metadata.dao.producer.KafkaEventProducer;
import com.linkedin.metadata.dao.producer.KafkaHealthChecker;
Expand Down Expand Up @@ -186,6 +187,7 @@ protected OperationContext javaSystemOperationContext(
components.getIndexConvention(),
RetrieverContext.builder()
.aspectRetriever(entityServiceAspectRetriever)
.cachingAspectRetriever(CachingAspectRetriever.EMPTY)
.graphRetriever(systemGraphRetriever)
.searchRetriever(searchServiceSearchRetriever)
.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void readerExecutable(ReaderWrapper reader, UpgradeContext context) {
try {
aspectRecord =
EntityUtils.toSystemAspect(
context.opContext().getRetrieverContext().get(), aspect.toEntityAspect())
context.opContext().getRetrieverContext(), aspect.toEntityAspect())
.get()
.getRecordTemplate();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public Function<UpgradeContext, UpgradeStepResult> executable() {
List<Pair<Future<?>, SystemAspect>> futures;
futures =
EntityUtils.toSystemAspectFromEbeanAspects(
opContext.getRetrieverContext().get(),
batch.collect(Collectors.toList()))
opContext.getRetrieverContext(), batch.collect(Collectors.toList()))
.stream()
.map(
systemAspect -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ static AspectsBatch generateAspectBatch(
.collect(Collectors.toList());

return AspectsBatchImpl.builder()
.mcps(mcps, auditStamp, opContext.getRetrieverContext().get())
.retrieverContext(opContext.getRetrieverContext().get())
.mcps(mcps, auditStamp, opContext.getRetrieverContext())
.retrieverContext(opContext.getRetrieverContext())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ public Function<UpgradeContext, UpgradeStepResult> executable() {

AspectsBatch aspectsBatch =
AspectsBatchImpl.builder()
.retrieverContext(opContext.getRetrieverContext().get())
.retrieverContext(opContext.getRetrieverContext())
.items(
batch
.flatMap(
ebeanAspectV2 ->
EntityUtils.toSystemAspectFromEbeanAspects(
opContext.getRetrieverContext().get(),
opContext.getRetrieverContext(),
Set.of(ebeanAspectV2))
.stream())
.map(
Expand All @@ -189,11 +189,7 @@ public Function<UpgradeContext, UpgradeStepResult> executable() {
.auditStamp(systemAspect.getAuditStamp())
.systemMetadata(
withAppSource(systemAspect.getSystemMetadata()))
.build(
opContext
.getRetrieverContext()
.get()
.getAspectRetriever()))
.build(opContext.getAspectRetriever()))
.collect(Collectors.toList()))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.linkedin.upgrade.DataHubUpgradeState;
import io.datahubproject.metadata.context.OperationContext;
import io.datahubproject.metadata.context.RetrieverContext;
import java.util.Optional;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -48,7 +47,7 @@ public void setup() {
step =
new GenerateSchemaFieldsFromSchemaMetadataStep(
mockOpContext, mockEntityService, mockAspectDao, 10, 100, 1000);
when(mockOpContext.getRetrieverContext()).thenReturn(Optional.of(mockRetrieverContext));
when(mockOpContext.getRetrieverContext()).thenReturn(mockRetrieverContext);
}

/** Test to verify the correct step ID is returned. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
package com.linkedin.metadata.aspect;

import com.linkedin.common.urn.Urn;
import com.linkedin.entity.Aspect;
import com.linkedin.metadata.models.registry.EmptyEntityRegistry;
import com.linkedin.metadata.models.registry.EntityRegistry;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;

/** Responses can be cached based on application.yaml caching configuration for the EntityClient */
public interface CachingAspectRetriever extends AspectRetriever {}
public interface CachingAspectRetriever extends AspectRetriever {

CachingAspectRetriever EMPTY = new EmptyAspectRetriever();

class EmptyAspectRetriever implements CachingAspectRetriever {
@Nonnull
@Override
public Map<Urn, Map<String, Aspect>> getLatestAspectObjects(
Set<Urn> urns, Set<String> aspectNames) {
return Collections.emptyMap();
}

@Nonnull
@Override
public Map<Urn, Map<String, SystemAspect>> getLatestSystemAspects(
Map<Urn, Set<String>> urnAspectNames) {
return Collections.emptyMap();
}

@Nonnull
@Override
public EntityRegistry getEntityRegistry() {
return EmptyEntityRegistry.EMPTY;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.query.filter.RelationshipFilter;
import com.linkedin.metadata.query.filter.SortCriterion;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -97,4 +98,26 @@ default void consumeRelatedEntities(
}
}
}

GraphRetriever EMPTY = new EmptyGraphRetriever();

class EmptyGraphRetriever implements GraphRetriever {

@Nonnull
@Override
public RelatedEntitiesScrollResult scrollRelatedEntities(
@Nullable List<String> sourceTypes,
@Nonnull Filter sourceEntityFilter,
@Nullable List<String> destinationTypes,
@Nonnull Filter destinationEntityFilter,
@Nonnull List<String> relationshipTypes,
@Nonnull RelationshipFilter relationshipFilter,
@Nonnull List<SortCriterion> sortCriterion,
@Nullable String scrollId,
int count,
@Nullable Long startTimeMillis,
@Nullable Long endTimeMillis) {
return new RelatedEntitiesScrollResult(0, 0, null, Collections.emptyList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.search.ScrollResult;
import com.linkedin.metadata.search.SearchEntityArray;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -21,4 +22,22 @@ ScrollResult scroll(
@Nullable Filter filters,
@Nullable String scrollId,
int count);

SearchRetriever EMPTY = new EmptySearchRetriever();

class EmptySearchRetriever implements SearchRetriever {

@Override
public ScrollResult scroll(
@Nonnull List<String> entities,
@Nullable Filter filters,
@Nullable String scrollId,
int count) {
ScrollResult empty = new ScrollResult();
empty.setEntities(new SearchEntityArray());
empty.setNumEntities(0);
empty.setPageSize(0);
return empty;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.linkedin.data.DataMap;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.entity.Aspect;
import com.linkedin.metadata.aspect.AspectRetriever;
import com.linkedin.metadata.aspect.CachingAspectRetriever;
import com.linkedin.metadata.aspect.SystemAspect;
import com.linkedin.metadata.models.registry.EntityRegistry;
import com.linkedin.mxe.SystemMetadata;
Expand All @@ -22,7 +22,7 @@
import javax.annotation.Nonnull;
import org.mockito.Mockito;

public class MockAspectRetriever implements AspectRetriever {
public class MockAspectRetriever implements CachingAspectRetriever {
private final Map<Urn, Map<String, Aspect>> data;
private final Map<Urn, Map<String, SystemAspect>> systemData = new HashMap<>();

Expand Down
2 changes: 2 additions & 0 deletions li-utils/src/main/java/com/linkedin/metadata/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ public class Constants {
/** User Status */
public static final String CORP_USER_STATUS_ACTIVE = "ACTIVE";

public static final String CORP_USER_STATUS_SUSPENDED = "SUSPENDED";

/** Task Runs */
public static final String DATA_PROCESS_INSTANCE_ENTITY_NAME = "dataProcessInstance";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.linkedin.data.schema.annotation.PathSpecBasedSchemaAnnotationVisitor;
import com.linkedin.dataset.DatasetProperties;
import com.linkedin.events.metadata.ChangeType;
import com.linkedin.metadata.aspect.AspectRetriever;
import com.linkedin.metadata.aspect.CachingAspectRetriever;
import com.linkedin.metadata.aspect.GraphRetriever;
import com.linkedin.metadata.aspect.batch.MCPItem;
import com.linkedin.metadata.aspect.patch.GenericJsonPatch;
Expand Down Expand Up @@ -56,7 +56,7 @@

public class AspectsBatchImplTest {
private EntityRegistry testRegistry;
private AspectRetriever mockAspectRetriever;
private CachingAspectRetriever mockAspectRetriever;
private RetrieverContext retrieverContext;

@BeforeTest
Expand All @@ -75,12 +75,12 @@ public void beforeTest() throws EntityRegistryException {

@BeforeMethod
public void setup() {
this.mockAspectRetriever = mock(AspectRetriever.class);
this.mockAspectRetriever = mock(CachingAspectRetriever.class);
when(this.mockAspectRetriever.getEntityRegistry()).thenReturn(testRegistry);
this.retrieverContext =
RetrieverContext.builder()
.searchRetriever(mock(SearchRetriever.class))
.aspectRetriever(mockAspectRetriever)
.cachingAspectRetriever(mockAspectRetriever)
.graphRetriever(mock(GraphRetriever.class))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static List<MCPItem> getAdditionalChanges(
getProposalFromAspectForDefault(
entry.getKey(), entry.getValue(), entityKeyAspect, templateItem),
templateItem.getAuditStamp(),
opContext.getAspectRetrieverOpt().get()))
opContext.getAspectRetriever()))
.filter(Objects::nonNull);
})
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public EntityRegistry getEntityRegistry() {
@Override
public Aspect getLatestAspectObject(@Nonnull Urn urn, @Nonnull String aspectName) {
try {
return entityClient.getLatestAspectObject(systemOperationContext, urn, aspectName);
return entityClient.getLatestAspectObject(systemOperationContext, urn, aspectName, false);
} catch (RemoteInvocationException | URISyntaxException e) {
throw new RuntimeException(e);
}
Expand All @@ -49,7 +49,7 @@ public Map<Urn, Map<String, Aspect>> getLatestAspectObjects(
return Map.of();
} else {
try {
return entityClient.getLatestAspects(systemOperationContext, urns, aspectNames);
return entityClient.getLatestAspects(systemOperationContext, urns, aspectNames, false);
} catch (RemoteInvocationException | URISyntaxException e) {
throw new RuntimeException(e);
}
Expand All @@ -70,7 +70,8 @@ public Map<Urn, Map<String, SystemAspect>> getLatestSystemAspects(
urnAspectNames.keySet(),
urnAspectNames.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toSet()));
.collect(Collectors.toSet()),
false);
} catch (RemoteInvocationException | URISyntaxException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,17 @@ public EntityResponse getV2(
@Nonnull OperationContext opContext,
@Nonnull String entityName,
@Nonnull final Urn urn,
@Nullable final Set<String> aspectNames)
@Nullable final Set<String> aspectNames,
@Nullable Boolean alwaysIncludeKeyAspect)
throws RemoteInvocationException, URISyntaxException {
final Set<String> projectedAspects =
aspectNames == null ? opContext.getEntityAspectNames(entityName) : aspectNames;
return entityService.getEntityV2(opContext, entityName, urn, projectedAspects);
return entityService.getEntityV2(
opContext,
entityName,
urn,
projectedAspects,
alwaysIncludeKeyAspect == null || alwaysIncludeKeyAspect);
}

@Override
Expand All @@ -126,7 +132,8 @@ public Map<Urn, EntityResponse> batchGetV2(
@Nonnull OperationContext opContext,
@Nonnull String entityName,
@Nonnull Set<Urn> urns,
@Nullable Set<String> aspectNames)
@Nullable Set<String> aspectNames,
@Nullable Boolean alwaysIncludeKeyAspect)
throws RemoteInvocationException, URISyntaxException {
final Set<String> projectedAspects =
aspectNames == null ? opContext.getEntityAspectNames(entityName) : aspectNames;
Expand All @@ -139,7 +146,11 @@ public Map<Urn, EntityResponse> batchGetV2(
try {
responseMap.putAll(
entityService.getEntitiesV2(
opContext, entityName, new HashSet<>(batch), projectedAspects));
opContext,
entityName,
new HashSet<>(batch),
projectedAspects,
alwaysIncludeKeyAspect == null || alwaysIncludeKeyAspect));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -772,7 +783,7 @@ public List<String> batchIngestProposals(
.mcps(
batch,
auditStamp,
opContext.getRetrieverContext().get(),
opContext.getRetrieverContext(),
opContext.getValidationContext().isAlternateValidation())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ public Map<Urn, EntityResponse> batchGetV2NoCache(
@Nonnull Set<Urn> urns,
@Nullable Set<String> aspectNames)
throws RemoteInvocationException, URISyntaxException {
return super.batchGetV2(opContext, entityName, urns, aspectNames);
return super.batchGetV2(opContext, entityName, urns, aspectNames, false);
}
}
Loading

0 comments on commit 6d03e03

Please sign in to comment.