adnanhemani commented on code in PR #2482:
URL: https://github.com/apache/polaris/pull/2482#discussion_r2325835738
##########
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisCatalogsEventServiceDelegator.java:
##########
@@ -106,14 +157,25 @@ public Response updateCatalogRole(
UpdateCatalogRoleRequest updateRequest,
RealmContext realmContext,
SecurityContext securityContext) {
- return delegate.updateCatalogRole(
- catalogName, catalogRoleName, updateRequest, realmContext,
securityContext);
+ polarisEventListener.onBeforeCatalogRoleUpdate(
+ new CatalogsServiceEvents.BeforeCatalogRoleUpdateEvent(
+ catalogName, catalogRoleName, updateRequest));
+ Response resp =
+ delegate.updateCatalogRole(
+ catalogName, catalogRoleName, updateRequest, realmContext,
securityContext);
+ polarisEventListener.onAfterCatalogRoleUpdate(
+ new CatalogsServiceEvents.AfterCatalogRoleUpdateEvent(
+ catalogName, (CatalogRole) resp.getEntity()));
+ return resp;
}
@Override
public Response listCatalogRoles(
String catalogName, RealmContext realmContext, SecurityContext
securityContext) {
- return delegate.listCatalogRoles(catalogName, realmContext,
securityContext);
+ polarisEventListener.onBeforeCatalogList(new
CatalogsServiceEvents.BeforeCatalogListEvent());
Review Comment:
Good catch!
##########
runtime/service/src/main/java/org/apache/polaris/service/events/CatalogsServiceEvents.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.service.events;
+
+import org.apache.polaris.core.admin.model.AddGrantRequest;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogRole;
+import org.apache.polaris.core.admin.model.GrantResource;
+import org.apache.polaris.core.admin.model.RevokeGrantRequest;
+import org.apache.polaris.core.admin.model.UpdateCatalogRequest;
+import org.apache.polaris.core.admin.model.UpdateCatalogRoleRequest;
+import org.apache.polaris.core.entity.PolarisPrivilege;
+
+public class CatalogsServiceEvents {
+ public record BeforeCatalogCreatedEvent(String catalogName) implements
PolarisEvent {}
Review Comment:
Changed!
##########
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisCatalogsEventServiceDelegator.java:
##########
@@ -123,8 +185,25 @@ public Response addGrantToCatalogRole(
AddGrantRequest grantRequest,
RealmContext realmContext,
SecurityContext securityContext) {
- return delegate.addGrantToCatalogRole(
- catalogName, catalogRoleName, grantRequest, realmContext,
securityContext);
+ polarisEventListener.onBeforeAddGrantToCatalogRole(
+ new CatalogsServiceEvents.BeforeAddGrantToCatalogRoleEvent(
+ catalogName, catalogRoleName, grantRequest));
+ Response resp =
+ delegate.addGrantToCatalogRole(
+ catalogName, catalogRoleName, grantRequest, realmContext,
securityContext);
+ PolarisServiceImpl.AddGrantToCatalogRoleEntityWrapper entityWrapper =
+ (PolarisServiceImpl.AddGrantToCatalogRoleEntityWrapper)
resp.getEntity();
+ if (resp.getStatus() != Response.Status.BAD_REQUEST.getStatusCode()) {
Review Comment:
Removed per comment below.
##########
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java:
##########
@@ -630,6 +635,12 @@ public Response listCatalogRolesForPrincipalRole(
return Response.ok(catalogRoles).build();
}
+ record AddGrantToCatalogRoleEntityWrapper(
Review Comment:
This makes sense, I will start a new ML discussion regarding this. In the
meantime, let me add TODOs for this and remove it for now from this PR to
unblock the rest of the events.
##########
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisCatalogsEventServiceDelegator.java:
##########
@@ -135,8 +214,22 @@ public Response revokeGrantFromCatalogRole(
RevokeGrantRequest grantRequest,
RealmContext realmContext,
SecurityContext securityContext) {
- return delegate.revokeGrantFromCatalogRole(
- catalogName, catalogRoleName, cascade, grantRequest, realmContext,
securityContext);
+ polarisEventListener.onBeforeRevokeGrantFromCatalogRole(
+ new CatalogsServiceEvents.BeforeRevokeGrantFromCatalogRoleEvent(
+ catalogName, catalogRoleName, grantRequest, cascade));
+ Response resp =
+ delegate.revokeGrantFromCatalogRole(
+ catalogName, catalogRoleName, cascade, grantRequest, realmContext,
securityContext);
+ PolarisServiceImpl.RevokeGrantFromCatalogRoleEntityWrapper entityWrapper =
+ (PolarisServiceImpl.RevokeGrantFromCatalogRoleEntityWrapper)
resp.getEntity();
+ polarisEventListener.onAfterRevokeGrantFromCatalogRole(
+ new CatalogsServiceEvents.AfterRevokeGrantFromCatalogRoleEvent(
+ catalogName,
+ catalogRoleName,
+ entityWrapper.polarisPrivilege(),
+ entityWrapper.grantResource(),
+ entityWrapper.cascade()));
+ return resp;
Review Comment:
Agreed, removing as per above comment.
##########
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java:
##########
@@ -397,7 +402,7 @@ public Response createPrincipalRole(
PrincipalRole newPrincipalRole =
new
PrincipalRoleEntity(adminService.createPrincipalRole(entity)).asPrincipalRole();
LOGGER.info("Created new principalRole {}", newPrincipalRole);
- return Response.status(Response.Status.CREATED).build();
+ return
Response.status(Response.Status.CREATED).entity(newPrincipalRole).build();
Review Comment:
Not opposed to this, but let's do this in a different PR :)
##########
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisCatalogsEventServiceDelegator.java:
##########
@@ -26,36 +26,58 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.SecurityContext;
import org.apache.polaris.core.admin.model.AddGrantRequest;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogRole;
import org.apache.polaris.core.admin.model.CreateCatalogRequest;
import org.apache.polaris.core.admin.model.CreateCatalogRoleRequest;
import org.apache.polaris.core.admin.model.RevokeGrantRequest;
import org.apache.polaris.core.admin.model.UpdateCatalogRequest;
import org.apache.polaris.core.admin.model.UpdateCatalogRoleRequest;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.service.admin.api.PolarisCatalogsApiService;
+import org.apache.polaris.service.events.CatalogsServiceEvents;
+import org.apache.polaris.service.events.PolarisEventListener;
@Decorator
@Priority(1000)
public class PolarisCatalogsEventServiceDelegator implements
PolarisCatalogsApiService {
@Inject @Delegate PolarisCatalogsApiService delegate;
+ @Inject PolarisEventListener polarisEventListener;
@Override
public Response createCatalog(
CreateCatalogRequest request, RealmContext realmContext, SecurityContext
securityContext) {
Review Comment:
Changed in next revision.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]