mchades commented on code in PR #10982:
URL: https://github.com/apache/gravitino/pull/10982#discussion_r3201834037


##########
server/src/main/java/org/apache/gravitino/server/web/rest/ViewOperations.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.gravitino.server.web.rest;
+
+import static org.apache.gravitino.dto.util.DTOConverters.fromDTOs;
+
+import com.codahale.metrics.annotation.ResponseMetered;
+import com.codahale.metrics.annotation.Timed;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.catalog.ViewDispatcher;
+import org.apache.gravitino.dto.requests.ViewCreateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdatesRequest;
+import org.apache.gravitino.dto.responses.DropResponse;
+import org.apache.gravitino.dto.responses.EntityListResponse;
+import org.apache.gravitino.dto.responses.ViewResponse;
+import org.apache.gravitino.dto.util.DTOConverters;
+import org.apache.gravitino.metrics.MetricNames;
+import org.apache.gravitino.rel.View;
+import org.apache.gravitino.rel.ViewChange;
+import org.apache.gravitino.server.web.Utils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/views")
+public class ViewOperations {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ViewOperations.class);
+
+  private final ViewDispatcher dispatcher;
+
+  @Context private HttpServletRequest httpRequest;
+
+  @Inject
+  public ViewOperations(ViewDispatcher dispatcher) {
+    this.dispatcher = dispatcher;
+  }
+
+  @GET
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "list-view." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "list-view", absolute = true)
+  public Response listViews(
+      @PathParam("metalake") String metalake,
+      @PathParam("catalog") String catalog,
+      @PathParam("schema") String schema) {
+    LOG.info("Received list views request for schema: {}.{}.{}", metalake, 
catalog, schema);
+    try {
+      return Utils.doAs(
+          httpRequest,
+          () -> {
+            Namespace viewNS = NamespaceUtil.ofView(metalake, catalog, schema);
+            NameIdentifier[] idents = dispatcher.listViews(viewNS);
+            Response response = Utils.ok(new EntityListResponse(idents));
+            LOG.info(
+                "List {} views under schema: {}.{}.{}", idents.length, 
metalake, catalog, schema);
+            return response;
+          });

Review Comment:
   Thanks for calling this out. We agree this is a valid authorization gap. For 
this PR, we are keeping scope limited to introducing the view REST 
endpoints/DTOs and related tests. The ViewOperations authorization wiring 
(endpoint-level expressions plus list filtering) is a broader security change 
and will be handled in a dedicated follow-up PR to keep this change set focused 
and low-risk.



##########
server/src/main/java/org/apache/gravitino/server/web/rest/ViewOperations.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.gravitino.server.web.rest;
+
+import static org.apache.gravitino.dto.util.DTOConverters.fromDTOs;
+
+import com.codahale.metrics.annotation.ResponseMetered;
+import com.codahale.metrics.annotation.Timed;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.catalog.ViewDispatcher;
+import org.apache.gravitino.dto.requests.ViewCreateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdatesRequest;
+import org.apache.gravitino.dto.responses.DropResponse;
+import org.apache.gravitino.dto.responses.EntityListResponse;
+import org.apache.gravitino.dto.responses.ViewResponse;
+import org.apache.gravitino.dto.util.DTOConverters;
+import org.apache.gravitino.metrics.MetricNames;
+import org.apache.gravitino.rel.View;
+import org.apache.gravitino.rel.ViewChange;
+import org.apache.gravitino.server.web.Utils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/views")
+public class ViewOperations {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ViewOperations.class);
+
+  private final ViewDispatcher dispatcher;
+
+  @Context private HttpServletRequest httpRequest;
+
+  @Inject
+  public ViewOperations(ViewDispatcher dispatcher) {
+    this.dispatcher = dispatcher;
+  }
+
+  @GET
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "list-view." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "list-view", absolute = true)
+  public Response listViews(
+      @PathParam("metalake") String metalake,
+      @PathParam("catalog") String catalog,
+      @PathParam("schema") String schema) {
+    LOG.info("Received list views request for schema: {}.{}.{}", metalake, 
catalog, schema);
+    try {
+      return Utils.doAs(
+          httpRequest,
+          () -> {
+            Namespace viewNS = NamespaceUtil.ofView(metalake, catalog, schema);
+            NameIdentifier[] idents = dispatcher.listViews(viewNS);
+            Response response = Utils.ok(new EntityListResponse(idents));
+            LOG.info(
+                "List {} views under schema: {}.{}.{}", idents.length, 
metalake, catalog, schema);
+            return response;
+          });
+
+    } catch (Exception e) {
+      return ExceptionHandlers.handleViewException(OperationType.LIST, "", 
schema, e);
+    }
+  }
+
+  @POST
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "create-view." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "create-view", absolute = true)
+  public Response createView(
+      @PathParam("metalake") String metalake,
+      @PathParam("catalog") String catalog,
+      @PathParam("schema") String schema,
+      ViewCreateRequest request) {
+    LOG.info(
+        "Received create view request: {}.{}.{}.{}", metalake, catalog, 
schema, request.getName());
+    try {
+      return Utils.doAs(

Review Comment:
   Acknowledged. These authorization annotations and metadata bindings are 
important, and we plan to add them in a separate follow-up PR. We are 
intentionally not mixing that cross-cutting authorization refactor into this 
endpoint-introduction PR so the review and rollout stay scoped.



-- 
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]

Reply via email to