Skip to content

Commit

Permalink
[#6092] docs(core): add credential openapi document (#6088)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
add credential openapi document 

### Why are the changes needed?

Fix: #6092 

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?
just document
  • Loading branch information
FANNG1 authored Jan 7, 2025
1 parent bec35a6 commit b3a848b
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface SupportsCredentials {
* org.apache.gravitino.file.Fileset}, {@link org.apache.gravitino.rel.Table}. There will be
* at most one credential for one credential type.
*/
Credential[] getCredentials() throws NoSuchCredentialException;
Credential[] getCredentials();

/**
* Retrieves an {@link Credential} object based on the specified credential type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.apache.gravitino.exceptions.ModelAlreadyExistsException;
import org.apache.gravitino.exceptions.ModelVersionAliasesAlreadyExistException;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.exceptions.NoSuchCredentialException;
import org.apache.gravitino.exceptions.NoSuchFilesetException;
import org.apache.gravitino.exceptions.NoSuchGroupException;
import org.apache.gravitino.exceptions.NoSuchMetadataObjectException;
Expand Down Expand Up @@ -898,10 +897,6 @@ public void accept(ErrorResponse errorResponse) {
case ErrorConstants.NOT_FOUND_CODE:
if (errorResponse.getType().equals(NoSuchMetalakeException.class.getSimpleName())) {
throw new NoSuchMetalakeException(errorMessage);
} else if (errorResponse
.getType()
.equals(NoSuchCredentialException.class.getSimpleName())) {
throw new NoSuchCredentialException(errorMessage);
} else {
throw new NotFoundException(errorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.gravitino.client;

import static org.apache.hc.core5.http.HttpStatus.SC_INTERNAL_SERVER_ERROR;
import static org.apache.hc.core5.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.hc.core5.http.HttpStatus.SC_OK;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -39,7 +38,6 @@
import org.apache.gravitino.dto.responses.CredentialResponse;
import org.apache.gravitino.dto.responses.ErrorResponse;
import org.apache.gravitino.dto.util.DTOConverters;
import org.apache.gravitino.exceptions.NoSuchCredentialException;
import org.apache.gravitino.file.Fileset;
import org.apache.hc.core5.http.Method;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -154,16 +152,6 @@ private void testGetCredentials(
credentials = supportsCredentials.getCredentials();
Assertions.assertEquals(0, credentials.length);

// Test throw NoSuchCredentialException
ErrorResponse errorResp =
ErrorResponse.notFound(NoSuchCredentialException.class.getSimpleName(), "mock error");
buildMockResource(Method.GET, path, null, errorResp, SC_NOT_FOUND);

Throwable ex =
Assertions.assertThrows(
NoSuchCredentialException.class, () -> supportsCredentials.getCredentials());
Assertions.assertTrue(ex.getMessage().contains("mock error"));

// Test throw internal error
ErrorResponse errorResp1 = ErrorResponse.internalError("mock error");
buildMockResource(Method.GET, path, null, errorResp1, SC_INTERNAL_SERVER_ERROR);
Expand Down
1 change: 1 addition & 0 deletions docs/open-api/catalogs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ components:
- hive
- lakehouse-iceberg
- lakehouse-paimon
- lakehouse-hudi
- jdbc-mysql
- jdbc-postgresql
- jdbc-doris
Expand Down
119 changes: 119 additions & 0 deletions docs/open-api/credentials.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# 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":
description: Not Found - The specified metalake does not exist
content:
application/vnd.gravitino.v1+json:
schema:
$ref: "./openapi.yaml#/components/schemas/ErrorModel"
examples:
NoSuchMetalakeException:
$ref: "./metalakes.yaml#/components/examples/NoSuchMetalakeException"
"5xx":
$ref: "./openapi.yaml#/components/responses/ServerErrorResponse"


components:
schemas:
Credential:
type: object
description: A credential
required:
- credentialType
- expireTimeInMs
- credentialInfo
properties:
credentialType:
type: string
description: The type of the credential, for example, s3-token, s3-secret-key, oss-token, oss-secret-key, gcs-token, adls-token, azure-account-key, etc.
expireTimeInMs:
type: integer
description: The expiration time of the credential in milliseconds since the epoch, 0 means not expire.
credentialInfo:
type: object
description: The specific information of the credential.
default: { }
additionalProperties:
type: string

responses:
CredentialResponse:
type: object
properties:
code:
type: integer
format: int32
description: Status code of the response
enum:
- 0
credentials:
type: array
description: A list of credential objects
items:
$ref: "#/components/schemas/Credential"

examples:
CredentialResponse:
value: {
"code": 0,
"credentials": [
{
"credentialType": "s3-token",
"expireTimeInMs": 1735891948411,
"credentialInfo": {
"s3-access-key-id": "value1",
"s3-secret-access-key": "value2",
"s3-session-token": "value3"
}
},
{
"credentialType": "s3-secret-key",
"expireTimeInMs": 0,
"credentialInfo": {
"s3-access-key-id": "value1",
"s3-secret-access-key": "value2"
}
},
]
}
3 changes: 3 additions & 0 deletions docs/open-api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ paths:
/metalakes/{metalake}/objects/{metadataObjectType}/{metadataObjectFullName}/roles:
$ref: "./roles.yaml#/paths/~1metalakes~1%7Bmetalake%7D~1objects~1%7BmetadataObjectType%7D~1%7BmetadataObjectFullName%7D~1roles"

/metalakes/{metalake}/objects/{metadataObjectType}/{metadataObjectFullName}/credentials:
$ref: "./credentials.yaml#/paths/~1metalakes~1%7Bmetalake%7D~1objects~1%7BmetadataObjectType%7D~1%7BmetadataObjectFullName%7D~1credentials"

/metalakes/{metalake}/objects/{metadataObjectType}/{metadataObjectFullName}/tags/{tag}:
$ref: "./tags.yaml#/paths/~1metalakes~1%7Bmetalake%7D~1objects~1%7BmetadataObjectType%7D~1%7BmetadataObjectFullName%7D~1tags~1%7Btag%7D"

Expand Down
22 changes: 21 additions & 1 deletion docs/open-api/tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ paths:
$ref: "#/components/examples/TagListResponse"
"400":
$ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse"
"404":
description: Not Found - The specified metalake does not exist
content:
application/vnd.gravitino.v1+json:
schema:
$ref: "./openapi.yaml#/components/schemas/ErrorModel"
examples:
NoSuchMetalakeException:
$ref: "./metalakes.yaml#/components/examples/NoSuchMetalakeException"
"5xx":
$ref: "./openapi.yaml#/components/responses/ServerErrorResponse"

Expand Down Expand Up @@ -233,6 +242,15 @@ paths:
examples:
NameListResponse:
$ref: "#/components/examples/NameListResponse"
"404":
description: Not Found - The specified metalake does not exist
content:
application/vnd.gravitino.v1+json:
schema:
$ref: "./openapi.yaml#/components/schemas/ErrorModel"
examples:
NoSuchMetalakeException:
$ref: "./metalakes.yaml#/components/examples/NoSuchMetalakeException"
"409":
description: Conflict - The target tag already associated with the specified metadata object
content:
Expand Down Expand Up @@ -272,14 +290,16 @@ paths:
"400":
$ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse"
"404":
description: Not Found - The specified metadata object does not exist or the specified tag is not associated with the specified metadata object
description: Not Found - The specified metalake does not exist or the specified tag is not associated with the specified metadata object
content:
application/vnd.gravitino.v1+json:
schema:
$ref: "./openapi.yaml#/components/schemas/ErrorModel"
examples:
NoSuchTagException:
$ref: "#/components/examples/NoSuchTagException"
NoSuchMetalakeException:
$ref: "./metalakes.yaml#/components/examples/NoSuchMetalakeException"
"5xx":
$ref: "./openapi.yaml#/components/responses/ServerErrorResponse"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.gravitino.server.web.rest;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -35,10 +34,7 @@
import org.apache.gravitino.credential.CredentialOperationDispatcher;
import org.apache.gravitino.credential.S3SecretKeyCredential;
import org.apache.gravitino.dto.responses.CredentialResponse;
import org.apache.gravitino.dto.responses.ErrorConstants;
import org.apache.gravitino.dto.responses.ErrorResponse;
import org.apache.gravitino.dto.util.DTOConverters;
import org.apache.gravitino.exceptions.NoSuchCredentialException;
import org.apache.gravitino.rest.RESTUtils;
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
Expand Down Expand Up @@ -138,25 +134,6 @@ private void testGetCredentialsForObject(MetadataObject metadataObject) {
credentialResponse = response.readEntity(CredentialResponse.class);
Assertions.assertEquals(0, credentialResponse.getCode());
Assertions.assertEquals(0, credentialResponse.getCredentials().length);

// Test throws NoSuchCredentialException
doThrow(new NoSuchCredentialException("mock error"))
.when(credentialOperationDispatcher)
.getCredentials(any());
response =
target(basePath(metalake))
.path(metadataObject.type().toString())
.path(metadataObject.fullName())
.path("/credentials")
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.gravitino.v1+json")
.get();

Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
Assertions.assertEquals(ErrorConstants.NOT_FOUND_CODE, errorResponse.getCode());
Assertions.assertEquals(
NoSuchCredentialException.class.getSimpleName(), errorResponse.getType());
}

private String basePath(String metalake) {
Expand Down

0 comments on commit b3a848b

Please sign in to comment.