tengqm commented on code in PR #6088:
URL: https://github.com/apache/gravitino/pull/6088#discussion_r1904778973


##########
docs/open-api/credentials.yaml:
##########
@@ -0,0 +1,130 @@
+# 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.
+
+---
+
+paths:
+
+  
/metalakes/{metalake}/objects/{metadataObjectType}/{metadataObjectFullName}/credentials:
+    parameters:
+      - $ref: "./openapi.yaml#/components/parameters/metalake"
+      - $ref: "./openapi.yaml#/components/parameters/metadataObjectType"
+      - $ref: "./openapi.yaml#/components/parameters/metadataObjectFullName"
+    get:
+      tags:
+        - credentials
+      summary: Get credentials
+      operationId: getCredentials
+      responses:
+        "200":
+          description: Returns the list of credential objects associated with 
specified metadata object.
+          content:
+            application/vnd.gravitino.v1+json:
+              schema:
+                $ref: "#/components/responses/CredentialResponse"
+              examples:
+                CredentialResponse:
+                  $ref: "#/components/examples/CredentialResponse"
+        "400":
+          $ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse"
+        "404":

Review Comment:
   > Your interpretation of "target resource" seems too narrow in the context 
of RESTful APIs. The HTTP specification ([RFC 
7231](https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4)) states that 
404 applies when "the origin server did not find a current representation for 
the target resource." In REST, each path segment is considered a resource, not 
just the final element.
   
   Correct. That was my interpretation, an interpretation I have seen in almost 
all RESTful API related web services. The "target resource", in this context, 
is the MetaObject. The 'metalake', 'schema' are all parameters (`in: path`) to 
get a MetaObject. If we say "not found", we mean, and only mean, the target 
MetaObject resource is not found. We are not confusing users (including client 
side software) that the metalake and the schema are correct, just that specific 
MetaObject is not found.
   
   > GET /repos/{owner}/{repo}
   
   This is not a "LIST" API. If you do `GET /repos`, where the path ends with a 
plural noun, the operation is a "LIST". For a "LIST" operation, the result is a 
list, which could be empty (`[]`). We are not telling users that a list is not 
found.
   
   GitHub is not a good example. Its API was designed long before we have a 
RESTful convention. Their interpration of `/repos/{owner}/{repo}` is equivalent 
to `/repos?owner=foo&repo=bar`, and they also failed to enforce that the result 
is a list.
   
   For this particular request:
   
   > `GET /metalakes/{metalake}/objects/{type}/{name}/credentials`
   
   Returning 404 is absolutely wrong. We are not checking a "specific 
resource", we are listing a collection.
   
   It is okay to return a 404 for the following request:
   
   > `GET /metalakes/{metalake}/objects/{obj-type}/{obj-name}/credentials/{id}`
   
   because this is a "get" rather than a list. If there is no credential with 
the given ID, we return 404 NotFound.
   
   If any of the `metalake`, `obj-type`, `obj-name` contains a `\@%)@*#$&`, we 
say 400 InvalidRequest. We are not responding with 404 which could be 
incorrectly interpreted as there is no MetaObjects in the metalake `\@%)@*#$&`. 
`metalake` should not be treated as a query string. It is part of the resource 
hierarchy in the system. Similarly, `obj-type` and `obj-name` are there for 
narrowing the scope for the **list** operation.
   
   How about `GET /credentials/?metalake=m&obj-type=t&obj-name=n` then? Can we 
return 404
   then? The answer is still a big NO. This is a list operation. There is no 
"target resource" here. There is only a concept of target resource collection.
   
   This is important. We cannot abuse 404, i.e. we cannot use the same 404 to 
express "the metalake is not found, OR the object type is not found, OR the 
object name is not found", we are not generalizing the target resource to 
anything other than a MetaObject.
   



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