This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into aman/eds_filter
- Loading branch information
Showing
19 changed files
with
283 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CVE-2023-5678 exp:2023-11-30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
gateway-service-impl/src/main/java/org/hypertrace/gateway/service/EntityTypesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.hypertrace.gateway.service; | ||
|
||
import com.google.common.cache.CacheBuilder; | ||
import com.google.common.cache.CacheLoader; | ||
import com.google.common.cache.LoadingCache; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.NonNull; | ||
import org.hypertrace.core.grpcutils.context.ContextualKey; | ||
import org.hypertrace.gateway.service.common.util.EntityTypeServiceClient; | ||
import org.hypertrace.gateway.service.common.util.EntityTypeServiceV2Client; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class EntityTypesProvider { | ||
private static final Logger LOG = LoggerFactory.getLogger(EntityTypesProvider.class); | ||
private static final int DEFAULT_CACHE_SIZE = 1024; | ||
private static final int DEFAULT_EXPIRE_DURATION_MIN = 30; // 30 minutes | ||
|
||
// TenantId to Entity types cache | ||
private final LoadingCache<ContextualKey<Void>, Set<String>> tenantIdToEntityTypesCache; | ||
|
||
public EntityTypesProvider( | ||
EntityTypeServiceClient entityTypeServiceClient, | ||
EntityTypeServiceV2Client entityTypeServiceV2Client) { | ||
CacheLoader<ContextualKey<Void>, Set<String>> cacheLoader = | ||
new CacheLoader<>() { | ||
@Override | ||
public Set<String> load(@NonNull ContextualKey<Void> contextualKey) { | ||
Set<String> entityTypesSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); | ||
entityTypeServiceClient | ||
.getAllEntityTypes(contextualKey.getContext()) | ||
.forEach(entityType -> entityTypesSet.add(entityType.getName())); | ||
entityTypeServiceV2Client | ||
.getAllEntityTypes(contextualKey.getContext()) | ||
.forEach(entityType -> entityTypesSet.add(entityType.getName())); | ||
return entityTypesSet; | ||
} | ||
}; | ||
|
||
tenantIdToEntityTypesCache = | ||
CacheBuilder.newBuilder() | ||
.maximumSize(DEFAULT_CACHE_SIZE) | ||
.expireAfterWrite(DEFAULT_EXPIRE_DURATION_MIN, TimeUnit.MINUTES) | ||
.build(cacheLoader); | ||
} | ||
|
||
public Set<String> getEntityTypes(ContextualKey<Void> contextualKey) { | ||
try { | ||
return tenantIdToEntityTypesCache.get(contextualKey); | ||
} catch (ExecutionException e) { | ||
LOG.error( | ||
String.format( | ||
"Error retrieving entity types for tenant %s", | ||
contextualKey.getContext().getTenantId())); | ||
throw new RuntimeException( | ||
String.format( | ||
"Error retrieving Entity types for tenant:%s", | ||
contextualKey.getContext().getTenantId())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...mpl/src/main/java/org/hypertrace/gateway/service/common/util/EntityTypeServiceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.hypertrace.gateway.service.common.util; | ||
|
||
import com.google.common.collect.Lists; | ||
import io.grpc.Channel; | ||
import java.util.List; | ||
import org.hypertrace.core.grpcutils.client.RequestContextClientCallCredsProviderFactory; | ||
import org.hypertrace.core.grpcutils.context.RequestContext; | ||
import org.hypertrace.entity.type.service.v1.EntityType; | ||
import org.hypertrace.entity.type.service.v1.EntityTypeFilter; | ||
import org.hypertrace.entity.type.service.v1.EntityTypeServiceGrpc; | ||
|
||
public class EntityTypeServiceClient { | ||
private final EntityTypeServiceGrpc.EntityTypeServiceBlockingStub blockingStub; | ||
|
||
public EntityTypeServiceClient(Channel channel) { | ||
this.blockingStub = | ||
EntityTypeServiceGrpc.newBlockingStub(channel) | ||
.withCallCredentials( | ||
RequestContextClientCallCredsProviderFactory.getClientCallCredsProvider().get()); | ||
} | ||
|
||
public List<EntityType> getAllEntityTypes(RequestContext requestContext) { | ||
return Lists.newArrayList( | ||
requestContext.call( | ||
() -> this.blockingStub.queryEntityTypes(EntityTypeFilter.newBuilder().build()))); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...l/src/main/java/org/hypertrace/gateway/service/common/util/EntityTypeServiceV2Client.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.hypertrace.gateway.service.common.util; | ||
|
||
import io.grpc.Channel; | ||
import java.util.List; | ||
import org.hypertrace.core.grpcutils.client.RequestContextClientCallCredsProviderFactory; | ||
import org.hypertrace.core.grpcutils.context.RequestContext; | ||
import org.hypertrace.entity.type.service.v2.EntityType; | ||
import org.hypertrace.entity.type.service.v2.EntityTypeServiceGrpc; | ||
import org.hypertrace.entity.type.service.v2.QueryEntityTypesRequest; | ||
|
||
public class EntityTypeServiceV2Client { | ||
private final EntityTypeServiceGrpc.EntityTypeServiceBlockingStub blockingStub; | ||
|
||
public EntityTypeServiceV2Client(Channel channel) { | ||
this.blockingStub = | ||
EntityTypeServiceGrpc.newBlockingStub(channel) | ||
.withCallCredentials( | ||
RequestContextClientCallCredsProviderFactory.getClientCallCredsProvider().get()); | ||
} | ||
|
||
public List<EntityType> getAllEntityTypes(RequestContext requestContext) { | ||
return requestContext | ||
.call( | ||
() -> this.blockingStub.queryEntityTypes(QueryEntityTypesRequest.newBuilder().build())) | ||
.getEntityTypeList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.